Skip to content

Commit c2fe667

Browse files
authored
pd.to_datetime() fails for KeyError when raising monotonic increasing index ValueError (#42635)
1 parent c86b129 commit c2fe667

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

pandas/tests/tools/test_to_datetime.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2530,3 +2530,15 @@ def test_empty_string_datetime_coerce__unit():
25302530
# verify that no exception is raised even when errors='raise' is set
25312531
result = to_datetime([1, ""], unit="s", errors="raise")
25322532
tm.assert_index_equal(expected, result)
2533+
2534+
2535+
@pytest.mark.parametrize("cache", [True, False])
2536+
def test_to_datetime_monotonic_increasing_index(cache):
2537+
# GH28238
2538+
cstart = start_caching_at
2539+
times = date_range(Timestamp("1980"), periods=cstart, freq="YS")
2540+
times = times.to_frame(index=False, name="DT").sample(n=cstart, random_state=1)
2541+
times.index = times.index.to_series().astype(float) / 1000
2542+
result = to_datetime(times.iloc[:, 0], cache=cache)
2543+
expected = times.iloc[:, 0]
2544+
tm.assert_series_equal(result, expected)

0 commit comments

Comments
 (0)