File tree Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -5276,6 +5276,18 @@ def _get_offset(name: str) -> BaseOffset:
52765276 return _offset_map[name]
52775277
52785278
5279+ deprec_to_valid_alias = {
5280+ " H" : " h" ,
5281+ " BH" : " bh" ,
5282+ " CBH" : " cbh" ,
5283+ " T" : " min" ,
5284+ " S" : " s" ,
5285+ " L" : " ms" ,
5286+ " U" : " us" ,
5287+ " N" : " ns" ,
5288+ }
5289+
5290+
52795291cpdef to_offset(freq , bint is_period = False ):
52805292 """
52815293 Return DateOffset object from string or datetime.timedelta object.
@@ -5389,6 +5401,8 @@ cpdef to_offset(freq, bint is_period=False):
53895401 # If n==0, then stride_sign is already incorporated
53905402 # into the offset
53915403 offset *= stride_sign
5404+ elif name in deprec_to_valid_alias:
5405+ raise ValueError (f" Did you mean '{deprec_to_valid_alias[name]}'?" )
53925406 else :
53935407 stride = int (stride)
53945408 offset = _get_offset(name)
Original file line number Diff line number Diff line change @@ -1157,6 +1157,11 @@ def test_offset_multiplication(
11571157 tm .assert_series_equal (resultarray , expectedarray )
11581158
11591159
1160+ def test_offset_deprecated_error ():
1161+ with pytest .raises (ValueError , match = r"Did you mean 'h'?" ):
1162+ date_range ("2012-01-01" , periods = 3 , freq = "H" )
1163+
1164+
11601165def test_dateoffset_operations_on_dataframes (performance_warning ):
11611166 # GH 47953
11621167 df = DataFrame ({"T" : [Timestamp ("2019-04-30" )], "D" : [DateOffset (months = 1 )]})
You can’t perform that action at this time.
0 commit comments