From adcf608929018a4706f3462b3ba388d97939e00f Mon Sep 17 00:00:00 2001 From: ChrisAlbertsen Date: Tue, 1 Feb 2022 21:27:28 +0100 Subject: [PATCH 1/5] TST: add test for compatibility with numpy datetime64 #41617 --- .../tseries/frequencies/test_freq_code.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/pandas/tests/tseries/frequencies/test_freq_code.py b/pandas/tests/tseries/frequencies/test_freq_code.py index 92795245103d0..72ad3f8cf5529 100644 --- a/pandas/tests/tseries/frequencies/test_freq_code.py +++ b/pandas/tests/tseries/frequencies/test_freq_code.py @@ -6,6 +6,7 @@ to_offset, ) from pandas._libs.tslibs.dtypes import _attrname_to_abbrevs +from numpy import datetime64 @pytest.mark.parametrize( @@ -78,3 +79,20 @@ def test_cat(args): with pytest.raises(ValueError, match=msg): to_offset(str(args[0]) + args[1]) + +@pytest.mark.parametrize( + 'freqstr,expected', + [ + ('1H','2021-01-01T09:00:00'), + ('1D','2021-01-01T08:00:00'), + ('1W','2021-01-03T08:00:00'), + ('1M','2021-01-31T08:00:00'), + ('1Y','2021-12-31T08:00:00') + ] +) +def test_compatibility(freqstr,expected): + ts_np = datetime64('2021-01-01T08:00:00.00') + do = to_offset(freqstr) + + assert ts_np + do == datetime64(expected) + \ No newline at end of file From 5c63b694e14d4a55d99245c09a65511e56a05812 Mon Sep 17 00:00:00 2001 From: ChrisAlbertsen Date: Tue, 1 Feb 2022 21:39:40 +0100 Subject: [PATCH 2/5] TST; add test for compatibility with numpy datetime64 (#41617) --- .../tseries/frequencies/test_freq_code.py | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/pandas/tests/tseries/frequencies/test_freq_code.py b/pandas/tests/tseries/frequencies/test_freq_code.py index 72ad3f8cf5529..eed4209a0dfe2 100644 --- a/pandas/tests/tseries/frequencies/test_freq_code.py +++ b/pandas/tests/tseries/frequencies/test_freq_code.py @@ -80,19 +80,18 @@ def test_cat(args): with pytest.raises(ValueError, match=msg): to_offset(str(args[0]) + args[1]) + @pytest.mark.parametrize( - 'freqstr,expected', + "freqstr,expected", [ - ('1H','2021-01-01T09:00:00'), - ('1D','2021-01-01T08:00:00'), - ('1W','2021-01-03T08:00:00'), - ('1M','2021-01-31T08:00:00'), - ('1Y','2021-12-31T08:00:00') + ("1H","2021-01-01T09:00:00"), + ("1D","2021-01-01T08:00:00"), + ("1W","2021-01-03T08:00:00"), + ("1M","2021-01-31T08:00:00"), + ("1Y","2021-12-31T08:00:00") ] ) -def test_compatibility(freqstr,expected): - ts_np = datetime64('2021-01-01T08:00:00.00') +def test_compatibility(freqstr,expected): + ts_np = datetime64("2021-01-01T08:00:00.00") do = to_offset(freqstr) - - assert ts_np + do == datetime64(expected) - \ No newline at end of file + assert ts_np + do == datetime64(expected) \ No newline at end of file From bdd250375be4ea1139f75d2032e15769cd686526 Mon Sep 17 00:00:00 2001 From: ChrisAlbertsen Date: Wed, 2 Feb 2022 21:30:00 +0100 Subject: [PATCH 3/5] Fixed a fat finger error in one of the expected values --- pandas/tests/tseries/frequencies/test_freq_code.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/tseries/frequencies/test_freq_code.py b/pandas/tests/tseries/frequencies/test_freq_code.py index eed4209a0dfe2..ec9555aaca8bc 100644 --- a/pandas/tests/tseries/frequencies/test_freq_code.py +++ b/pandas/tests/tseries/frequencies/test_freq_code.py @@ -85,7 +85,7 @@ def test_cat(args): "freqstr,expected", [ ("1H","2021-01-01T09:00:00"), - ("1D","2021-01-01T08:00:00"), + ("1D","2021-01-02T08:00:00"), ("1W","2021-01-03T08:00:00"), ("1M","2021-01-31T08:00:00"), ("1Y","2021-12-31T08:00:00") From 9e2310d52cb769e242b2ff72e4336241c89c49bd Mon Sep 17 00:00:00 2001 From: ChrisAlbertsen Date: Wed, 2 Feb 2022 21:12:07 +0000 Subject: [PATCH 4/5] Fixes from pre-commit [automated commit] --- .../tseries/frequencies/test_freq_code.py | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/pandas/tests/tseries/frequencies/test_freq_code.py b/pandas/tests/tseries/frequencies/test_freq_code.py index ec9555aaca8bc..9a84cc03510cb 100644 --- a/pandas/tests/tseries/frequencies/test_freq_code.py +++ b/pandas/tests/tseries/frequencies/test_freq_code.py @@ -1,3 +1,4 @@ +from numpy import datetime64 import pytest from pandas._libs.tslibs import ( @@ -6,7 +7,6 @@ to_offset, ) from pandas._libs.tslibs.dtypes import _attrname_to_abbrevs -from numpy import datetime64 @pytest.mark.parametrize( @@ -82,16 +82,16 @@ def test_cat(args): @pytest.mark.parametrize( - "freqstr,expected", - [ - ("1H","2021-01-01T09:00:00"), - ("1D","2021-01-02T08:00:00"), - ("1W","2021-01-03T08:00:00"), - ("1M","2021-01-31T08:00:00"), - ("1Y","2021-12-31T08:00:00") - ] + "freqstr,expected", + [ + ("1H", "2021-01-01T09:00:00"), + ("1D", "2021-01-02T08:00:00"), + ("1W", "2021-01-03T08:00:00"), + ("1M", "2021-01-31T08:00:00"), + ("1Y", "2021-12-31T08:00:00"), + ], ) -def test_compatibility(freqstr,expected): +def test_compatibility(freqstr, expected): ts_np = datetime64("2021-01-01T08:00:00.00") do = to_offset(freqstr) - assert ts_np + do == datetime64(expected) \ No newline at end of file + assert ts_np + do == datetime64(expected) From da2d8758ccd125f737ab1b272b8a7369131bfb50 Mon Sep 17 00:00:00 2001 From: ChrisAlbertsen Date: Thu, 10 Feb 2022 07:50:56 +0100 Subject: [PATCH 5/5] changed numpy import --- pandas/tests/tseries/frequencies/test_freq_code.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pandas/tests/tseries/frequencies/test_freq_code.py b/pandas/tests/tseries/frequencies/test_freq_code.py index 9a84cc03510cb..4d8c4ddbce441 100644 --- a/pandas/tests/tseries/frequencies/test_freq_code.py +++ b/pandas/tests/tseries/frequencies/test_freq_code.py @@ -1,4 +1,4 @@ -from numpy import datetime64 +import numpy as np import pytest from pandas._libs.tslibs import ( @@ -92,6 +92,6 @@ def test_cat(args): ], ) def test_compatibility(freqstr, expected): - ts_np = datetime64("2021-01-01T08:00:00.00") + ts_np = np.datetime64("2021-01-01T08:00:00.00") do = to_offset(freqstr) - assert ts_np + do == datetime64(expected) + assert ts_np + do == np.datetime64(expected)