Skip to content

Commit f97772f

Browse files
committed
Fix import order, revise the patch and add test with more kinds of plotting.
Signed-off-by: HE, Tao <[email protected]>
1 parent ff7314d commit f97772f

File tree

2 files changed

+26
-16
lines changed

2 files changed

+26
-16
lines changed

pandas/plotting/_core.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
from pandas.util._decorators import Appender, cache_readonly
1616

1717
from pandas.core.dtypes.common import (
18-
is_hashable, is_integer, is_iterator, is_list_like, is_number,
19-
is_extension_array_dtype)
18+
is_extension_array_dtype, is_hashable, is_integer, is_iterator,
19+
is_list_like, is_number)
2020
from pandas.core.dtypes.generic import (
2121
ABCDataFrame, ABCIndexClass, ABCMultiIndex, ABCPeriodIndex, ABCSeries)
2222
from pandas.core.dtypes.missing import isna, notna, remove_na_arraylike
@@ -364,6 +364,12 @@ def _compute_plot_data(self):
364364
raise TypeError('Empty {0!r}: no numeric data to '
365365
'plot'.format(numeric_data.__class__.__name__))
366366

367+
# GH25587: cast ExtensionArray of pandas (IntegerArray, etc.) to
368+
# np.ndarray before plot.
369+
for col in numeric_data:
370+
if is_extension_array_dtype(numeric_data[col]):
371+
numeric_data[col] = np.asarray(numeric_data[col])
372+
367373
self.data = numeric_data
368374

369375
def _make_plot(self):
@@ -575,13 +581,6 @@ def _get_xticks(self, convert_period=False):
575581

576582
@classmethod
577583
def _plot(cls, ax, x, y, style=None, is_errorbar=False, **kwds):
578-
# GH25587: cast ExtensionArray of pandas (IntegerArray, etc.) to
579-
# np.ndarray before plot.
580-
if is_extension_array_dtype(x):
581-
x = np.asarray(x)
582-
if is_extension_array_dtype(y):
583-
y = np.asarray(y)
584-
585584
mask = isna(y)
586585
if mask.any():
587586
y = np.ma.array(y)

pandas/tests/plotting/test_frame.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from pandas.compat import PY3, lmap, lrange, lzip, range, u, zip
1414
import pandas.util._test_decorators as td
1515

16+
from pandas.core.arrays import integer_array
1617
from pandas.core.dtypes.api import is_list_like
1718

1819
import pandas as pd
@@ -144,14 +145,24 @@ def test_plot(self):
144145
result = ax.axes
145146
assert result is axes[0]
146147

147-
@pytest.mark.parametrize("kwargs", [
148-
dict(yticks=[1, 2, 3, 4]),
149-
dict(xticks=[4, 5, 3, 2])
150-
])
151-
def test_integer_array_plot(self, kwargs):
148+
def test_integer_array_plot(self):
152149
# GH 25587
153-
s = Series([4, 5, 3, 2], dtype="UInt32")
154-
_check_plot_works(s.plot, **kwargs)
150+
arr = integer_array([1, 2, 3, 4], dtype="UInt32")
151+
152+
s = Series(arr)
153+
_check_plot_works(s.plot.line)
154+
_check_plot_works(s.plot.bar)
155+
_check_plot_works(s.plot.hist)
156+
_check_plot_works(s.plot.pie)
157+
158+
df = DataFrame({'x': arr, 'y': arr})
159+
_check_plot_works(df.plot.line)
160+
_check_plot_works(df.plot.bar)
161+
_check_plot_works(df.plot.hist)
162+
_check_plot_works(df.plot.area)
163+
_check_plot_works(df.plot.pie, y='y')
164+
_check_plot_works(df.plot.scatter, x='x', y='y')
165+
_check_plot_works(df.plot.hexbin, x='x', y='y')
155166

156167
def test_mpl2_color_cycle_str(self):
157168
# GH 15516

0 commit comments

Comments
 (0)