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:
5276
5276
return _offset_map[name]
5277
5277
5278
5278
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
+
5279
5291
cpdef to_offset(freq , bint is_period = False ):
5280
5292
"""
5281
5293
Return DateOffset object from string or datetime.timedelta object.
@@ -5389,6 +5401,8 @@ cpdef to_offset(freq, bint is_period=False):
5389
5401
# If n==0, then stride_sign is already incorporated
5390
5402
# into the offset
5391
5403
offset *= stride_sign
5404
+ elif name in deprec_to_valid_alias:
5405
+ raise ValueError (f" Did you mean '{deprec_to_valid_alias[name]}'?" )
5392
5406
else :
5393
5407
stride = int (stride)
5394
5408
offset = _get_offset(name)
Original file line number Diff line number Diff line change @@ -1157,6 +1157,11 @@ def test_offset_multiplication(
1157
1157
tm .assert_series_equal (resultarray , expectedarray )
1158
1158
1159
1159
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
+
1160
1165
def test_dateoffset_operations_on_dataframes (performance_warning ):
1161
1166
# GH 47953
1162
1167
df = DataFrame ({"T" : [Timestamp ("2019-04-30" )], "D" : [DateOffset (months = 1 )]})
You can’t perform that action at this time.
0 commit comments