Skip to content
Prev Previous commit
Next Next commit
update location of checking deprecated freq
  • Loading branch information
jgao8 committed Oct 3, 2025
commit 51c55cd89696ebeaaa449a20434f7e308cfdccac
7 changes: 5 additions & 2 deletions pandas/_libs/tslibs/offsets.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -5371,6 +5371,11 @@ cpdef to_offset(freq, bint is_period=False):

tups = zip(split[0::4], split[1::4], split[2::4], strict=False)
for n, (sep, stride, name) in enumerate(tups):
if name in deprec_to_valid_alias:
raise ValueError(INVALID_FREQ_ERR_MSG.format(
f"{name}. Did you mean {deprec_to_valid_alias[name]}?")
)

name = _warn_about_deprecated_aliases(name, is_period)
_validate_to_offset_alias(name, is_period)
if is_period:
Expand Down Expand Up @@ -5401,8 +5406,6 @@ cpdef to_offset(freq, bint is_period=False):
# If n==0, then stride_sign is already incorporated
# into the offset
offset *= stride_sign
elif name in deprec_to_valid_alias:
raise ValueError(f"Did you mean '{deprec_to_valid_alias[name]}'?")
else:
stride = int(stride)
offset = _get_offset(name)
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/tseries/offsets/test_offsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -1158,7 +1158,7 @@ def test_offset_multiplication(


def test_offset_deprecated_error():
with pytest.raises(ValueError, match=r"Did you mean 'h'?"):
with pytest.raises(ValueError, match=r"Did you mean h?"):
date_range("2012-01-01", periods=3, freq="H")


Expand Down