Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/whatsnew/v3.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,7 @@ Datetimelike
- Bug in :func:`date_range` where using a negative frequency value would not include all points between the start and end values (:issue:`56147`)
- Bug in :func:`tseries.api.guess_datetime_format` would fail to infer time format when "%Y" == "%H%M" (:issue:`57452`)
- Bug in :func:`tseries.frequencies.to_offset` would fail to parse frequency strings starting with "LWOM" (:issue:`59218`)
- Bug in :meth:`DataFrame.fillna` raising an ``AssertionError`` instead of ``OutOfBoundsDatetime`` when filling a ``datetime64[ns]`` column with an out-of-bounds timestamp. Now correctly raises ``OutOfBoundsDatetime``. (:issue:`61208`)
- Bug in :meth:`DataFrame.min` and :meth:`DataFrame.max` casting ``datetime64`` and ``timedelta64`` columns to ``float64`` and losing precision (:issue:`60850`)
- Bug in :meth:`Dataframe.agg` with df with missing values resulting in IndexError (:issue:`58810`)
- Bug in :meth:`DatetimeIndex.is_year_start` and :meth:`DatetimeIndex.is_quarter_start` does not raise on Custom business days frequencies bigger then "1C" (:issue:`58664`)
Expand Down
2 changes: 2 additions & 0 deletions pandas/core/internals/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -1749,6 +1749,8 @@ def putmask(self, mask, new) -> list[Block]:
try:
# Caller is responsible for ensuring matching lengths
values._putmask(mask, new)
except OutOfBoundsDatetime:
raise
except (TypeError, ValueError):
if self.ndim == 1 or self.shape[0] == 1:
if isinstance(self.dtype, IntervalDtype):
Expand Down
14 changes: 14 additions & 0 deletions pandas/tests/frame/methods/test_fillna.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import numpy as np
import pytest

from pandas.errors import OutOfBoundsDatetime

from pandas import (
Categorical,
DataFrame,
Expand Down Expand Up @@ -781,3 +783,15 @@ def test_fillna_with_none_object(test_frame, dtype):
if test_frame:
expected = expected.to_frame()
tm.assert_equal(result, expected)


def test_fillna_out_of_bounds_datetime():
# GH#61208
df = DataFrame(
{"datetime": date_range("1/1/2011", periods=3, freq="h"), "value": [1, 2, 3]}
)
df.iloc[0, 0] = None

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)