Skip to content
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

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

Closed
3 tasks done
mortnstak opened this issue Oct 25, 2024 · 5 comments
Closed
3 tasks done

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

mortnstak opened this issue Oct 25, 2024 · 5 comments
Labels
Bug Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate NA - MaskedArrays Related to pd.NA and nullable extension arrays Needs Discussion Requires discussion from core team before further action PDEP missing values Issues that would be addressed by the Ice Cream Agreement from the Aug 2023 sprint

Comments

@mortnstak
Copy link

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

@mortnstak mortnstak added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Oct 25, 2024
@mortnstak
Copy link
Author

Also - this is correctly handled if datatype the non-nullable "float64"

@mortnstak mortnstak changed the title BUG: isna() does not catch np.nan when datatype is Float64 BUG: isna() does not catch np.NaN when datatype is Float64 Oct 25, 2024
@rhshadrach
Copy link
Member

cc @jbrockmendel @jorisvandenbossche @mroeschke - there is one test that hits this where we check that NaN in the float values gives False with pd.isna:

But it seems unexpected to me to have float64 and Float64 act differently here. Can't find a discussion on the current behavior, has this been considered before?

@rhshadrach rhshadrach added Needs Discussion Requires discussion from core team before further action PDEP missing values Issues that would be addressed by the Ice Cream Agreement from the Aug 2023 sprint Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate NA - MaskedArrays Related to pd.NA and nullable extension arrays and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Oct 25, 2024
@asishm
Copy link
Contributor

asishm commented Oct 25, 2024

It would be good to get a decision here.. #53887

@jbrockmendel
Copy link
Member

This has been considered before, many times. xref #32265. Pdep 16 is the solution.

@rhshadrach
Copy link
Member

Thanks, this is certainly a duplicate of #53887, if not #32265. Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate NA - MaskedArrays Related to pd.NA and nullable extension arrays Needs Discussion Requires discussion from core team before further action PDEP missing values Issues that would be addressed by the Ice Cream Agreement from the Aug 2023 sprint
Projects
None yet
Development

No branches or pull requests

4 participants