Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
17 changes: 17 additions & 0 deletions pandas/_libs/tslibs/offsets.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -5276,6 +5276,18 @@ def _get_offset(name: str) -> BaseOffset:
return _offset_map[name]


deprec_to_valid_alias = {
"H": "h",
"BH": "bh",
"CBH": "cbh",
"T": "min",
"S": "s",
"L": "ms",
"U": "us",
"N": "ns",
}


cpdef to_offset(freq, bint is_period=False):
"""
Return DateOffset object from string or datetime.timedelta object.
Expand Down Expand Up @@ -5359,6 +5371,11 @@ 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 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
5 changes: 5 additions & 0 deletions pandas/tests/tseries/offsets/test_offsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -1157,6 +1157,11 @@ def test_offset_multiplication(
tm.assert_series_equal(resultarray, expectedarray)


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


def test_dateoffset_operations_on_dataframes(performance_warning):
# GH 47953
df = DataFrame({"T": [Timestamp("2019-04-30")], "D": [DateOffset(months=1)]})
Expand Down
Loading