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: OverflowError when fillna on DataFrame with a pd.Timestamp (#61208) #61216

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

Conversation

PedroM4rques
Copy link

@PedroM4rques PedroM4rques commented Apr 2, 2025

Fix for fillna with Out-of-Bounds Datetime Values

Issue: Using fillna on a datetime64[ns] column with an out-of-bounds timestamp (e.g., '0001-01-01') raised an AssertionError instead of the expected OutOfBoundsDatetime.

Fix: Modified the putmask method in pandas/core/internals/blocks.py to catch and re-raise OutOfBoundsDatetime directly, preventing the AssertionError.

Test Added:

  • Created test_fillna_out_of_bounds_datetime in pandas/tests/frame/methods/test_fillna.py.
  • The test:
    • Sets up a DataFrame with a datetime64[ns] column containing NaT.
    • Attempts to fill NaT with '0001-01-01'.
    • Expects OutOfBoundsDatetime.

Sorry, something went wrong.

…d.Timestamp

- Now correctly raises OutOfBoundsDatetime
- Added test_fillna_out_of_bounds_datetime()
@PedroM4rques PedroM4rques requested a review from yuanx749 April 2, 2025 22:11
Copy link
Member

@rhshadrach rhshadrach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good, just one request.


msg = "Cannot cast 0001-01-01 00:00:00 to unit='ns' without overflow"
with pytest.raises(OutOfBoundsDatetime, match=msg):
df.fillna(Timestamp("0001-01-01"), inplace=True)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remove inplace=True; that argument is going to be removed in a future pandas version.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

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: OverflowError when fillna on DataFrame with a pd.Timestamp
3 participants