Skip to content

Commit 46a85f2

Browse files
MarcoGorellimeeseeksmachine
authored andcommitted
Backport PR pandas-dev#56849: REGR: freq "m" (as alias of deprecated "M") raises an error
1 parent 1c34627 commit 46a85f2

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

pandas/_libs/tslibs/offsets.pyx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4845,15 +4845,15 @@ cpdef to_offset(freq, bint is_period=False):
48454845

48464846
tups = zip(split[0::4], split[1::4], split[2::4])
48474847
for n, (sep, stride, name) in enumerate(tups):
4848-
if is_period is False and name in c_OFFSET_DEPR_FREQSTR:
4848+
if is_period is False and name.upper() in c_OFFSET_DEPR_FREQSTR:
48494849
warnings.warn(
48504850
f"\'{name}\' is deprecated and will be removed "
48514851
f"in a future version, please use "
4852-
f"\'{c_OFFSET_DEPR_FREQSTR.get(name)}\' instead.",
4852+
f"\'{c_OFFSET_DEPR_FREQSTR.get(name.upper())}\' instead.",
48534853
FutureWarning,
48544854
stacklevel=find_stack_level(),
48554855
)
4856-
name = c_OFFSET_DEPR_FREQSTR[name]
4856+
name = c_OFFSET_DEPR_FREQSTR[name.upper()]
48574857
if is_period is True and name in c_REVERSE_OFFSET_DEPR_FREQSTR:
48584858
if name.startswith("Y"):
48594859
raise ValueError(

pandas/tests/indexes/datetimes/test_date_range.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -822,6 +822,17 @@ def test_frequencies_A_deprecated_Y_renamed(self, freq, freq_depr):
822822
result = date_range("1/1/2000", periods=2, freq=freq_depr)
823823
tm.assert_index_equal(result, expected)
824824

825+
def test_to_offset_with_lowercase_deprecated_freq(self) -> None:
826+
# https://github.com/pandas-dev/pandas/issues/56847
827+
msg = (
828+
"'m' is deprecated and will be removed in a future version, please use "
829+
"'ME' instead."
830+
)
831+
with tm.assert_produces_warning(FutureWarning, match=msg):
832+
result = date_range("2010-01-01", periods=2, freq="m")
833+
expected = DatetimeIndex(["2010-01-31", "2010-02-28"], freq="ME")
834+
tm.assert_index_equal(result, expected)
835+
825836
def test_date_range_bday(self):
826837
sdate = datetime(1999, 12, 25)
827838
idx = date_range(start=sdate, freq="1B", periods=20)

pandas/tests/tslibs/test_to_offset.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ def test_to_offset_negative(freqstr, expected):
4545
assert result.n == expected
4646

4747

48+
@pytest.mark.filterwarnings("ignore:.*'m' is deprecated.*:FutureWarning")
4849
@pytest.mark.parametrize(
4950
"freqstr",
5051
[

0 commit comments

Comments
 (0)