19
19
is_number ,
20
20
is_hashable ,
21
21
is_iterator )
22
- from pandas .core .dtypes .generic import ABCSeries
22
+ from pandas .core .dtypes .generic import ABCSeries , ABCDataFrame
23
23
24
24
from pandas .core .common import AbstractMethodError , _try_sort , _any_not_none
25
25
from pandas .core .generic import _shared_docs , _shared_doc_kwargs
@@ -1680,17 +1680,16 @@ def _plot(data, x=None, y=None, subplots=False,
1680
1680
else :
1681
1681
raise ValueError ("%r is not a valid plot kind" % kind )
1682
1682
1683
- from pandas import DataFrame
1684
1683
if kind in _dataframe_kinds :
1685
- if isinstance (data , DataFrame ):
1684
+ if isinstance (data , ABCDataFrame ):
1686
1685
plot_obj = klass (data , x = x , y = y , subplots = subplots , ax = ax ,
1687
1686
kind = kind , ** kwds )
1688
1687
else :
1689
1688
raise ValueError ("plot kind %r can only be used for data frames"
1690
1689
% kind )
1691
1690
1692
1691
elif kind in _series_kinds :
1693
- if isinstance (data , DataFrame ):
1692
+ if isinstance (data , ABCDataFrame ):
1694
1693
if y is None and subplots is False :
1695
1694
msg = "{0} requires either y column or 'subplots=True'"
1696
1695
raise ValueError (msg .format (kind ))
@@ -1702,15 +1701,19 @@ def _plot(data, x=None, y=None, subplots=False,
1702
1701
data .index .name = y
1703
1702
plot_obj = klass (data , subplots = subplots , ax = ax , kind = kind , ** kwds )
1704
1703
else :
1705
- if isinstance (data , DataFrame ):
1704
+ if isinstance (data , ABCDataFrame ):
1706
1705
if x is not None :
1707
1706
if is_integer (x ) and not data .columns .holds_integer ():
1708
1707
x = data .columns [x ]
1708
+ elif not isinstance (data [x ], ABCSeries ):
1709
+ raise ValueError ("x must be a label or position" )
1709
1710
data = data .set_index (x )
1710
1711
1711
1712
if y is not None :
1712
1713
if is_integer (y ) and not data .columns .holds_integer ():
1713
1714
y = data .columns [y ]
1715
+ elif not isinstance (data [y ], ABCSeries ):
1716
+ raise ValueError ("y must be a label or position" )
1714
1717
label = kwds ['label' ] if 'label' in kwds else y
1715
1718
series = data [y ].copy () # Don't modify
1716
1719
series .name = label
0 commit comments