Skip to content

Commit ae575b7

Browse files
committed
improve error message when specifying a previously-deprecated frequency alias
1 parent 5cc3240 commit ae575b7

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

pandas/_libs/tslibs/offsets.pyx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5275,6 +5275,16 @@ def _get_offset(name: str) -> BaseOffset:
52755275

52765276
return _offset_map[name]
52775277

5278+
deprecated_to_valid_alias = {
5279+
"H": "h",
5280+
"BH": "bh",
5281+
"CBH": "cbh",
5282+
"T": "min",
5283+
"S": "s",
5284+
"L": "ms",
5285+
"U": "us",
5286+
"N": "ns",
5287+
}
52785288

52795289
cpdef to_offset(freq, bint is_period=False):
52805290
"""
@@ -5389,6 +5399,8 @@ cpdef to_offset(freq, bint is_period=False):
53895399
# If n==0, then stride_sign is already incorporated
53905400
# into the offset
53915401
offset *= stride_sign
5402+
elif name in deprecated_to_valid_alias:
5403+
raise ValueError(f"Did you mean '{deprecated_to_valid_alias[name]}'")
53925404
else:
53935405
stride = int(stride)
53945406
offset = _get_offset(name)

pandas/tests/tseries/offsets/test_offsets.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,6 +1156,9 @@ def test_offset_multiplication(
11561156

11571157
tm.assert_series_equal(resultarray, expectedarray)
11581158

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

11601163
def test_dateoffset_operations_on_dataframes(performance_warning):
11611164
# GH 47953

0 commit comments

Comments
 (0)