Skip to content

Testing to_datetime, converting none to NaT #43006

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

Closed
Closed
Changes from all 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
19 changes: 19 additions & 0 deletions pandas/tests/tools/test_to_datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -992,6 +992,25 @@ def test_convert_object_to_datetime_with_cache(
)
tm.assert_series_equal(result_series, expected_series)

@pytest.mark.parametrize("cache", [True, False])
@pytest.mark.parametrize(
("input", "expected"),
(
(
Series([NaT] * 200 + [None] * 200, dtype="object"),
Series([NaT] * 400, dtype="datetime64[ns]"),
),
(Series([None] * 200), Series([NaT] * 200, dtype="datetime64[ns]")),
(Series([""] * 200), Series([NaT] * 200, dtype="datetime64[ns]")),
(Series([pd.NA] * 200), Series([NaT] * 200, dtype="datetime64[ns]")),
(Series([np.NaN] * 200), Series([NaT] * 200, dtype="datetime64[ns]")),
),
)
def test_to_datetime_converts_null_like_to_nat(self, cache, input, expected):
# GH35888
result = to_datetime(input, cache=cache)
tm.assert_series_equal(result, expected)

@pytest.mark.parametrize(
"date, format",
[
Expand Down