From f67ffe365d7ed8bd0e6576825076fd5145b13074 Mon Sep 17 00:00:00 2001 From: Ryan Gilmour Date: Thu, 12 Aug 2021 23:57:10 +0100 Subject: [PATCH 1/4] Testing to_datetime, converting none to NaT --- pandas/tests/tools/test_to_datetime.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/pandas/tests/tools/test_to_datetime.py b/pandas/tests/tools/test_to_datetime.py index 7351f50aea8c1..b35d201d038ef 100644 --- a/pandas/tests/tools/test_to_datetime.py +++ b/pandas/tests/tools/test_to_datetime.py @@ -2542,3 +2542,21 @@ def test_to_datetime_monotonic_increasing_index(cache): result = to_datetime(times.iloc[:, 0], cache=cache) expected = times.iloc[:, 0] tm.assert_series_equal(result, expected) + + +@pytest.mark.parametrize("cache", [True, False]) +@pytest.mark.parametrize( + ("input", "expected"), + ( + ( + pd.Series([pd.NaT] * 200 + [None] * 200, dtype="object"), + pd.Series([pd.NaT] * 400, dtype="datetime64[ns]"), + ), + (pd.Series([None] * 200), pd.Series([pd.NaT] * 200, dtype="datetime64[ns]")), + (pd.Series([""] * 200), pd.Series([pd.NaT] * 200, dtype="datetime64[ns]")), + ), +) +def test_to_datetime_converts_null_like_to_nat(cache, input, expected): + # GH35888 + result = to_datetime(input) + tm.assert_series_equal(result, expected) From 908c202bcf6ea5db515e4900c9acab2e51b268f8 Mon Sep 17 00:00:00 2001 From: Ryan Gilmour Date: Fri, 13 Aug 2021 00:25:38 +0100 Subject: [PATCH 2/4] Testing to_datetime, converting NA/NaN to NaT --- pandas/tests/tools/test_to_datetime.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pandas/tests/tools/test_to_datetime.py b/pandas/tests/tools/test_to_datetime.py index b35d201d038ef..f341e11ccdf37 100644 --- a/pandas/tests/tools/test_to_datetime.py +++ b/pandas/tests/tools/test_to_datetime.py @@ -2554,6 +2554,8 @@ def test_to_datetime_monotonic_increasing_index(cache): ), (pd.Series([None] * 200), pd.Series([pd.NaT] * 200, dtype="datetime64[ns]")), (pd.Series([""] * 200), pd.Series([pd.NaT] * 200, dtype="datetime64[ns]")), + (pd.Series([pd.NA] * 200), pd.Series([pd.NaT] * 200, dtype="datetime64[ns]")), + (pd.Series([np.NaN] * 200), pd.Series([pd.NaT] * 200, dtype="datetime64[ns]")), ), ) def test_to_datetime_converts_null_like_to_nat(cache, input, expected): From bfbfb62156874b6e86d56e267b0196686b042300 Mon Sep 17 00:00:00 2001 From: Ryan Gilmour Date: Fri, 20 Aug 2021 13:31:38 +0000 Subject: [PATCH 3/4] Fix linting issues - move test near other related ones. --- pandas/tests/tools/test_to_datetime.py | 39 +++++++++++++------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/pandas/tests/tools/test_to_datetime.py b/pandas/tests/tools/test_to_datetime.py index f341e11ccdf37..8f59ee4c512a4 100644 --- a/pandas/tests/tools/test_to_datetime.py +++ b/pandas/tests/tools/test_to_datetime.py @@ -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(cache, input, expected): + # GH35888 + result = to_datetime(input) + tm.assert_series_equal(result, expected) + @pytest.mark.parametrize( "date, format", [ @@ -2542,23 +2561,3 @@ def test_to_datetime_monotonic_increasing_index(cache): result = to_datetime(times.iloc[:, 0], cache=cache) expected = times.iloc[:, 0] tm.assert_series_equal(result, expected) - - -@pytest.mark.parametrize("cache", [True, False]) -@pytest.mark.parametrize( - ("input", "expected"), - ( - ( - pd.Series([pd.NaT] * 200 + [None] * 200, dtype="object"), - pd.Series([pd.NaT] * 400, dtype="datetime64[ns]"), - ), - (pd.Series([None] * 200), pd.Series([pd.NaT] * 200, dtype="datetime64[ns]")), - (pd.Series([""] * 200), pd.Series([pd.NaT] * 200, dtype="datetime64[ns]")), - (pd.Series([pd.NA] * 200), pd.Series([pd.NaT] * 200, dtype="datetime64[ns]")), - (pd.Series([np.NaN] * 200), pd.Series([pd.NaT] * 200, dtype="datetime64[ns]")), - ), -) -def test_to_datetime_converts_null_like_to_nat(cache, input, expected): - # GH35888 - result = to_datetime(input) - tm.assert_series_equal(result, expected) From ab1851b1c3a45a24173b3b5e2a27ac41301f284c Mon Sep 17 00:00:00 2001 From: Ryan Gilmour Date: Fri, 20 Aug 2021 18:11:43 +0000 Subject: [PATCH 4/4] Fix CI error: function uses no argument 'cache' --- pandas/tests/tools/test_to_datetime.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/tests/tools/test_to_datetime.py b/pandas/tests/tools/test_to_datetime.py index 8f59ee4c512a4..d727271bd6793 100644 --- a/pandas/tests/tools/test_to_datetime.py +++ b/pandas/tests/tools/test_to_datetime.py @@ -1006,9 +1006,9 @@ def test_convert_object_to_datetime_with_cache( (Series([np.NaN] * 200), Series([NaT] * 200, dtype="datetime64[ns]")), ), ) - def test_to_datetime_converts_null_like_to_nat(cache, input, expected): + def test_to_datetime_converts_null_like_to_nat(self, cache, input, expected): # GH35888 - result = to_datetime(input) + result = to_datetime(input, cache=cache) tm.assert_series_equal(result, expected) @pytest.mark.parametrize(