Skip to content

BUG: OverflowError when fillna on DataFrame with a pd.Timestamp (#61208) #61216

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

Merged
merged 3 commits into from
Apr 14, 2025

Conversation

PedroM4rques
Copy link
Contributor

@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 where method in pandas/core/internals/blocks.py to catch and re-raise OutOfBoundsDatetime directly, preventing the AssertionError.

Fix (inplace=True): 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.

…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.

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.

lgtm

@rhshadrach rhshadrach added this to the 3.0 milestone Apr 14, 2025
@rhshadrach rhshadrach added Bug Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate Error Reporting Incorrect or improved errors from pandas Timestamp pd.Timestamp and associated methods labels Apr 14, 2025
@mroeschke mroeschke merged commit 80795df into pandas-dev:main Apr 14, 2025
54 checks passed
@mroeschke
Copy link
Member

Thanks @PedroM4rques

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Error Reporting Incorrect or improved errors from pandas Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate Timestamp pd.Timestamp and associated methods
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: OverflowError when fillna on DataFrame with a pd.Timestamp
4 participants