11# being a bit too dynamic
22# pylint: disable=E1101
3- from itertools import izip
43import datetime
54import warnings
65import re
@@ -701,10 +700,8 @@ class MPLPlot(object):
701700 """
702701 _default_rot = 0
703702
704- _pop_attributes = ['label' , 'style' , 'logy' , 'logx' , 'loglog' ,
705- 'raise_on_error' ]
706- _attr_defaults = {'logy' : False , 'logx' : False , 'loglog' : False ,
707- 'raise_on_error' : True }
703+ _pop_attributes = ['label' , 'style' , 'logy' , 'logx' , 'loglog' ]
704+ _attr_defaults = {'logy' : False , 'logx' : False , 'loglog' : False }
708705
709706 def __init__ (self , data , kind = None , by = None , subplots = False , sharex = True ,
710707 sharey = False , use_index = True ,
@@ -875,7 +872,27 @@ def _get_layout(self):
875872 return (len (self .data .columns ), 1 )
876873
877874 def _compute_plot_data (self ):
878- pass
875+ try :
876+ # might be a frame
877+ numeric_data = self .data ._get_numeric_data ()
878+ except AttributeError :
879+ # a series, but no object dtypes allowed!
880+ if self .data .dtype == np .object_ :
881+ raise TypeError ('invalid dtype for plotting, please cast to a '
882+ 'numeric dtype explicitly if you want to plot' )
883+
884+ numeric_data = self .data
885+
886+ try :
887+ is_empty = numeric_data .empty
888+ except AttributeError :
889+ is_empty = not len (numeric_data )
890+
891+ # no empty frames or series allowed
892+ if is_empty :
893+ raise TypeError ('No numeric data to plot' )
894+
895+ self .data = numeric_data
879896
880897 def _make_plot (self ):
881898 raise NotImplementedError
@@ -1184,27 +1201,17 @@ def _make_plot(self):
11841201 else :
11851202 args = (ax , x , y , style )
11861203
1187- try :
1188- newline = plotf (* args , ** kwds )[0 ]
1189- lines .append (newline )
1190- leg_label = label
1191- if self .mark_right and self .on_right (i ):
1192- leg_label += ' (right)'
1193- labels .append (leg_label )
1194- ax .grid (self .grid )
1195-
1196- if self ._is_datetype ():
1197- left , right = _get_xlim (lines )
1198- ax .set_xlim (left , right )
1199- except AttributeError as inst : # non-numeric
1200- msg = ('Unable to plot data %s vs index %s,\n '
1201- 'error was: %s' % (str (y ), str (x ), str (inst )))
1202- if not self .raise_on_error :
1203- print msg
1204- else :
1205- msg = msg + ('\n Consider setting raise_on_error=False'
1206- 'to suppress' )
1207- raise Exception (msg )
1204+ newline = plotf (* args , ** kwds )[0 ]
1205+ lines .append (newline )
1206+ leg_label = label
1207+ if self .mark_right and self .on_right (i ):
1208+ leg_label += ' (right)'
1209+ labels .append (leg_label )
1210+ ax .grid (self .grid )
1211+
1212+ if self ._is_datetype ():
1213+ left , right = _get_xlim (lines )
1214+ ax .set_xlim (left , right )
12081215
12091216 self ._make_legend (lines , labels )
12101217
@@ -1223,22 +1230,12 @@ def to_leg_label(label, i):
12231230 return label
12241231
12251232 def _plot (data , col_num , ax , label , style , ** kwds ):
1226- try :
1227- newlines = tsplot (data , plotf , ax = ax , label = label ,
1228- style = style , ** kwds )
1229- ax .grid (self .grid )
1230- lines .append (newlines [0 ])
1231- leg_label = to_leg_label (label , col_num )
1232- labels .append (leg_label )
1233- except AttributeError as inst : #non-numeric
1234- msg = ('Unable to plot %s,\n '
1235- 'error was: %s' % (str (data ), str (inst )))
1236- if not self .raise_on_error :
1237- print msg
1238- else :
1239- msg = msg + ('\n Consider setting raise_on_error=False'
1240- 'to suppress' )
1241- raise Exception (msg )
1233+ newlines = tsplot (data , plotf , ax = ax , label = label ,
1234+ style = style , ** kwds )
1235+ ax .grid (self .grid )
1236+ lines .append (newlines [0 ])
1237+ leg_label = to_leg_label (label , col_num )
1238+ labels .append (leg_label )
12421239
12431240 if isinstance (data , Series ):
12441241 ax = self ._get_ax (0 ) # self.axes[0]
@@ -1610,8 +1607,8 @@ def plot_series(series, label=None, kind='line', use_index=True, rot=None,
16101607 If not passed, uses gca()
16111608 style : string, default matplotlib default
16121609 matplotlib line style to use
1613- grid : matplot grid
1614- legend: matplot legende
1610+ grid : matplotlib grid
1611+ legend: matplotlib legend
16151612 logx : boolean, default False
16161613 For line plots, use log scaling on x axis
16171614 logy : boolean, default False
@@ -1633,6 +1630,8 @@ def plot_series(series, label=None, kind='line', use_index=True, rot=None,
16331630 klass = BarPlot
16341631 elif kind == 'kde' :
16351632 klass = KdePlot
1633+ else :
1634+ raise ValueError ('Invalid chart type given %s' % kind )
16361635
16371636 """
16381637 If no axis is specified, we check whether there are existing figures.
0 commit comments