Skip to content

Commit 920945d

Browse files
committed
update location of checking deprecated freq
1 parent 8c2b5fb commit 920945d

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

pandas/_libs/tslibs/offsets.pyx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5371,6 +5371,11 @@ cpdef to_offset(freq, bint is_period=False):
53715371

53725372
tups = zip(split[0::4], split[1::4], split[2::4])
53735373
for n, (sep, stride, name) in enumerate(tups):
5374+
if name in deprec_to_valid_alias:
5375+
raise ValueError(INVALID_FREQ_ERR_MSG.format(
5376+
f"{name}. Did you mean {deprec_to_valid_alias[name]}?")
5377+
)
5378+
53745379
name = _warn_about_deprecated_aliases(name, is_period)
53755380
_validate_to_offset_alias(name, is_period)
53765381
if is_period:
@@ -5401,8 +5406,6 @@ cpdef to_offset(freq, bint is_period=False):
54015406
# If n==0, then stride_sign is already incorporated
54025407
# into the offset
54035408
offset *= stride_sign
5404-
elif name in deprec_to_valid_alias:
5405-
raise ValueError(f"Did you mean '{deprec_to_valid_alias[name]}'?")
54065409
else:
54075410
stride = int(stride)
54085411
offset = _get_offset(name)

pandas/tests/tseries/offsets/test_offsets.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1158,7 +1158,7 @@ def test_offset_multiplication(
11581158

11591159

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

11641164

0 commit comments

Comments
 (0)