Skip to content

Commit d6724bc

Browse files
authored
BUG: .plot(kind='pie') with ArrowDtype (#59211)
1 parent b46bae4 commit d6724bc

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

doc/source/whatsnew/v3.0.0.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -582,9 +582,9 @@ Period
582582

583583
Plotting
584584
^^^^^^^^
585-
- Bug in :meth:`.DataFrameGroupBy.boxplot` failed when there were multiple groupings (:issue:`14701`)
585+
- Bug in :meth:`.DataFrameGroupBy.boxplot` failed when there were multiple groupings (:issue:`14701`)
586586
- Bug in :meth:`DataFrame.plot` that causes a shift to the right when the frequency multiplier is greater than one. (:issue:`57587`)
587-
-
587+
- Bug in :meth:`Series.plot` with ``kind="pie"`` with :class:`ArrowDtype` (:issue:`59192`)
588588

589589
Groupby/resample/rolling
590590
^^^^^^^^^^^^^^^^^^^^^^^^

pandas/plotting/_matplotlib/core.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@
5555
from pandas.core.dtypes.missing import isna
5656

5757
import pandas.core.common as com
58-
from pandas.core.frame import DataFrame
5958
from pandas.util.version import Version
6059

6160
from pandas.io.formats.printing import pprint_thing
@@ -94,6 +93,7 @@
9493
)
9594

9695
from pandas import (
96+
DataFrame,
9797
Index,
9898
Series,
9999
)
@@ -183,7 +183,7 @@ def __init__(
183183
# Assign the rest of columns into self.columns if by is explicitly defined
184184
# while column is not, only need `columns` in hist/box plot when it's DF
185185
# TODO: Might deprecate `column` argument in future PR (#28373)
186-
if isinstance(data, DataFrame):
186+
if isinstance(data, ABCDataFrame):
187187
if column:
188188
self.columns = com.maybe_make_list(column)
189189
elif self.by is None:
@@ -2035,9 +2035,12 @@ def _kind(self) -> Literal["pie"]:
20352035

20362036
_layout_type = "horizontal"
20372037

2038-
def __init__(self, data, kind=None, **kwargs) -> None:
2038+
def __init__(self, data: Series | DataFrame, kind=None, **kwargs) -> None:
20392039
data = data.fillna(value=0)
2040-
if (data < 0).any().any():
2040+
lt_zero = data < 0
2041+
if isinstance(data, ABCDataFrame) and lt_zero.any().any():
2042+
raise ValueError(f"{self._kind} plot doesn't allow negative values")
2043+
elif isinstance(data, ABCSeries) and lt_zero.any():
20412044
raise ValueError(f"{self._kind} plot doesn't allow negative values")
20422045
MPLPlot.__init__(self, data, kind=kind, **kwargs)
20432046

pandas/tests/plotting/test_series.py

+6
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,12 @@ def test_pie_series(self):
377377
_check_text_labels(ax.texts, series.index)
378378
assert ax.get_ylabel() == ""
379379

380+
def test_pie_arrow_type(self):
381+
# GH 59192
382+
pytest.importorskip("pyarrow")
383+
ser = Series([1, 2, 3, 4], dtype="int32[pyarrow]")
384+
_check_plot_works(ser.plot.pie)
385+
380386
def test_pie_series_no_label(self):
381387
series = Series(
382388
np.random.default_rng(2).integers(1, 5),

0 commit comments

Comments
 (0)