Skip to content

Commit f35a3ef

Browse files
add test for pandas-devGH-42921
1 parent c8276c7 commit f35a3ef

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

pandas/tests/series/methods/test_reindex.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
Period,
1010
PeriodIndex,
1111
Series,
12+
Timedelta,
13+
Timestamp,
1214
date_range,
1315
isna,
1416
)
@@ -300,6 +302,21 @@ def test_reindex_fill_value():
300302
tm.assert_series_equal(result, expected)
301303

302304

305+
@pytest.mark.parametrize("dtype", ["datetime64[ns]", "timedelta64[ns]"])
306+
@pytest.mark.parametrize("fill_value", ["string", 0, Timedelta(0)])
307+
def test_reindex_fill_value_datetimelike_upcast(dtype, fill_value):
308+
# https://github.com/pandas-dev/pandas/issues/42921
309+
if dtype == "timedelta64[ns]" and fill_value == Timedelta(0):
310+
# use the scalar that is not compatible with the dtype for this test
311+
fill_value = Timestamp(0)
312+
313+
ser = Series([NaT], dtype=dtype)
314+
315+
result = ser.reindex([0, 1], fill_value=fill_value)
316+
expected = Series([None, fill_value], index=[0, 1], dtype=object)
317+
tm.assert_series_equal(result, expected)
318+
319+
303320
def test_reindex_datetimeindexes_tz_naive_and_aware():
304321
# GH 8306
305322
idx = date_range("20131101", tz="America/Chicago", periods=7)

0 commit comments

Comments
 (0)