Skip to content

pd.to_datetime() fails for KeyError when raising monotonic increasing index ValueError #42635

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 11 commits into from
Jul 25, 2021
11 changes: 11 additions & 0 deletions pandas/tests/tools/test_to_datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -2530,3 +2530,14 @@ def test_empty_string_datetime_coerce__unit():
# verify that no exception is raised even when errors='raise' is set
result = to_datetime([1, ""], unit="s", errors="raise")
tm.assert_index_equal(expected, result)


def test_to_datetime_monotonic_increasing_index():
# GH28238
times = date_range(datetime.now(), periods=1000, freq="h")
times = times.to_frame(index=False, name="DT").sample(1000)
times.index = times.index.to_series().astype(float) / 1000
converted = to_datetime(times.iloc[:, 0])
expected = np.ravel(times.values)
result = np.ravel(converted.values)
tm.assert_equal(result, expected)