From 4fd071c71db4fc5da705fc30e99ba067c7ef7c76 Mon Sep 17 00:00:00 2001 From: MomIsBestFriend <> Date: Thu, 5 Mar 2020 17:54:47 +0200 Subject: [PATCH 01/14] TST: Cleaned tests --- .../offsets/test_offsets_properties.py | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/pandas/tests/tseries/offsets/test_offsets_properties.py b/pandas/tests/tseries/offsets/test_offsets_properties.py index 716d3ff3faf1c..4e07318366d0e 100644 --- a/pandas/tests/tseries/offsets/test_offsets_properties.py +++ b/pandas/tests/tseries/offsets/test_offsets_properties.py @@ -85,8 +85,6 @@ # Offset-specific behaviour tests -# Based on CI runs: Always passes on OSX, fails on Linux, sometimes on Windows -@pytest.mark.xfail(strict=False, reason="inconsistent between OSs, Pythons") @given(gen_random_datetime, gen_yqm_offset) def test_on_offset_implementations(dt, offset): assume(not offset.normalize) @@ -98,15 +96,19 @@ def test_on_offset_implementations(dt, offset): @pytest.mark.xfail( - reason="res_v2 below is incorrect, needs to use the " - "commented-out version with tz_localize. " - "But with that fix in place, hypothesis then " - "has errors in timezone generation." + reason=( + "res_v2 below is incorrect, needs to use the " + "commented-out version with tz_localize. " + "But with that fix in place, hypothesis then " + "has errors in timezone generation." + ) ) @given(gen_yqm_offset, gen_date_range) def test_apply_index_implementations(offset, rng): # offset.apply_index(dti)[i] should match dti[i] + offset - assume(offset.n != 0) # TODO: test for that case separately + + # TODO: test for that case separately + assume(offset.n != 0) # rng = pd.date_range(start='1/1/2000', periods=100000, freq='T') ser = pd.Series(rng) @@ -116,13 +118,14 @@ def test_apply_index_implementations(offset, rng): # res_v2 = offset.apply_index(rng.tz_localize(None)).tz_localize(rng.tz) assert (res == res_v2).all() + # apply_index is only for indexes, not series, so no res2_v2 assert res[0] == rng[0] + offset assert res[-1] == rng[-1] + offset res2 = ser + offset - # apply_index is only for indexes, not series, so no res2_v2 + + # TODO: Check randomly assorted entries, not just first/last assert res2.iloc[0] == ser.iloc[0] + offset assert res2.iloc[-1] == ser.iloc[-1] + offset - # TODO: Check randomly assorted entries, not just first/last @pytest.mark.xfail # TODO: reason? From d69692cf3070a5a3a21a29c1f21c92c9da088989 Mon Sep 17 00:00:00 2001 From: MomIsBestFriend <> Date: Thu, 5 Mar 2020 17:57:48 +0200 Subject: [PATCH 02/14] Fixed another test --- .../tests/tseries/offsets/test_offsets_properties.py | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/pandas/tests/tseries/offsets/test_offsets_properties.py b/pandas/tests/tseries/offsets/test_offsets_properties.py index 4e07318366d0e..362db618b97f4 100644 --- a/pandas/tests/tseries/offsets/test_offsets_properties.py +++ b/pandas/tests/tseries/offsets/test_offsets_properties.py @@ -94,15 +94,6 @@ def test_on_offset_implementations(dt, offset): compare = (dt + offset) - offset assert offset.is_on_offset(dt) == (compare == dt) - -@pytest.mark.xfail( - reason=( - "res_v2 below is incorrect, needs to use the " - "commented-out version with tz_localize. " - "But with that fix in place, hypothesis then " - "has errors in timezone generation." - ) -) @given(gen_yqm_offset, gen_date_range) def test_apply_index_implementations(offset, rng): # offset.apply_index(dti)[i] should match dti[i] + offset @@ -110,12 +101,11 @@ def test_apply_index_implementations(offset, rng): # TODO: test for that case separately assume(offset.n != 0) - # rng = pd.date_range(start='1/1/2000', periods=100000, freq='T') ser = pd.Series(rng) res = rng + offset res_v2 = offset.apply_index(rng) - # res_v2 = offset.apply_index(rng.tz_localize(None)).tz_localize(rng.tz) + res_v2 = offset.apply_index(rng.tz_localize(None)).tz_localize(rng.tz) assert (res == res_v2).all() # apply_index is only for indexes, not series, so no res2_v2 From 6112dddf027d86275833a688c527dfc19ebc65f3 Mon Sep 17 00:00:00 2001 From: MomIsBestFriend <> Date: Thu, 5 Mar 2020 18:06:00 +0200 Subject: [PATCH 03/14] Cosmetic changes --- pandas/tests/tseries/offsets/test_offsets_properties.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pandas/tests/tseries/offsets/test_offsets_properties.py b/pandas/tests/tseries/offsets/test_offsets_properties.py index 362db618b97f4..e239657a42a1e 100644 --- a/pandas/tests/tseries/offsets/test_offsets_properties.py +++ b/pandas/tests/tseries/offsets/test_offsets_properties.py @@ -94,6 +94,7 @@ def test_on_offset_implementations(dt, offset): compare = (dt + offset) - offset assert offset.is_on_offset(dt) == (compare == dt) + @given(gen_yqm_offset, gen_date_range) def test_apply_index_implementations(offset, rng): # offset.apply_index(dti)[i] should match dti[i] + offset @@ -121,9 +122,12 @@ def test_apply_index_implementations(offset, rng): @pytest.mark.xfail # TODO: reason? @given(gen_yqm_offset) def test_shift_across_dst(offset): - # GH#18319 check that 1) timezone is correctly normalized and + # GH#18319 + # check that: + # 1) timezone is correctly normalized and # 2) that hour is not incorrectly changed by this normalization # Note that dti includes a transition across DST boundary + dti = pd.date_range( start="2017-10-30 12:00:00", end="2017-11-06", freq="D", tz="US/Eastern" ) From 86415fac040e6eae68b06f6150808967b77a1e27 Mon Sep 17 00:00:00 2001 From: MomIsBestFriend <> Date: Thu, 5 Mar 2020 19:25:23 +0200 Subject: [PATCH 04/14] Skiping tests if dateutils 2.7.0 or higher is not installed --- pandas/tests/tseries/offsets/test_offsets_properties.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pandas/tests/tseries/offsets/test_offsets_properties.py b/pandas/tests/tseries/offsets/test_offsets_properties.py index e239657a42a1e..f7667c1af13b3 100644 --- a/pandas/tests/tseries/offsets/test_offsets_properties.py +++ b/pandas/tests/tseries/offsets/test_offsets_properties.py @@ -9,6 +9,7 @@ """ import warnings +import dateutil from hypothesis import assume, given, strategies as st from hypothesis.extra.dateutil import timezones as dateutil_timezones from hypothesis.extra.pytz import timezones as pytz_timezones @@ -85,6 +86,10 @@ # Offset-specific behaviour tests +@pytest.mark.skipif( + dateutil.__version__ < "2.7", + reason="hypothesis uses dateutil.tz.UTC which was intreduced in dateutils 2.7.0", +) @given(gen_random_datetime, gen_yqm_offset) def test_on_offset_implementations(dt, offset): assume(not offset.normalize) @@ -95,6 +100,10 @@ def test_on_offset_implementations(dt, offset): assert offset.is_on_offset(dt) == (compare == dt) +@pytest.mark.skipif( + dateutil.__version__ < "2.7", + reason="hypothesis uses dateutil.tz.UTC which was intreduced in dateutils 2.7.0", +) @given(gen_yqm_offset, gen_date_range) def test_apply_index_implementations(offset, rng): # offset.apply_index(dti)[i] should match dti[i] + offset From a1ad09b97712e51f7d242dc277a93a202473a0d6 Mon Sep 17 00:00:00 2001 From: MomIsBestFriend <> Date: Fri, 6 Mar 2020 10:23:00 +0200 Subject: [PATCH 05/14] Suppressing mypy errors --- pandas/tests/tseries/offsets/test_offsets_properties.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pandas/tests/tseries/offsets/test_offsets_properties.py b/pandas/tests/tseries/offsets/test_offsets_properties.py index f7667c1af13b3..044c0839138f2 100644 --- a/pandas/tests/tseries/offsets/test_offsets_properties.py +++ b/pandas/tests/tseries/offsets/test_offsets_properties.py @@ -33,6 +33,8 @@ YearEnd, ) +DATEUTIL_VERSION = dateutil.__version__ # type: ignore + # ---------------------------------------------------------------- # Helpers for generating random data @@ -87,7 +89,7 @@ @pytest.mark.skipif( - dateutil.__version__ < "2.7", + DATEUTIL_VERSION < "2.7", reason="hypothesis uses dateutil.tz.UTC which was intreduced in dateutils 2.7.0", ) @given(gen_random_datetime, gen_yqm_offset) @@ -101,7 +103,7 @@ def test_on_offset_implementations(dt, offset): @pytest.mark.skipif( - dateutil.__version__ < "2.7", + DATEUTIL_VERSION < "2.7", reason="hypothesis uses dateutil.tz.UTC which was intreduced in dateutils 2.7.0", ) @given(gen_yqm_offset, gen_date_range) From 30d9ef754a706519d4d9cf77a5efa0f89a084f37 Mon Sep 17 00:00:00 2001 From: MomIsBestFriend <> Date: Wed, 18 Mar 2020 22:25:44 +0200 Subject: [PATCH 06/14] Using LooseVersion REF: https://github.com/pandas-dev/pandas/pull/32465#discussion_r390001432 --- pandas/tests/tseries/offsets/test_offsets_properties.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pandas/tests/tseries/offsets/test_offsets_properties.py b/pandas/tests/tseries/offsets/test_offsets_properties.py index 044c0839138f2..ffb7ed309bacc 100644 --- a/pandas/tests/tseries/offsets/test_offsets_properties.py +++ b/pandas/tests/tseries/offsets/test_offsets_properties.py @@ -7,6 +7,7 @@ You may wish to consult the previous version for inspiration on further tests, or when trying to pin down the bugs exposed by the tests below. """ +from distutils.version import LooseVersion import warnings import dateutil @@ -33,7 +34,7 @@ YearEnd, ) -DATEUTIL_VERSION = dateutil.__version__ # type: ignore +DATEUTIL_VERSION = LooseVersion(dateutil.__version__) # type: ignore # ---------------------------------------------------------------- # Helpers for generating random data From 9087485233d6b9a104446c2e744d5b9ab9b1264a Mon Sep 17 00:00:00 2001 From: MomIsBestFriend <> Date: Thu, 19 Mar 2020 17:58:34 +0200 Subject: [PATCH 07/14] Added simplefilter for warnings --- pandas/tests/tseries/offsets/test_offsets_properties.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pandas/tests/tseries/offsets/test_offsets_properties.py b/pandas/tests/tseries/offsets/test_offsets_properties.py index ffb7ed309bacc..4a3e8d78a8a02 100644 --- a/pandas/tests/tseries/offsets/test_offsets_properties.py +++ b/pandas/tests/tseries/offsets/test_offsets_properties.py @@ -111,6 +111,9 @@ def test_on_offset_implementations(dt, offset): def test_apply_index_implementations(offset, rng): # offset.apply_index(dti)[i] should match dti[i] + offset + # TODO: Remove this `warnings.simplefilter` + warnings.simplefilter("ignore") + # TODO: test for that case separately assume(offset.n != 0) From 889b7261dccc9f67bad42f98629cf039bb28dd3d Mon Sep 17 00:00:00 2001 From: MomIsBestFriend <> Date: Thu, 19 Mar 2020 18:02:03 +0200 Subject: [PATCH 08/14] Typos REF: https://github.com/pandas-dev/pandas/pull/32465#discussion_r390001373 --- pandas/tests/tseries/offsets/test_offsets_properties.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/tests/tseries/offsets/test_offsets_properties.py b/pandas/tests/tseries/offsets/test_offsets_properties.py index 4a3e8d78a8a02..d4fd2f656a0d4 100644 --- a/pandas/tests/tseries/offsets/test_offsets_properties.py +++ b/pandas/tests/tseries/offsets/test_offsets_properties.py @@ -91,7 +91,7 @@ @pytest.mark.skipif( DATEUTIL_VERSION < "2.7", - reason="hypothesis uses dateutil.tz.UTC which was intreduced in dateutils 2.7.0", + reason="hypothesis uses dateutil.tz.UTC which was introduced in dateutils 2.7.0", ) @given(gen_random_datetime, gen_yqm_offset) def test_on_offset_implementations(dt, offset): @@ -105,7 +105,7 @@ def test_on_offset_implementations(dt, offset): @pytest.mark.skipif( DATEUTIL_VERSION < "2.7", - reason="hypothesis uses dateutil.tz.UTC which was intreduced in dateutils 2.7.0", + reason="hypothesis uses dateutil.tz.UTC which was introduced in dateutils 2.7.0", ) @given(gen_yqm_offset, gen_date_range) def test_apply_index_implementations(offset, rng): From a33bb0ca67714c845de97333819210dce9141680 Mon Sep 17 00:00:00 2001 From: MomIsBestFriend <> Date: Thu, 19 Mar 2020 18:39:52 +0200 Subject: [PATCH 09/14] Using td.skip.if_no decorator REF: https://github.com/pandas-dev/pandas/pull/32465#discussion_r395157803 --- .../tseries/offsets/test_offsets_properties.py | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/pandas/tests/tseries/offsets/test_offsets_properties.py b/pandas/tests/tseries/offsets/test_offsets_properties.py index d4fd2f656a0d4..ff6bc87e13279 100644 --- a/pandas/tests/tseries/offsets/test_offsets_properties.py +++ b/pandas/tests/tseries/offsets/test_offsets_properties.py @@ -7,15 +7,15 @@ You may wish to consult the previous version for inspiration on further tests, or when trying to pin down the bugs exposed by the tests below. """ -from distutils.version import LooseVersion import warnings -import dateutil from hypothesis import assume, given, strategies as st from hypothesis.extra.dateutil import timezones as dateutil_timezones from hypothesis.extra.pytz import timezones as pytz_timezones import pytest +import pandas.util._test_decorators as td + import pandas as pd from pandas import Timestamp @@ -34,8 +34,6 @@ YearEnd, ) -DATEUTIL_VERSION = LooseVersion(dateutil.__version__) # type: ignore - # ---------------------------------------------------------------- # Helpers for generating random data @@ -89,10 +87,7 @@ # Offset-specific behaviour tests -@pytest.mark.skipif( - DATEUTIL_VERSION < "2.7", - reason="hypothesis uses dateutil.tz.UTC which was introduced in dateutils 2.7.0", -) +@td.skip_if_no("dateutil", "2.7") @given(gen_random_datetime, gen_yqm_offset) def test_on_offset_implementations(dt, offset): assume(not offset.normalize) @@ -103,10 +98,7 @@ def test_on_offset_implementations(dt, offset): assert offset.is_on_offset(dt) == (compare == dt) -@pytest.mark.skipif( - DATEUTIL_VERSION < "2.7", - reason="hypothesis uses dateutil.tz.UTC which was introduced in dateutils 2.7.0", -) +@td.skip_if_no("dateutil", "2.7") @given(gen_yqm_offset, gen_date_range) def test_apply_index_implementations(offset, rng): # offset.apply_index(dti)[i] should match dti[i] + offset From d8a51f6eff77e4e96c04dd15c1ba35c06bad4e70 Mon Sep 17 00:00:00 2001 From: MomIsBestFriend <> Date: Wed, 25 Mar 2020 20:44:33 +0200 Subject: [PATCH 10/14] Delted duplicate apply_index REF: https://github.com/pandas-dev/pandas/pull/32465#discussion_r398045781 --- pandas/tests/tseries/offsets/test_offsets_properties.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pandas/tests/tseries/offsets/test_offsets_properties.py b/pandas/tests/tseries/offsets/test_offsets_properties.py index ff6bc87e13279..a4a616955d4c7 100644 --- a/pandas/tests/tseries/offsets/test_offsets_properties.py +++ b/pandas/tests/tseries/offsets/test_offsets_properties.py @@ -112,7 +112,6 @@ def test_apply_index_implementations(offset, rng): ser = pd.Series(rng) res = rng + offset - res_v2 = offset.apply_index(rng) res_v2 = offset.apply_index(rng.tz_localize(None)).tz_localize(rng.tz) assert (res == res_v2).all() From 3a508cfb7aa72a54fb738775670575197b543744 Mon Sep 17 00:00:00 2001 From: MomIsBestFriend <> Date: Wed, 25 Mar 2020 20:46:39 +0200 Subject: [PATCH 11/14] Remove warnings.simplefilter --- pandas/tests/tseries/offsets/test_offsets_properties.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/pandas/tests/tseries/offsets/test_offsets_properties.py b/pandas/tests/tseries/offsets/test_offsets_properties.py index a4a616955d4c7..7e3f9fa78787f 100644 --- a/pandas/tests/tseries/offsets/test_offsets_properties.py +++ b/pandas/tests/tseries/offsets/test_offsets_properties.py @@ -103,9 +103,6 @@ def test_on_offset_implementations(dt, offset): def test_apply_index_implementations(offset, rng): # offset.apply_index(dti)[i] should match dti[i] + offset - # TODO: Remove this `warnings.simplefilter` - warnings.simplefilter("ignore") - # TODO: test for that case separately assume(offset.n != 0) From 635b28e20199b29cf1c1f92307230c6fb1fb208c Mon Sep 17 00:00:00 2001 From: MomIsBestFriend <> Date: Sun, 29 Mar 2020 15:54:06 +0300 Subject: [PATCH 12/14] Trying with smaller daterange --- pandas/tests/tseries/offsets/test_offsets_properties.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/tseries/offsets/test_offsets_properties.py b/pandas/tests/tseries/offsets/test_offsets_properties.py index 7e3f9fa78787f..d8bc30030c024 100644 --- a/pandas/tests/tseries/offsets/test_offsets_properties.py +++ b/pandas/tests/tseries/offsets/test_offsets_properties.py @@ -46,7 +46,7 @@ pd.date_range, start=st.datetimes( # TODO: Choose the min/max values more systematically - min_value=Timestamp(1900, 1, 1).to_pydatetime(), + min_value=Timestamp(2000, 1, 1).to_pydatetime(), max_value=Timestamp(2100, 1, 1).to_pydatetime(), ), periods=st.integers(min_value=2, max_value=100), From baf83d4b17b5e3ca7a985496c1282b93e0a65722 Mon Sep 17 00:00:00 2001 From: MomIsBestFriend <> Date: Sun, 29 Mar 2020 17:54:22 +0300 Subject: [PATCH 13/14] Revert "Trying with smaller daterange" This reverts commit 635b28e20199b29cf1c1f92307230c6fb1fb208c. --- pandas/tests/tseries/offsets/test_offsets_properties.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/tseries/offsets/test_offsets_properties.py b/pandas/tests/tseries/offsets/test_offsets_properties.py index d8bc30030c024..7e3f9fa78787f 100644 --- a/pandas/tests/tseries/offsets/test_offsets_properties.py +++ b/pandas/tests/tseries/offsets/test_offsets_properties.py @@ -46,7 +46,7 @@ pd.date_range, start=st.datetimes( # TODO: Choose the min/max values more systematically - min_value=Timestamp(2000, 1, 1).to_pydatetime(), + min_value=Timestamp(1900, 1, 1).to_pydatetime(), max_value=Timestamp(2100, 1, 1).to_pydatetime(), ), periods=st.integers(min_value=2, max_value=100), From e4a9d0b0338549e3fa689080bccc2e543e271b7b Mon Sep 17 00:00:00 2001 From: MomIsBestFriend <> Date: Fri, 10 Apr 2020 20:23:27 +0300 Subject: [PATCH 14/14] Removed skip decorators --- pandas/tests/tseries/offsets/test_offsets_properties.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/pandas/tests/tseries/offsets/test_offsets_properties.py b/pandas/tests/tseries/offsets/test_offsets_properties.py index 7e3f9fa78787f..6e01c83c725bf 100644 --- a/pandas/tests/tseries/offsets/test_offsets_properties.py +++ b/pandas/tests/tseries/offsets/test_offsets_properties.py @@ -14,8 +14,6 @@ from hypothesis.extra.pytz import timezones as pytz_timezones import pytest -import pandas.util._test_decorators as td - import pandas as pd from pandas import Timestamp @@ -87,7 +85,6 @@ # Offset-specific behaviour tests -@td.skip_if_no("dateutil", "2.7") @given(gen_random_datetime, gen_yqm_offset) def test_on_offset_implementations(dt, offset): assume(not offset.normalize) @@ -98,7 +95,6 @@ def test_on_offset_implementations(dt, offset): assert offset.is_on_offset(dt) == (compare == dt) -@td.skip_if_no("dateutil", "2.7") @given(gen_yqm_offset, gen_date_range) def test_apply_index_implementations(offset, rng): # offset.apply_index(dti)[i] should match dti[i] + offset