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: Presence of pd.NA value in pd.Series prevents values from being rounded #60499

Closed
3 tasks done
mijalapenos opened this issue Dec 5, 2024 · 1 comment
Closed
3 tasks done
Labels
Bug Constructors Series/DataFrame/Index/pd.array Constructors Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate

Comments

@mijalapenos
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
pd.Series([1.123, 2.123, pd.NA]).round(0)

Issue Description

Presence of pd.NA value in pd.Series prevents values from being rounded.

>>> pd.Series([1.123, 2.123, pd.NA]).round(0)
0    1.123
1    2.123
2     <NA>
dtype: object

Expected Behavior

I would expect the same behavior as with np.nan values:

>>> pd.Series([1.123, 2.123, np.nan]).round(0)
0    1.0
1    2.0
2    NaN
dtype: float64

Installed Versions

/Users//miniforge3/envs/nlp/lib/python3.9/site-packages/_distutils_hack/init.py:33: UserWarning: Setuptools is replacing distutils.
warnings.warn("Setuptools is replacing distutils.")

INSTALLED VERSIONS

commit : d9cdd2e
python : 3.9.16.final.0
python-bits : 64
OS : Darwin
OS-release : 24.1.0
Version : Darwin Kernel Version 24.1.0: Thu Oct 10 21:05:14 PDT 2024; root:xnu-11215.41.3~2/RELEASE_ARM64_T8103
machine : arm64
processor : arm
byteorder : little
LC_ALL : None
LANG : None
LOCALE : None.UTF-8

pandas : 2.2.2
numpy : 1.25.2
pytz : 2023.3.post1
dateutil : 2.8.2
setuptools : 68.2.2
pip : 23.2.1
Cython : None
pytest : 7.4.0
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.9.3
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.1.2
IPython : 8.16.1
pandas_datareader : None
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : 4.12.2
bottleneck : None
dataframe-api-compat : None
fastparquet : None
fsspec : 2023.10.0
gcsfs : None
matplotlib : 3.8.0
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 14.0.1
pyreadstat : None
python-calamine : None
pyxlsb : None
s3fs : None
scipy : 1.11.3
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
zstandard : None
tzdata : 2023.3
qtpy : None
pyqt5 : None

@mijalapenos mijalapenos added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Dec 5, 2024
@rhshadrach
Copy link
Member

Thanks for the report. When you do not specify a dtype, pandas results in object dtype here. round() does not impact object dtype.

res = pd.Series([1.123, 2.123, pd.NA], dtype="Float64").round(0)
print(res)
# 0     1.0
# 1     2.0
# 2    <NA>
# dtype: Float64

That pandas does not infer Float64 without the dtype is #33662.

Closing.

@rhshadrach rhshadrach added Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate Constructors Series/DataFrame/Index/pd.array Constructors and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Dec 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Constructors Series/DataFrame/Index/pd.array Constructors Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate
Projects
None yet
Development

No branches or pull requests

2 participants