BUG: Pyarrow series .any() returns a bool, messing up plotting · Issue #59192 · pandas-dev/pandas (original) (raw)

Pandas version checks

Reproducible Example

import pandas as pd

series = pd.Series([1, 2, 3, 4], dtype='int32[pyarrow]')

series.plot(kind='pie')

Issue Description

The example yields this error:

Traceback (most recent call last):
  File "/home/jon/work/panda.py", line 5, in <module>
    series.plot(kind='pie')
  File "/home/jon/.local/lib/python3.11/site-packages/pandas/plotting/_core.py", line 1030, in __call__
    return plot_backend.plot(data, kind=kind, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jon/.local/lib/python3.11/site-packages/pandas/plotting/_matplotlib/__init__.py", line 70, in plot
    plot_obj = PLOT_CLASSES[kind](data, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jon/.local/lib/python3.11/site-packages/pandas/plotting/_matplotlib/core.py", line 2051, in __init__
    if (data < 0).any().any():
       ^^^^^^^^^^^^^^^^^^^^
AttributeError: 'bool' object has no attribute 'any'

The error comes from (data < 0).any() giving a boolean (<class 'bool'>) instead of a numpy boolean (<class 'numpy.bool_'>).

>>> series = pd.Series([1, 2, 3, 4], dtype='int32[pyarrow]')
>>> type((series < 0).any())
<class 'bool'>
>>> series = pd.Series([1, 2, 3, 4], dtype='int32')         
>>> type((series < 0).any())                       
<class 'numpy.bool_'>

When .any() is called on the numpy bool, it just returns the same value, but the AttributeError is raised when .any() is called on the boolean.

Expected Behavior

This code does exactly what I want:

import pandas as pd import matplotlib.pyplot as plt

series = pd.Series([1, 2, 3, 4], dtype='int32[pyarrow]')

plt.pie(series)

and works, but I don't have direct control over the code as I'm using an LLM to write code and it still uses the series.plot feature.

Installed Versions

INSTALLED VERSIONS

commit : d9cdd2e
python : 3.11.3.final.0
python-bits : 64
OS : Linux
OS-release : 5.4.0-187-generic
Version : #207-Ubuntu SMP Mon Jun 10 08:16:10 UTC 2024
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 2.2.2
numpy : 1.24.3
pytz : 2024.1
dateutil : 2.9.0.post0
setuptools : 65.5.0
pip : 23.2.1
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : 2.9.7
jinja2 : None
IPython : None
pandas_datareader : None
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : 4.12.2
bottleneck : None
dataframe-api-compat : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : 3.7.2
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 16.1.0
pyreadstat : None
python-calamine : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
zstandard : 0.21.0
tzdata : 2024.1
qtpy : None
pyqt5 : None