Skip to content

BUG: .plot(kind='pie') with ArrowDtype #59211

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions doc/source/whatsnew/v3.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -578,9 +578,9 @@ Period

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

Groupby/resample/rolling
^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
11 changes: 7 additions & 4 deletions pandas/plotting/_matplotlib/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
from pandas.core.dtypes.missing import isna

import pandas.core.common as com
from pandas.core.frame import DataFrame
from pandas.util.version import Version

from pandas.io.formats.printing import pprint_thing
Expand Down Expand Up @@ -94,6 +93,7 @@
)

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

_layout_type = "horizontal"

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

Expand Down
6 changes: 6 additions & 0 deletions pandas/tests/plotting/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,12 @@ def test_pie_series(self):
_check_text_labels(ax.texts, series.index)
assert ax.get_ylabel() == ""

def test_pie_arrow_type(self):
# GH 59192
pytest.importorskip("pyarrow")
ser = Series([1, 2, 3, 4], dtype="int32[pyarrow]")
_check_plot_works(ser.plot.pie)

def test_pie_series_no_label(self):
series = Series(
np.random.default_rng(2).integers(1, 5),
Expand Down