Skip to content

BUG: Series.round with pd.NA no longer raises; coerce object+NA to nullable float and round; add test (#61712) #62081

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

CyberSully
Copy link

Summary:
Fixes Series.round raising TypeError for object-dtype Series containing pd.NA by coercing to nullable Float64 before rounding, preserving pd.NA values.

Description:
This PR fixes an issue where calling Series.round on an object-dtype Series containing pd.NA would raise a TypeError.
The method now attempts to safely cast to the nullable Float64 dtype before rounding, preserving pd.NA values.

Includes:

Bug fix in Series.round to coerce object with pd.NA to Float64 and round as expected.

New test in test_round.py covering the case of object-dtype Series with pd.NA.

Added changelog entry in doc/source/whatsnew/v3.0.0.rst.

closes #61712

Tests added and passed

All code checks passed

Added type annotations (N/A – no new functions/args)

Added an entry in the latest doc/source/whatsnew/v3.0.0.rst file

@jbrockmendel
Copy link
Member

Simpler to just operate point wise?

@CyberSully
Copy link
Author

Simpler to just operate point wise?

Thanks for the feedback! I went with the dtype coercion approach since it keeps the operation vectorized and avoids Python-level iteration, which I assumed would be more consistent with how similar numeric conversions are handled in Pandas.

A pointwise implementation could definitely work for handling pd.NA cases explicitly, but I was aiming to minimize performance overhead and preserve existing behavior for other object-typed numeric data. If you think a pointwise approach would be preferable for clarity or maintainability here, I’m happy to prototype it so we can compare.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: .round causes TypeError / NaN-
2 participants