Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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 as e:
raise
except (TypeError, ValueError):
if self.ndim == 1 or self.shape[0] == 1:
if isinstance(self.dtype, IntervalDtype):
Expand Down
17 changes: 17 additions & 0 deletions pandas/tests/frame/methods/test_fillna.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
)
import pandas._testing as tm
from pandas.tests.frame.common import _check_mixed_float
from pandas.errors import OutOfBoundsDatetime


class TestFillNA:
Expand Down Expand Up @@ -781,3 +782,19 @@ 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)
Loading