From efa35768b386797a0df4a69b358961df86989736 Mon Sep 17 00:00:00 2001 From: Natalia Mokeeva Date: Sat, 8 Nov 2025 22:47:08 +0100 Subject: [PATCH] enh: clarify error message the new usage of the removed year frequencies in error message --- pandas/_libs/tslibs/offsets.pyx | 26 +++++++++++++++++++ .../indexes/datetimes/test_date_range.py | 16 ++++++++++++ 2 files changed, 42 insertions(+) diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index 66427a0e38847..6f9a1ba34bde9 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -5202,6 +5202,32 @@ deprec_to_valid_alias = { "L": "ms", "U": "us", "N": "ns", + "AS": "YS", + "AS-JAN": "YS-JAN", + "AS-FEB": "YS-FEB", + "AS-MAR": "YS-MAR", + "AS-APR": "YS-APR", + "AS-MAY": "YS-MAY", + "AS-JUN": "YS-JUN", + "AS-JUL": "YS-JUL", + "AS-AUG": "YS-AUG", + "AS-SEP": "YS-SEP", + "AS-OCT": "YS-OCT", + "AS-NOV": "YS-NOV", + "AS-DEC": "YS-DEC", + "A": "Y", + "A-JAN": "Y-JAN", + "A-FEB": "Y-FEB", + "A-MAR": "Y-MAR", + "A-APR": "Y-APR", + "A-MAY": "Y-MAY", + "A-JUN": "Y-JUN", + "A-JUL": "Y-JUL", + "A-AUG": "Y-AUG", + "A-SEP": "Y-SEP", + "A-OCT": "Y-OCT", + "A-NOV": "Y-NOV", + "A-DEC": "Y-DEC", } diff --git a/pandas/tests/indexes/datetimes/test_date_range.py b/pandas/tests/indexes/datetimes/test_date_range.py index b179f1b272fac..bb701adaf4c4f 100644 --- a/pandas/tests/indexes/datetimes/test_date_range.py +++ b/pandas/tests/indexes/datetimes/test_date_range.py @@ -814,6 +814,22 @@ def test_date_range_depr_lowercase_frequency(self, freq, freq_depr): result = date_range("1/1/2000", periods=4, freq=freq_depr) tm.assert_index_equal(result, expected) + @pytest.mark.parametrize( + "freq_removed,freq", + [ + ("100A", "Y"), + ("2A-DEC", "Y-DEC"), + ("100AS", "YS"), + ("2AS-MAY", "YS-MAY"), + ], + ) + def test_error_message_for_removed_year_yearbegin_frequencies( + self, freq, freq_removed + ): + msg = f"Did you mean {freq}" + with pytest.raises(ValueError, match=msg): + date_range("1/1/2000", periods=2, freq=freq_removed) + class TestDateRangeTZ: """Tests for date_range with timezones"""