From 137faf559d2434458ffe4079b514000a291dd09c Mon Sep 17 00:00:00 2001 From: Natalia Mokeeva <91160475+natmokval@users.noreply.github.com> Date: Mon, 11 Mar 2024 15:56:02 +0100 Subject: [PATCH] CLN: remove deprecated strings 'BA', 'BAS', 'AS' denoting frequencies for timeseries (#57793) * remove BA, BAS-from timeseries freq, fix tests * remove AS from timeseries freq, add test * add notes to v3.0.0 * correct def to_offset --- doc/source/whatsnew/v3.0.0.rst | 3 ++ pandas/_libs/tslibs/dtypes.pyx | 52 ------------------- pandas/tests/frame/methods/test_asfreq.py | 18 ++++--- .../tests/indexes/datetimes/test_datetime.py | 41 +++------------ 4 files changed, 22 insertions(+), 92 deletions(-) diff --git a/doc/source/whatsnew/v3.0.0.rst b/doc/source/whatsnew/v3.0.0.rst index bdd961b11f3e6..8214893c62a9f 100644 --- a/doc/source/whatsnew/v3.0.0.rst +++ b/doc/source/whatsnew/v3.0.0.rst @@ -203,7 +203,10 @@ Removal of prior version deprecations/changes - Enforced deprecation of :meth:`.DataFrameGroupBy.get_group` and :meth:`.SeriesGroupBy.get_group` allowing the ``name`` argument to be a non-tuple when grouping by a list of length 1 (:issue:`54155`) - Enforced deprecation of ``axis=None`` acting the same as ``axis=0`` in the DataFrame reductions ``sum``, ``prod``, ``std``, ``var``, and ``sem``, passing ``axis=None`` will now reduce over both axes; this is particularly the case when doing e.g. ``numpy.sum(df)`` (:issue:`21597`) - Enforced deprecation of passing a dictionary to :meth:`SeriesGroupBy.agg` (:issue:`52268`) +- Enforced deprecation of string ``AS`` denoting frequency in :class:`YearBegin` and strings ``AS-DEC``, ``AS-JAN``, etc. denoting annual frequencies with various fiscal year starts (:issue:`57793`) - Enforced deprecation of string ``A`` denoting frequency in :class:`YearEnd` and strings ``A-DEC``, ``A-JAN``, etc. denoting annual frequencies with various fiscal year ends (:issue:`57699`) +- Enforced deprecation of string ``BAS`` denoting frequency in :class:`BYearBegin` and strings ``BAS-DEC``, ``BAS-JAN``, etc. denoting annual frequencies with various fiscal year starts (:issue:`57793`) +- Enforced deprecation of string ``BA`` denoting frequency in :class:`BYearEnd` and strings ``BA-DEC``, ``BA-JAN``, etc. denoting annual frequencies with various fiscal year ends (:issue:`57793`) - Enforced deprecation of the behavior of :func:`concat` when ``len(keys) != len(objs)`` would truncate to the shorter of the two. Now this raises a ``ValueError`` (:issue:`43485`) - Enforced silent-downcasting deprecation for :ref:`all relevant methods ` (:issue:`54710`) - In :meth:`DataFrame.stack`, the default value of ``future_stack`` is now ``True``; specifying ``False`` will raise a ``FutureWarning`` (:issue:`55448`) diff --git a/pandas/_libs/tslibs/dtypes.pyx b/pandas/_libs/tslibs/dtypes.pyx index 6a81681369fb7..906842d322e91 100644 --- a/pandas/_libs/tslibs/dtypes.pyx +++ b/pandas/_libs/tslibs/dtypes.pyx @@ -286,19 +286,6 @@ cdef dict c_OFFSET_DEPR_FREQSTR = { "BY-SEP": "BYE-SEP", "BY-OCT": "BYE-OCT", "BY-NOV": "BYE-NOV", - "BA": "BYE", - "BA-DEC": "BYE-DEC", - "BA-JAN": "BYE-JAN", - "BA-FEB": "BYE-FEB", - "BA-MAR": "BYE-MAR", - "BA-APR": "BYE-APR", - "BA-MAY": "BYE-MAY", - "BA-JUN": "BYE-JUN", - "BA-JUL": "BYE-JUL", - "BA-AUG": "BYE-AUG", - "BA-SEP": "BYE-SEP", - "BA-OCT": "BYE-OCT", - "BA-NOV": "BYE-NOV", "BM": "BME", "CBM": "CBME", "SM": "SME", @@ -323,45 +310,6 @@ cdef dict c_REVERSE_OFFSET_DEPR_FREQSTR = { # Map deprecated resolution abbreviations to correct resolution abbreviations cdef dict c_DEPR_ABBREVS = { - "BA": "BY", - "BA-DEC": "BY-DEC", - "BA-JAN": "BY-JAN", - "BA-FEB": "BY-FEB", - "BA-MAR": "BY-MAR", - "BA-APR": "BY-APR", - "BA-MAY": "BY-MAY", - "BA-JUN": "BY-JUN", - "BA-JUL": "BY-JUL", - "BA-AUG": "BY-AUG", - "BA-SEP": "BY-SEP", - "BA-OCT": "BY-OCT", - "BA-NOV": "BY-NOV", - "AS": "YS", - "AS-DEC": "YS-DEC", - "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", - "BAS": "BYS", - "BAS-DEC": "BYS-DEC", - "BAS-JAN": "BYS-JAN", - "BAS-FEB": "BYS-FEB", - "BAS-MAR": "BYS-MAR", - "BAS-APR": "BYS-APR", - "BAS-MAY": "BYS-MAY", - "BAS-JUN": "BYS-JUN", - "BAS-JUL": "BYS-JUL", - "BAS-AUG": "BYS-AUG", - "BAS-SEP": "BYS-SEP", - "BAS-OCT": "BYS-OCT", - "BAS-NOV": "BYS-NOV", "H": "h", "BH": "bh", "CBH": "cbh", diff --git a/pandas/tests/frame/methods/test_asfreq.py b/pandas/tests/frame/methods/test_asfreq.py index ffb14a1008b9e..fb288e19c6e82 100644 --- a/pandas/tests/frame/methods/test_asfreq.py +++ b/pandas/tests/frame/methods/test_asfreq.py @@ -242,10 +242,9 @@ def test_asfreq_2ME(self, freq, freq_half): ("2BQE-SEP", "2BQ-SEP"), ("1YE", "1Y"), ("2YE-MAR", "2Y-MAR"), - ("2BYE-MAR", "2BA-MAR"), ], ) - def test_asfreq_frequency_M_Q_Y_A_deprecated(self, freq, freq_depr): + def test_asfreq_frequency_M_Q_Y_deprecated(self, freq, freq_depr): # GH#9586, #55978 depr_msg = f"'{freq_depr[1:]}' is deprecated and will be removed " f"in a future version, please use '{freq[1:]}' instead." @@ -282,11 +281,18 @@ def test_asfreq_unsupported_freq(self, freq, error_msg): with pytest.raises(ValueError, match=error_msg): df.asfreq(freq=freq) - def test_asfreq_frequency_A_raises(self): - msg = "Invalid frequency: 2A" + @pytest.mark.parametrize( + "freq, freq_depr", + [ + ("2YE", "2A"), + ("2BYE-MAR", "2BA-MAR"), + ], + ) + def test_asfreq_frequency_A_BA_raises(self, freq, freq_depr): + msg = f"Invalid frequency: {freq_depr}" - index = date_range("1/1/2000", periods=4, freq="2ME") + index = date_range("1/1/2000", periods=4, freq=freq) df = DataFrame({"s": Series([0.0, 1.0, 2.0, 3.0], index=index)}) with pytest.raises(ValueError, match=msg): - df.asfreq(freq="2A") + df.asfreq(freq=freq_depr) diff --git a/pandas/tests/indexes/datetimes/test_datetime.py b/pandas/tests/indexes/datetimes/test_datetime.py index f7fc64d4b0163..84a616f05cd63 100644 --- a/pandas/tests/indexes/datetimes/test_datetime.py +++ b/pandas/tests/indexes/datetimes/test_datetime.py @@ -1,6 +1,5 @@ import datetime as dt from datetime import date -import re import numpy as np import pytest @@ -158,42 +157,9 @@ def test_CBH_deprecated(self): tm.assert_index_equal(result, expected) - @pytest.mark.parametrize( - "freq_depr, expected_values, expected_freq", - [ - ( - "AS-AUG", - ["2021-08-01", "2022-08-01", "2023-08-01"], - "YS-AUG", - ), - ( - "1BAS-MAY", - ["2021-05-03", "2022-05-02", "2023-05-01"], - "1BYS-MAY", - ), - ], - ) - def test_AS_BAS_deprecated(self, freq_depr, expected_values, expected_freq): - # GH#55479 - freq_msg = re.split("[0-9]*", freq_depr, maxsplit=1)[1] - msg = f"'{freq_msg}' is deprecated and will be removed in a future version." - - with tm.assert_produces_warning(FutureWarning, match=msg): - expected = date_range( - dt.datetime(2020, 12, 1), dt.datetime(2023, 12, 1), freq=freq_depr - ) - result = DatetimeIndex( - expected_values, - dtype="datetime64[ns]", - freq=expected_freq, - ) - - tm.assert_index_equal(result, expected) - @pytest.mark.parametrize( "freq, expected_values, freq_depr", [ - ("2BYE-MAR", ["2016-03-31"], "2BA-MAR"), ("2BYE-JUN", ["2016-06-30"], "2BY-JUN"), ("2BME", ["2016-02-29", "2016-04-29", "2016-06-30"], "2BM"), ("2BQE", ["2016-03-31"], "2BQ"), @@ -214,3 +180,10 @@ def test_BM_BQ_BY_deprecated(self, freq, expected_values, freq_depr): ) tm.assert_index_equal(result, expected) + + @pytest.mark.parametrize("freq", ["2BA-MAR", "1BAS-MAY", "2AS-AUG"]) + def test_BA_BAS_raises(self, freq): + msg = f"Invalid frequency: {freq}" + + with pytest.raises(ValueError, match=msg): + date_range(start="2016-02-21", end="2016-08-21", freq=freq)