From 06277b7459ce2b140f6260b933936046318653ae Mon Sep 17 00:00:00 2001 From: MarcoGorelli <33491632+MarcoGorelli@users.noreply.github.com> Date: Fri, 12 Jan 2024 19:14:20 +0000 Subject: [PATCH 1/3] dont raise if users use (undocumented) "m" for "month end", warn to use "ME" instead --- pandas/_libs/tslibs/offsets.pyx | 6 +++--- pandas/tests/indexes/datetimes/test_date_range.py | 9 +++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index 84544322b57a8..446088821b10d 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -4860,15 +4860,15 @@ cpdef to_offset(freq, bint is_period=False): tups = zip(split[0::4], split[1::4], split[2::4]) for n, (sep, stride, name) in enumerate(tups): - if is_period is False and name in c_OFFSET_DEPR_FREQSTR: + if is_period is False and name.upper() in c_OFFSET_DEPR_FREQSTR: warnings.warn( f"\'{name}\' is deprecated and will be removed " f"in a future version, please use " - f"\'{c_OFFSET_DEPR_FREQSTR.get(name)}\' instead.", + f"\'{c_OFFSET_DEPR_FREQSTR.get(name.upper())}\' instead.", FutureWarning, stacklevel=find_stack_level(), ) - name = c_OFFSET_DEPR_FREQSTR[name] + name = c_OFFSET_DEPR_FREQSTR[name.upper()] if is_period is True and name in c_REVERSE_OFFSET_DEPR_FREQSTR: if name.startswith("Y"): raise ValueError( diff --git a/pandas/tests/indexes/datetimes/test_date_range.py b/pandas/tests/indexes/datetimes/test_date_range.py index ec158f7b194a0..69f2ba8a4deab 100644 --- a/pandas/tests/indexes/datetimes/test_date_range.py +++ b/pandas/tests/indexes/datetimes/test_date_range.py @@ -818,6 +818,15 @@ def test_frequencies_A_deprecated_Y_renamed(self, freq, freq_depr): result = date_range("1/1/2000", periods=2, freq=freq_depr) tm.assert_index_equal(result, expected) + def test_to_offset_with_lowercase_deprecated_freq(self) -> None: + # https://github.com/pandas-dev/pandas/issues/56847 + msg = "'m' is deprecated and will be removed in a future version, please use " + "'ME' instead." + with tm.assert_produces_warning(FutureWarning, match=msg): + result = date_range("2010-01-01", periods=2, freq="m") + expected = DatetimeIndex(["2010-01-31", "2010-02-28"], freq="ME") + tm.assert_index_equal(result, expected) + def test_date_range_bday(self): sdate = datetime(1999, 12, 25) idx = date_range(start=sdate, freq="1B", periods=20) From 77a3bbbf65b91964bb0f59ffdf2e3377c2da7e20 Mon Sep 17 00:00:00 2001 From: MarcoGorelli <33491632+MarcoGorelli@users.noreply.github.com> Date: Fri, 12 Jan 2024 19:41:08 +0000 Subject: [PATCH 2/3] fixup test --- pandas/tests/tslibs/test_to_offset.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pandas/tests/tslibs/test_to_offset.py b/pandas/tests/tslibs/test_to_offset.py index 204775347e47a..c5a2f08933392 100644 --- a/pandas/tests/tslibs/test_to_offset.py +++ b/pandas/tests/tslibs/test_to_offset.py @@ -44,6 +44,7 @@ def test_to_offset_negative(freqstr, expected): assert result.n == expected +@pytest.mark.filterwarnings("ignore:.*'m' is deprecated.*:FutureWarning") @pytest.mark.parametrize( "freqstr", [ From 42c3bb6875bb519e75b9c20d0506ae948d426ace Mon Sep 17 00:00:00 2001 From: MarcoGorelli <33491632+MarcoGorelli@users.noreply.github.com> Date: Fri, 12 Jan 2024 20:12:08 +0000 Subject: [PATCH 3/3] lint --- pandas/tests/indexes/datetimes/test_date_range.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pandas/tests/indexes/datetimes/test_date_range.py b/pandas/tests/indexes/datetimes/test_date_range.py index 69f2ba8a4deab..e26f35f4e8258 100644 --- a/pandas/tests/indexes/datetimes/test_date_range.py +++ b/pandas/tests/indexes/datetimes/test_date_range.py @@ -820,8 +820,10 @@ def test_frequencies_A_deprecated_Y_renamed(self, freq, freq_depr): def test_to_offset_with_lowercase_deprecated_freq(self) -> None: # https://github.com/pandas-dev/pandas/issues/56847 - msg = "'m' is deprecated and will be removed in a future version, please use " - "'ME' instead." + msg = ( + "'m' is deprecated and will be removed in a future version, please use " + "'ME' instead." + ) with tm.assert_produces_warning(FutureWarning, match=msg): result = date_range("2010-01-01", periods=2, freq="m") expected = DatetimeIndex(["2010-01-31", "2010-02-28"], freq="ME")