File tree Expand file tree Collapse file tree 2 files changed +30
-1
lines changed
tests/tseries/frequencies Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Original file line number Diff line number Diff line change 22
33from pandas ._libs .tslibs import offsets
44
5+ import pandas as pd
6+
57from pandas .tseries .frequencies import (
68 is_subperiod ,
79 is_superperiod ,
2729def test_super_sub_symmetry (p1 , p2 , expected ):
2830 assert is_superperiod (p1 , p2 ) is expected
2931 assert is_subperiod (p2 , p1 ) is expected
32+
33+
34+ def test_deprecated_freq_alias_error ():
35+ # GH#62259
36+ with pytest .raises (ValueError , match = "Invalid frequency 'H'.*Did you mean 'h'?" ):
37+ pd .date_range ("2012-01-01" , periods = 3 , freq = "H" )
Original file line number Diff line number Diff line change 2727from pandas ._libs .tslibs .offsets import (
2828 DateOffset ,
2929 Day ,
30- to_offset ,
30+ to_offset as _to_offset ,
3131)
3232from pandas ._libs .tslibs .parsing import get_rule_month
3333from pandas .util ._decorators import cache_readonly
5353 TimedeltaIndex ,
5454 )
5555 from pandas .core .arrays .datetimelike import DatetimeLikeArrayMixin
56+
57+ _DEPRECATED_FREQ_ALIASES = {
58+ "H" : "h" ,
59+ "T" : "min" ,
60+ "S" : "s" ,
61+ }
5662# --------------------------------------------------------------------
5763# Offset related functions
5864
@@ -600,6 +606,21 @@ def _is_weekly(rule: str) -> bool:
600606 return rule == "W" or rule .startswith ("W-" )
601607
602608
609+ def to_offset (freq ):
610+ try :
611+ return _to_offset (freq )
612+ except Exception as err :
613+ if isinstance (freq , str ) and freq in _DEPRECATED_FREQ_ALIASES :
614+ suggestion = _DEPRECATED_FREQ_ALIASES [freq ]
615+ raise ValueError (
616+ f"Invalid frequency '{ freq } '. This alias was deprecated and removed. "
617+ f"Did you mean '{ suggestion } '?"
618+ ) from None
619+ raise ValueError (
620+ f"Invalid frequency: { freq } , failed to parse with error message: { err } "
621+ ) from None
622+
623+
603624__all__ = [
604625 "Day" ,
605626 "get_period_alias" ,
You can’t perform that action at this time.
0 commit comments