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: None values are not processed when applying pd.isnull to a Series with dtype category #59832

Closed
2 of 3 tasks
StephanMertel opened this issue Sep 18, 2024 · 6 comments
Closed
2 of 3 tasks
Assignees
Labels
Apply Apply, Aggregate, Transform, Map Bug Categorical Categorical Data Type Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate

Comments

@StephanMertel
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

# Create a Series with dtype category which contains a None value
my_series = pd.Series([1, None], dtype="category")

my_series.apply(pd.isnull)
# This will output
# 0    False
# 1      NaN   <------------------ I would expect this to be True
# dtype: category
# Categories (1, bool): [False]

Issue Description

When applying pd.isnull to a Series of dtype category which contains None like values (None, np.nan, pd.NA, etc.), the output doesn't contain a boolean but a float nan instead.

Expected Behavior

The output should contain only boolean values and all None, pd.NA etc. values should be evaluated as True.

Installed Versions

INSTALLED VERSIONS

commit : d9cdd2e
python : 3.11.3.final.0
python-bits : 64
OS : Darwin
OS-release : 23.6.0
Version : Darwin Kernel Version 23.6.0: Mon Jul 29 21:14:21 PDT 2024; root:xnu-10063.141.2~1/RELEASE_ARM64_T8103
machine : arm64
processor : arm
byteorder : little
LC_ALL : None
LANG : None
LOCALE : None.UTF-8

pandas : 2.2.2
numpy : 1.24.3
pytz : 2023.3
dateutil : 2.8.2
setuptools : 67.6.1
pip : 23.0.1
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : 8.13.2
pandas_datareader : None
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : None
bottleneck : None
dataframe-api-compat : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : None
numba : None
numexpr : None
odfpy : None
openpyxl : 3.1.2
pandas_gbq : None
pyarrow : 12.0.0
pyreadstat : None
python-calamine : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
zstandard : None
tzdata : 2023.3
qtpy : None
pyqt5 : None

@StephanMertel StephanMertel added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Sep 18, 2024
@PriyaDCosta
Copy link

Take

@rhshadrach rhshadrach added Apply Apply, Aggregate, Transform, Map and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Sep 23, 2024
@rhshadrach
Copy link
Member

Thanks for the report. Agreed this is a bug and on the expectation, but for performance you should prefer my_series.isnull() to using apply. Using apply is very slow.

@rhshadrach rhshadrach added Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate Categorical Categorical Data Type labels Sep 23, 2024
@StephanMertel
Copy link
Author

@rhshadrach thanks for your answer and the hint! Will do.

@tyqiangz
Copy link

tyqiangz commented Oct 5, 2024

Take

@tyqiangz
Copy link

tyqiangz commented Oct 6, 2024

@rhshadrach I believe this issue is already solved in this PR #59966.

@rhshadrach
Copy link
Member

Agreed, thanks @tyqiangz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Apply Apply, Aggregate, Transform, Map Bug Categorical Categorical Data Type Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate
Projects
None yet
Development

No branches or pull requests

4 participants