Skip to content

Commit

Permalink
test pd freq strings are passed through
Browse files Browse the repository at this point in the history
  • Loading branch information
mathause committed Feb 15, 2024
1 parent f86355b commit 6a8001b
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 6 deletions.
2 changes: 1 addition & 1 deletion xarray/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def _importorskip(
has_pint, requires_pint = _importorskip("pint")
has_numexpr, requires_numexpr = _importorskip("numexpr")
has_flox, requires_flox = _importorskip("flox")
has_pandas_gt_2_2, __ = _importorskip("pandas", "2.2")
has_pandas_ge_2_2, __ = _importorskip("pandas", "2.2")


# some special cases
Expand Down
52 changes: 47 additions & 5 deletions xarray/tests/test_cftime_offsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
_CFTIME_CALENDARS,
assert_no_warnings,
has_cftime,
has_pandas_gt_2_2,
has_pandas_ge_2_2,
requires_cftime,
)

Expand Down Expand Up @@ -1611,7 +1611,7 @@ def test_to_offset_deprecation_warning(freq):
to_offset(freq)


@pytest.mark.skipif(has_pandas_gt_2_2, reason="only relevant for pandas lt 2.2")
@pytest.mark.skipif(has_pandas_ge_2_2, reason="only relevant for pandas lt 2.2")
@pytest.mark.parametrize(
"freq, expected",
(
Expand All @@ -1636,7 +1636,7 @@ def test_legacy_to_new_freq(freq, expected, n):
assert result == expected


@pytest.mark.skipif(has_pandas_gt_2_2, reason="only relevant for pandas lt 2.2")
@pytest.mark.skipif(has_pandas_ge_2_2, reason="only relevant for pandas lt 2.2")
@pytest.mark.parametrize("year_alias", ("YE", "Y", "A"))
@pytest.mark.parametrize("n", ("", "2"))
def test_legacy_to_new_freq_anchored(year_alias, n):
Expand All @@ -1649,7 +1649,7 @@ def test_legacy_to_new_freq_anchored(year_alias, n):
assert result == expected


@pytest.mark.skipif(has_pandas_gt_2_2, reason="only relevant for pandas lt 2.2")
@pytest.mark.skipif(has_pandas_ge_2_2, reason="only relevant for pandas lt 2.2")
@pytest.mark.filterwarnings("ignore:'[AY]' is deprecated")
@pytest.mark.parametrize(
"freq, expected",
Expand All @@ -1665,7 +1665,7 @@ def test_new_to_legacy_freq(freq, expected, n):
assert result == expected


@pytest.mark.skipif(has_pandas_gt_2_2, reason="only relevant for pandas lt 2.2")
@pytest.mark.skipif(has_pandas_ge_2_2, reason="only relevant for pandas lt 2.2")
@pytest.mark.filterwarnings("ignore:'[AY]-.{3}' is deprecated")
@pytest.mark.parametrize("year_alias", ("A", "Y", "YE"))
@pytest.mark.parametrize("n", ("", "2"))
Expand All @@ -1679,6 +1679,48 @@ def test_new_to_legacy_freq_anchored(year_alias, n):
assert result == expected


@pytest.mark.skipif(has_pandas_ge_2_2, reason="only for pandas lt 2.2")
@pytest.mark.parametrize(
"freq, expected",
(
# pandas-only freq strings are passed through
("BH", "BH"),
("CBH", "CBH"),
("N", "N"),
),
)
def test_legacy_to_new_freq_pd_freq_passthrough(freq, expected):

result = _legacy_to_new_freq(freq)
assert result == expected


@pytest.mark.filterwarnings("ignore:'.' is deprecated ")
@pytest.mark.skipif(has_pandas_ge_2_2, reason="only for pandas lt 2.2")
@pytest.mark.parametrize(
"freq, expected",
(
# these are each valid in pandas lt 2.2
("T", "T"),
("min", "min"),
("S", "S"),
("s", "s"),
("L", "L"),
("ms", "ms"),
("U", "U"),
("us", "us"),
# pandas-only freq strings are passed through
("bh", "bh"),
("cbh", "cbh"),
("ns", "ns"),
),
)
def test_new_to_legacy_freq_pd_freq_passthrough(freq, expected):

result = _new_to_legacy_freq(freq)
assert result == expected


@pytest.mark.filterwarnings("ignore:Converting a CFTimeIndex with:")
@pytest.mark.parametrize("start", ("2000", "2001"))
@pytest.mark.parametrize("end", ("2000", "2001"))
Expand Down

0 comments on commit 6a8001b

Please sign in to comment.