From 04f904898728ba4d9b63efb43dab46f923014b50 Mon Sep 17 00:00:00 2001 From: Brock Date: Fri, 5 Jun 2020 16:02:29 -0700 Subject: [PATCH 1/4] TST: misplaced tslibs tests --- .../tseries/frequencies/test_frequencies.py | 25 +++++++++++++++++++ pandas/tests/tslibs/test_libfrequencies.py | 22 ---------------- 2 files changed, 25 insertions(+), 22 deletions(-) create mode 100644 pandas/tests/tseries/frequencies/test_frequencies.py diff --git a/pandas/tests/tseries/frequencies/test_frequencies.py b/pandas/tests/tseries/frequencies/test_frequencies.py new file mode 100644 index 0000000000000..ef272bc7e0821 --- /dev/null +++ b/pandas/tests/tseries/frequencies/test_frequencies.py @@ -0,0 +1,25 @@ +from pandas.tseries.frequencies import is_subperiod, is_superperiod +from pandas._libs.tslibs import offsets + +import pytest + + +@pytest.mark.parametrize( + "p1,p2,expected", + [ + # Input validation. + (offsets.MonthEnd(), None, False), + (offsets.YearEnd(), None, False), + (None, offsets.YearEnd(), False), + (None, offsets.MonthEnd(), False), + (None, None, False), + (offsets.YearEnd(), offsets.MonthEnd(), True), + (offsets.Hour(), offsets.Minute(), True), + (offsets.Second(), offsets.Milli(), True), + (offsets.Milli(), offsets.Micro(), True), + (offsets.Micro(), offsets.Nano(), True), + ], +) +def test_super_sub_symmetry(p1, p2, expected): + assert is_superperiod(p1, p2) is expected + assert is_subperiod(p2, p1) is expected diff --git a/pandas/tests/tslibs/test_libfrequencies.py b/pandas/tests/tslibs/test_libfrequencies.py index 65d3b15bb3dac..feaaaf6adca6f 100644 --- a/pandas/tests/tslibs/test_libfrequencies.py +++ b/pandas/tests/tslibs/test_libfrequencies.py @@ -4,7 +4,6 @@ from pandas._libs.tslibs.parsing import get_rule_month from pandas.tseries import offsets -from pandas.tseries.frequencies import is_subperiod, is_superperiod # TODO: move tests @pytest.mark.parametrize( @@ -56,27 +55,6 @@ def test_period_str_to_code(obj, expected): assert _period_str_to_code(obj) == expected -@pytest.mark.parametrize( - "p1,p2,expected", - [ - # Input validation. - (offsets.MonthEnd(), None, False), - (offsets.YearEnd(), None, False), - (None, offsets.YearEnd(), False), - (None, offsets.MonthEnd(), False), - (None, None, False), - (offsets.YearEnd(), offsets.MonthEnd(), True), - (offsets.Hour(), offsets.Minute(), True), - (offsets.Second(), offsets.Milli(), True), - (offsets.Milli(), offsets.Micro(), True), - (offsets.Micro(), offsets.Nano(), True), - ], -) -def test_super_sub_symmetry(p1, p2, expected): - assert is_superperiod(p1, p2) is expected - assert is_subperiod(p2, p1) is expected - - @pytest.mark.parametrize( "freq,expected,aliases", [ From 0c9229306a55f1a17bbb400cc66c9831c3450ca1 Mon Sep 17 00:00:00 2001 From: Brock Date: Fri, 5 Jun 2020 16:05:57 -0700 Subject: [PATCH 2/4] TST: move tslibs tests --- pandas/tests/{tseries/frequencies => tslibs}/test_to_offset.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename pandas/tests/{tseries/frequencies => tslibs}/test_to_offset.py (100%) diff --git a/pandas/tests/tseries/frequencies/test_to_offset.py b/pandas/tests/tslibs/test_to_offset.py similarity index 100% rename from pandas/tests/tseries/frequencies/test_to_offset.py rename to pandas/tests/tslibs/test_to_offset.py From 4e3c45c875d1e333f4371791ebc0eeef8613883a Mon Sep 17 00:00:00 2001 From: Brock Date: Fri, 5 Jun 2020 16:07:00 -0700 Subject: [PATCH 3/4] clean up imports --- pandas/tests/tseries/frequencies/test_freq_code.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/pandas/tests/tseries/frequencies/test_freq_code.py b/pandas/tests/tseries/frequencies/test_freq_code.py index d4eb31168b20e..4df221913b805 100644 --- a/pandas/tests/tseries/frequencies/test_freq_code.py +++ b/pandas/tests/tseries/frequencies/test_freq_code.py @@ -1,6 +1,6 @@ import pytest -from pandas._libs.tslibs import to_offset +from pandas._libs.tslibs import Resolution, offsets, to_offset from pandas._libs.tslibs.frequencies import ( FreqGroup, _attrname_to_abbrevs, @@ -9,9 +9,6 @@ get_freq_group, get_to_timestamp_base, ) -from pandas._libs.tslibs.resolution import Resolution as _reso - -import pandas.tseries.offsets as offsets @pytest.fixture(params=list(_period_code_map.items())) @@ -103,19 +100,19 @@ def test_get_to_timestamp_base(freqstr, exp_freqstr): ], ) def test_get_attrname_from_abbrev(freqstr, expected): - assert _reso.get_reso_from_freq(freqstr).attrname == expected + assert Resolution.get_reso_from_freq(freqstr).attrname == expected @pytest.mark.parametrize("freq", ["A", "Q", "M"]) def test_get_freq_unsupported_(freq): # Lowest-frequency resolution is for Day with pytest.raises(KeyError, match=freq.lower()): - _reso.get_reso_from_freq(freq) + Resolution.get_reso_from_freq(freq) @pytest.mark.parametrize("freq", ["D", "H", "T", "S", "L", "U", "N"]) def test_get_freq_roundtrip2(freq): - obj = _reso.get_reso_from_freq(freq) + obj = Resolution.get_reso_from_freq(freq) result = _attrname_to_abbrevs[obj.attrname] assert freq == result From 3fedbaee49b26ff743210b7455b297ef63ebcfd7 Mon Sep 17 00:00:00 2001 From: Brock Date: Fri, 5 Jun 2020 16:30:22 -0700 Subject: [PATCH 4/4] isort fixup --- pandas/tests/tseries/frequencies/test_frequencies.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pandas/tests/tseries/frequencies/test_frequencies.py b/pandas/tests/tseries/frequencies/test_frequencies.py index ef272bc7e0821..0479de8e8e7c3 100644 --- a/pandas/tests/tseries/frequencies/test_frequencies.py +++ b/pandas/tests/tseries/frequencies/test_frequencies.py @@ -1,7 +1,8 @@ -from pandas.tseries.frequencies import is_subperiod, is_superperiod +import pytest + from pandas._libs.tslibs import offsets -import pytest +from pandas.tseries.frequencies import is_subperiod, is_superperiod @pytest.mark.parametrize(