From f67ffe365d7ed8bd0e6576825076fd5145b13074 Mon Sep 17 00:00:00 2001 From: Ryan Gilmour Date: Thu, 12 Aug 2021 23:57:10 +0100 Subject: [PATCH 01/11] 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 02/11] 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 03/11] 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 04/11] 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( From 479a9789165007f8934e23413b6b5856d84d94c1 Mon Sep 17 00:00:00 2001 From: Ryan Gilmour Date: Thu, 12 Aug 2021 23:57:10 +0100 Subject: [PATCH 05/11] 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 5f8e0b4f70ec4..36421437f0fa7 100644 --- a/pandas/tests/tools/test_to_datetime.py +++ b/pandas/tests/tools/test_to_datetime.py @@ -2736,3 +2736,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 b0fe84e0a4006c112a1de29e907ea15e065f2379 Mon Sep 17 00:00:00 2001 From: Ryan Gilmour Date: Fri, 13 Aug 2021 00:25:38 +0100 Subject: [PATCH 06/11] 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 36421437f0fa7..95fecc9f52f9c 100644 --- a/pandas/tests/tools/test_to_datetime.py +++ b/pandas/tests/tools/test_to_datetime.py @@ -2748,6 +2748,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 a79d754749754abc2c18e113e2623a5fd8f378d8 Mon Sep 17 00:00:00 2001 From: Ryan Gilmour Date: Fri, 20 Aug 2021 13:31:38 +0000 Subject: [PATCH 07/11] 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 95fecc9f52f9c..f6ec8c5b9b15a 100644 --- a/pandas/tests/tools/test_to_datetime.py +++ b/pandas/tests/tools/test_to_datetime.py @@ -1066,6 +1066,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", [ @@ -2736,23 +2755,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 da9fa355cf09d2191f210c8b871470c5b32868fe Mon Sep 17 00:00:00 2001 From: Ryan Gilmour Date: Fri, 20 Aug 2021 18:11:43 +0000 Subject: [PATCH 08/11] 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 f6ec8c5b9b15a..de2027817a7d0 100644 --- a/pandas/tests/tools/test_to_datetime.py +++ b/pandas/tests/tools/test_to_datetime.py @@ -1080,9 +1080,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( From dadf5fd91acedd96b54656bb055b0e66d2704cf1 Mon Sep 17 00:00:00 2001 From: Ryan Gilmour Date: Fri, 21 Jan 2022 11:31:26 +0000 Subject: [PATCH 09/11] reduce test case series sizes --- pandas/tests/tools/test_to_datetime.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pandas/tests/tools/test_to_datetime.py b/pandas/tests/tools/test_to_datetime.py index de2027817a7d0..1e8e001781988 100644 --- a/pandas/tests/tools/test_to_datetime.py +++ b/pandas/tests/tools/test_to_datetime.py @@ -1071,13 +1071,13 @@ def test_convert_object_to_datetime_with_cache( ("input", "expected"), ( ( - Series([NaT] * 200 + [None] * 200, dtype="object"), - Series([NaT] * 400, dtype="datetime64[ns]"), + Series([NaT] * 20 + [None] * 20, dtype="object"), + Series([NaT] * 40, 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]")), + (Series([None] * 20), Series([NaT] * 20, dtype="datetime64[ns]")), + (Series([""] * 20), Series([NaT] * 20, dtype="datetime64[ns]")), + (Series([pd.NA] * 20), Series([NaT] * 20, dtype="datetime64[ns]")), + (Series([np.NaN] * 20), Series([NaT] * 20, dtype="datetime64[ns]")), ), ) def test_to_datetime_converts_null_like_to_nat(self, cache, input, expected): From 53335dfa2c7f5a96e31d639055123d7a8a4e2a70 Mon Sep 17 00:00:00 2001 From: Ryan Gilmour Date: Sun, 23 Jan 2022 17:51:00 +0000 Subject: [PATCH 10/11] ignore list item in type checking --- pandas/tests/tools/test_to_datetime.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/tools/test_to_datetime.py b/pandas/tests/tools/test_to_datetime.py index 1e8e001781988..edc5c43b5c1e5 100644 --- a/pandas/tests/tools/test_to_datetime.py +++ b/pandas/tests/tools/test_to_datetime.py @@ -1071,7 +1071,7 @@ def test_convert_object_to_datetime_with_cache( ("input", "expected"), ( ( - Series([NaT] * 20 + [None] * 20, dtype="object"), + Series([NaT] * 20 + [None] * 20, dtype="object"), # type: ignore[list-item] # noqa: E501 Series([NaT] * 40, dtype="datetime64[ns]"), ), (Series([None] * 20), Series([NaT] * 20, dtype="datetime64[ns]")), From b3862a33a4fb650a5d08843a588e150150058b79 Mon Sep 17 00:00:00 2001 From: Ryan Gilmour Date: Mon, 31 Jan 2022 20:27:38 +0000 Subject: [PATCH 11/11] test caching and non-caching behaviour --- pandas/tests/tools/test_to_datetime.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pandas/tests/tools/test_to_datetime.py b/pandas/tests/tools/test_to_datetime.py index edc5c43b5c1e5..1e05603f704a7 100644 --- a/pandas/tests/tools/test_to_datetime.py +++ b/pandas/tests/tools/test_to_datetime.py @@ -1074,10 +1074,18 @@ def test_convert_object_to_datetime_with_cache( Series([NaT] * 20 + [None] * 20, dtype="object"), # type: ignore[list-item] # noqa: E501 Series([NaT] * 40, dtype="datetime64[ns]"), ), + ( + Series([NaT] * 60 + [None] * 60, dtype="object"), # type: ignore[list-item] # noqa: E501 + Series([NaT] * 120, dtype="datetime64[ns]"), + ), (Series([None] * 20), Series([NaT] * 20, dtype="datetime64[ns]")), + (Series([None] * 60), Series([NaT] * 60, dtype="datetime64[ns]")), (Series([""] * 20), Series([NaT] * 20, dtype="datetime64[ns]")), + (Series([""] * 60), Series([NaT] * 60, dtype="datetime64[ns]")), (Series([pd.NA] * 20), Series([NaT] * 20, dtype="datetime64[ns]")), + (Series([pd.NA] * 60), Series([NaT] * 60, dtype="datetime64[ns]")), (Series([np.NaN] * 20), Series([NaT] * 20, dtype="datetime64[ns]")), + (Series([np.NaN] * 60), Series([NaT] * 60, dtype="datetime64[ns]")), ), ) def test_to_datetime_converts_null_like_to_nat(self, cache, input, expected):