Skip to content

BUG: 0/0 with arrow backend is not "NA" #59122

Closed
@b-phi

Description

@b-phi

Pandas version checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

import pyarrow as pa
import pandas as pd

s = pd.Series([0], dtype=pd.ArrowDtype(pa.float64()))
(s / s).isna()

Issue Description

Dividing by zero with the arrow backend produces float('nan') which is not detected as NA by pandas when it is inside an arrow series.

In [25]: s / s
Out[25]:
0    NaN
dtype: double[pyarrow]

In [25]: (s / s).isna()
Out[25]:
0    False
dtype: bool

In [26]: (s / s).apply(pd.isna)
Out[26]:
0    True
dtype: bool

In [28]: pd.isna(float('nan'))
Out[28]: True

In [30]: pd.Series([float('nan')]).isna()
Out[30]:
0    True
dtype: bool

Expected Behavior

What is considered a NaN should not be dependent on the dtype backend used.

Installed Versions

INSTALLED VERSIONS

commit : d9cdd2e
python : 3.10.10.final.0
python-bits : 64
OS : Darwin
OS-release : 23.5.0
Version : Darwin Kernel Version 23.5.0: Wed May 1 20:09:52 PDT 2024; root:xnu-10063.121.3~5/RELEASE_X86_64
machine : x86_64
processor : i386
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 2.2.2
numpy : 2.0.0
pytz : 2024.1
dateutil : 2.9.0.post0
setuptools : 70.1.1
pip : 24.1.1
Cython : None
pytest : 8.2.1
hypothesis : None
sphinx : 7.3.7
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : 2.9.9
jinja2 : 3.1.4
IPython : 8.24.0
pandas_datareader : None
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : 4.12.3
bottleneck : None
dataframe-api-compat : None
fastparquet : None
fsspec : 2024.5.0
gcsfs : None
matplotlib : None
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 16.1.0
pyreadstat : None
python-calamine : None
pyxlsb : None
s3fs : 2024.5.0
scipy : 1.13.1
sqlalchemy : None
tables : None
tabulate : 0.9.0
xarray : None
xlrd : None
zstandard : None
tzdata : 2024.1
qtpy : None
pyqt5 : None

Metadata

Metadata

Assignees

No one assigned

    Labels

    Arrowpyarrow functionalityMissing-datanp.nan, pd.NaT, pd.NA, dropna, isnull, interpolate

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions