Skip to content

ERR: improve error message when specifying a previously-deprecated frequency alias #62259

@jorisvandenbossche

Description

@jorisvandenbossche

For example, in pd.date_range, we deprecated some frequency aliases. With pandas 2.3:

>>> pd.date_range("2012-01-01", periods=3, freq='H')
FutureWarning: 'H' is deprecated and will be removed in a future version, please use 'h' instead.
DatetimeIndex(['2012-01-01 00:00:00', '2012-01-01 01:00:00',
               '2012-01-01 02:00:00'],
              dtype='datetime64[ns]', freq='h')

and now with main (pandas 3.0) the deprecation is enforeced and we raise an error:

>>> pd.date_range("2012-01-01", periods=3, freq='H')
... 
ValueError: Invalid frequency: H, failed to parse with error message: ValueError("Invalid frequency: H, failed to parse with error message: KeyError('H')")

However, I think that is not the best error message ..
First, it's already a bit confusing that it contains the message twice.
But secondly, I think it would also be nice to still keep a mapping of those aliases around, so that when parsing fails and the input is an old alias, we can provide a more informative error message (something like "invalid frequency 'H'. Did you mean 'h'?")

Metadata

Metadata

Assignees

No one assigned

    Labels

    Error ReportingIncorrect or improved errors from pandasFrequencyDateOffsets

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions