Skip to content

BUG: pd.isna handles np.nan inconsistently between numpy and extension / arrow types #58151

Closed
@WillAyd

Description

@WillAyd

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 pandas as pd
import numpy as np
import pyarrow as pa

np_arr = pd.Series([0, np.nan], dtype=np.float64) / 0
pd_arr = pd.Series([0, np.nan], dtype=pd.Float64Dtype()) / 0
pa_arr = pd.Series([0, np.nan], dtype=pd.ArrowDtype(pa.float64())) / 0
>>> np_arr
0   NaN
1   NaN
dtype: float64
>>> pd.isna(np_arr)
0    True
1    True
dtype: bool
>>> pd_arr
0     NaN
1    <NA>
dtype: Float64
>>> pd.isna(pd_arr)
0    False
1     True
dtype: bool
>>> pa_arr
0     NaN
1    <NA>
dtype: double[pyarrow]
>>> pd.isna(pa_arr)
0    False
1     True
dtype: bool

Issue Description

In the NumPy case, the NaN value resulting from the 0 / 0 division is caught by pd.isna but not in the pandas / pyarrow case

Expected Behavior

I think all should be True @jorisvandenbossche

Installed Versions

run on main

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugNeeds TriageIssue that has not been reviewed by a pandas team member

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions