Skip to content

BUG: isna() does not catch np.NaN when datatype is Float64 #60106

@mortnstak

Description

@mortnstak

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

data={"x":[1,0],"y":[1,0]}
df=pd.DataFrame(data,dtype="Float64")
df['z']=df['y']/df['x']
df['z'].isna()

Issue Description

The pandas isna() function does not catch NaN values that are of type np.NaN when using the Float64 datatype. The call df['z'].isna() returns a series with following rows.

0    False
1    False
Name: z, dtype: bool

Using the code above, both rows return a false value. Using df['z'].apply(np.isnan) correctly returns false for the first row, and true for the second row.

0    False
1     True
Name: z, dtype: boolean

Expected Behavior

I would expect the pandas isna() function to also classify the np.NaN type as a null or nan value when using the Float64 datatype.
The returned value of df['z'].isna() should be a series with following rows.

0    False
1     True
Name: z, dtype: bool

Installed Versions

INSTALLED VERSIONS

commit : 0691c5c
python : 3.11.9
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.22631
machine : AMD64
processor : Intel64 Family 6 Model 141 Stepping 1, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : Norwegian Bokmål_Norway.1252

pandas : 2.2.3
numpy : 1.26.2
pytz : 2023.3.post1
dateutil : 2.8.2
pip : 24.2
Cython : None
sphinx : None
IPython : 8.18.1
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : None
blosc : None
bottleneck : None
dataframe-api-compat : None
fastparquet : None
fsspec : None
html5lib : None
hypothesis : None
gcsfs : None
jinja2 : None
lxml.etree : None
matplotlib : None
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
psycopg2 : None
pymysql : None
pyarrow : 14.0.1
pyreadstat : None
pytest : None
python-calamine : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlsxwriter : None
zstandard : None
tzdata : 2023.3
qtpy : None
pyqt5 : None

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugMissing-datanp.nan, pd.NaT, pd.NA, dropna, isnull, interpolateNA - MaskedArraysRelated to pd.NA and nullable extension arraysNeeds DiscussionRequires discussion from core team before further actionPDEP missing valuesIssues that would be addressed by the Ice Cream Agreement from the Aug 2023 sprint

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions