Skip to content

REGR: freq "m" (as alias of deprecated "M") raises an error #56849

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pandas/_libs/tslibs/offsets.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
11 changes: 11 additions & 0 deletions pandas/tests/indexes/datetimes/test_date_range.py
Original file line number Diff line number Diff line change
Expand Up @@ -818,6 +818,17 @@ 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)
Expand Down
1 change: 1 addition & 0 deletions pandas/tests/tslibs/test_to_offset.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
[
Expand Down