Skip to content

Commit 7072085

Browse files
committed
Revise.
Signed-off-by: HE, Tao <[email protected]>
1 parent b3445fc commit 7072085

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

doc/source/whatsnew/v0.24.2.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Fixed Regressions
3131
- Fixed regression in ``IntervalDtype`` construction where passing an incorrect string with 'Interval' as a prefix could result in a ``RecursionError``. (:issue:`25338`)
3232
- Fixed regression in :class:`Categorical`, where constructing it from a categorical ``Series`` and an explicit ``categories=`` that differed from that in the ``Series`` created an invalid object which could trigger segfaults. (:issue:`25318`)
3333
- Fixed pip installing from source into an environment without NumPy (:issue:`25193`)
34-
- Fixed bug that :class:`ExtensionArray` cannot be used to matplotlib plotting (:issue:`25587`)
34+
- Fixed bug where :class:`api.extensions.ExtensionArray` could not be used in matplotlib plotting (:issue:`25587`)
3535

3636
.. _whatsnew_0242.enhancements:
3737

pandas/plotting/_core.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +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)
18+
is_hashable, is_integer, is_iterator, is_list_like, is_number,
19+
is_extension_array_dtype)
1920
from pandas.core.dtypes.generic import (
2021
ABCDataFrame, ABCIndexClass, ABCMultiIndex, ABCPeriodIndex, ABCSeries)
2122
from pandas.core.dtypes.missing import isna, notna, remove_na_arraylike
@@ -577,10 +578,10 @@ def _get_xticks(self, convert_period=False):
577578
def _plot(cls, ax, x, y, style=None, is_errorbar=False, **kwds):
578579
# GH25587: cast ExtensionArray of pandas (IntegerArray, etc.) to
579580
# np.ndarray before plot.
580-
if isinstance(x, ExtensionArray):
581-
x = x.__array__()
582-
if isinstance(y, ExtensionArray):
583-
y = y.__array__()
581+
if is_extension_array_dtype(x):
582+
x = np.asarray(x)
583+
if is_extension_array_dtype(y):
584+
y = np.asarray(y)
584585

585586
mask = isna(y)
586587
if mask.any():

pandas/tests/plotting/test_frame.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,14 +144,17 @@ def test_plot(self):
144144
result = ax.axes
145145
assert result is axes[0]
146146

147-
# GH 25587
148-
def test_integer_array_plot(self):
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):
152+
# GH 25587
149153
s = Series([4, 5, 3, 2], dtype="UInt32")
150-
_check_plot_works(s.plot, yticks=[1, 2, 3, 4])
151-
_check_plot_works(s.plot, xticks=[4, 5, 3, 2])
154+
_check_plot_works(s.plot, **kwargs)
152155

153-
# GH 15516
154156
def test_mpl2_color_cycle_str(self):
157+
# GH 15516
155158
colors = ['C' + str(x) for x in range(10)]
156159
df = DataFrame(randn(10, 3), columns=['a', 'b', 'c'])
157160
for c in colors:

0 commit comments

Comments
 (0)