Skip to content

Commit 7287487

Browse files
authored
DEPR: remove deprecated freqs/abbrevs 'A', 'A-DEC', 'A-JAN', etc. (#57699)
1 parent a76f24e commit 7287487

File tree

11 files changed

+48
-70
lines changed

11 files changed

+48
-70
lines changed

doc/source/user_guide/timeseries.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -1327,8 +1327,8 @@ frequencies. We will refer to these aliases as *period aliases*.
13271327

13281328
.. deprecated:: 2.2.0
13291329

1330-
Aliases ``A``, ``H``, ``T``, ``S``, ``L``, ``U``, and ``N`` are deprecated in favour of the aliases
1331-
``Y``, ``h``, ``min``, ``s``, ``ms``, ``us``, and ``ns``.
1330+
Aliases ``H``, ``T``, ``S``, ``L``, ``U``, and ``N`` are deprecated in favour of the aliases
1331+
``h``, ``min``, ``s``, ``ms``, ``us``, and ``ns``.
13321332

13331333

13341334
Combining aliases

doc/source/whatsnew/v3.0.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ Removal of prior version deprecations/changes
203203
- 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`)
204204
- 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`)
205205
- Enforced deprecation of passing a dictionary to :meth:`SeriesGroupBy.agg` (:issue:`52268`)
206+
- 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`)
206207
- Enforced silent-downcasting deprecation for :ref:`all relevant methods <whatsnew_220.silent_downcasting>` (:issue:`54710`)
207208
- In :meth:`DataFrame.stack`, the default value of ``future_stack`` is now ``True``; specifying ``False`` will raise a ``FutureWarning`` (:issue:`55448`)
208209
- Iterating over a :class:`.DataFrameGroupBy` or :class:`.SeriesGroupBy` will return tuples of length 1 for the groups when grouping by ``level`` a list of length 1 (:issue:`50064`)

pandas/_libs/tslibs/dtypes.pyx

-27
Original file line numberDiff line numberDiff line change
@@ -273,19 +273,6 @@ cdef dict c_OFFSET_DEPR_FREQSTR = {
273273
"Y-SEP": "YE-SEP",
274274
"Y-OCT": "YE-OCT",
275275
"Y-NOV": "YE-NOV",
276-
"A": "YE",
277-
"A-DEC": "YE-DEC",
278-
"A-JAN": "YE-JAN",
279-
"A-FEB": "YE-FEB",
280-
"A-MAR": "YE-MAR",
281-
"A-APR": "YE-APR",
282-
"A-MAY": "YE-MAY",
283-
"A-JUN": "YE-JUN",
284-
"A-JUL": "YE-JUL",
285-
"A-AUG": "YE-AUG",
286-
"A-SEP": "YE-SEP",
287-
"A-OCT": "YE-OCT",
288-
"A-NOV": "YE-NOV",
289276
"BY": "BYE",
290277
"BY-DEC": "BYE-DEC",
291278
"BY-JAN": "BYE-JAN",
@@ -336,20 +323,6 @@ cdef dict c_REVERSE_OFFSET_DEPR_FREQSTR = {
336323

337324
# Map deprecated resolution abbreviations to correct resolution abbreviations
338325
cdef dict c_DEPR_ABBREVS = {
339-
"A": "Y",
340-
"a": "Y",
341-
"A-DEC": "Y-DEC",
342-
"A-JAN": "Y-JAN",
343-
"A-FEB": "Y-FEB",
344-
"A-MAR": "Y-MAR",
345-
"A-APR": "Y-APR",
346-
"A-MAY": "Y-MAY",
347-
"A-JUN": "Y-JUN",
348-
"A-JUL": "Y-JUL",
349-
"A-AUG": "Y-AUG",
350-
"A-SEP": "Y-SEP",
351-
"A-OCT": "Y-OCT",
352-
"A-NOV": "Y-NOV",
353326
"BA": "BY",
354327
"BA-DEC": "BY-DEC",
355328
"BA-JAN": "BY-JAN",

pandas/_libs/tslibs/offsets.pyx

-8
Original file line numberDiff line numberDiff line change
@@ -4885,14 +4885,6 @@ cpdef to_offset(freq, bint is_period=False):
48854885
f"instead of \'{name}\'"
48864886
)
48874887
elif is_period and name.upper() in c_OFFSET_DEPR_FREQSTR:
4888-
if name.upper().startswith("A"):
4889-
warnings.warn(
4890-
f"\'{name}\' is deprecated and will be removed in a future "
4891-
f"version, please use "
4892-
f"\'{c_DEPR_ABBREVS.get(name.upper())}\' instead.",
4893-
FutureWarning,
4894-
stacklevel=find_stack_level(),
4895-
)
48964888
if name.upper() != name:
48974889
warnings.warn(
48984890
f"\'{name}\' is deprecated and will be removed in "

pandas/tests/arrays/test_datetimes.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -773,11 +773,8 @@ def test_iter_zoneinfo_fold(self, tz):
773773
("2QE-SEP", "2Q-SEP"),
774774
("1YE", "1Y"),
775775
("2YE-MAR", "2Y-MAR"),
776-
("1YE", "1A"),
777-
("2YE-MAR", "2A-MAR"),
778776
("2ME", "2m"),
779777
("2QE-SEP", "2q-sep"),
780-
("2YE-MAR", "2a-mar"),
781778
("2YE", "2y"),
782779
],
783780
)
@@ -827,6 +824,13 @@ def test_date_range_lowercase_frequency_deprecated(self, freq_depr):
827824
result = pd.date_range("1/1/2000", periods=4, freq=freq_depr)
828825
tm.assert_index_equal(result, expected)
829826

827+
@pytest.mark.parametrize("freq", ["1A", "2A-MAR", "2a-mar"])
828+
def test_date_range_frequency_A_raises(self, freq):
829+
msg = f"Invalid frequency: {freq}"
830+
831+
with pytest.raises(ValueError, match=msg):
832+
pd.date_range("1/1/2000", periods=4, freq=freq)
833+
830834

831835
def test_factorize_sort_without_freq():
832836
dta = DatetimeArray._from_sequence([0, 2, 1], dtype="M8[ns]")

pandas/tests/frame/methods/test_asfreq.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,6 @@ def test_asfreq_2ME(self, freq, freq_half):
242242
("2BQE-SEP", "2BQ-SEP"),
243243
("1YE", "1Y"),
244244
("2YE-MAR", "2Y-MAR"),
245-
("1YE", "1A"),
246-
("2YE-MAR", "2A-MAR"),
247245
("2BYE-MAR", "2BA-MAR"),
248246
],
249247
)
@@ -283,3 +281,12 @@ def test_asfreq_unsupported_freq(self, freq, error_msg):
283281

284282
with pytest.raises(ValueError, match=error_msg):
285283
df.asfreq(freq=freq)
284+
285+
def test_asfreq_frequency_A_raises(self):
286+
msg = "Invalid frequency: 2A"
287+
288+
index = date_range("1/1/2000", periods=4, freq="2ME")
289+
df = DataFrame({"s": Series([0.0, 1.0, 2.0, 3.0], index=index)})
290+
291+
with pytest.raises(ValueError, match=msg):
292+
df.asfreq(freq="2A")

pandas/tests/indexes/datetimes/methods/test_to_period.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,9 @@ def test_dti_to_period_2monthish(self, freq_offset, freq_period):
9797
("2QE-SEP", "2Q-SEP"),
9898
("1YE", "1Y"),
9999
("2YE-MAR", "2Y-MAR"),
100-
("1YE", "1A"),
101-
("2YE-MAR", "2A-MAR"),
102100
],
103101
)
104-
def test_to_period_frequency_M_Q_Y_A_deprecated(self, freq, freq_depr):
102+
def test_to_period_frequency_M_Q_Y_deprecated(self, freq, freq_depr):
105103
# GH#9586
106104
msg = f"'{freq_depr[1:]}' is deprecated and will be removed "
107105
f"in a future version, please use '{freq[1:]}' instead."

pandas/tests/indexes/datetimes/test_date_range.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -800,13 +800,11 @@ def test_frequencies_H_T_S_L_U_N_deprecated(self, freq, freq_depr):
800800
@pytest.mark.parametrize(
801801
"freq,freq_depr",
802802
[
803-
("200YE", "200A"),
804803
("YE", "Y"),
805-
("2YE-MAY", "2A-MAY"),
806804
("YE-MAY", "Y-MAY"),
807805
],
808806
)
809-
def test_frequencies_A_deprecated_Y_renamed(self, freq, freq_depr):
807+
def test_frequencies_Y_renamed(self, freq, freq_depr):
810808
# GH#9586, GH#54275
811809
freq_msg = re.split("[0-9]*", freq, maxsplit=1)[1]
812810
freq_depr_msg = re.split("[0-9]*", freq_depr, maxsplit=1)[1]
@@ -836,6 +834,14 @@ def test_date_range_bday(self):
836834
assert idx[0] == sdate + 0 * offsets.BDay()
837835
assert idx.freq == "B"
838836

837+
@pytest.mark.parametrize("freq", ["200A", "2A-MAY"])
838+
def test_frequency_A_raises(self, freq):
839+
freq_msg = re.split("[0-9]*", freq, maxsplit=1)[1]
840+
msg = f"Invalid frequency: {freq_msg}"
841+
842+
with pytest.raises(ValueError, match=msg):
843+
date_range("1/1/2000", periods=2, freq=freq)
844+
839845

840846
class TestDateRangeTZ:
841847
"""Tests for date_range with timezones"""

pandas/tests/indexes/period/test_period_range.py

+7-17
Original file line numberDiff line numberDiff line change
@@ -205,23 +205,6 @@ def test_constructor_U(self):
205205
with pytest.raises(ValueError, match="Invalid frequency: X"):
206206
period_range("2007-1-1", periods=500, freq="X")
207207

208-
@pytest.mark.parametrize(
209-
"freq,freq_depr",
210-
[
211-
("2Y", "2A"),
212-
("2Y", "2a"),
213-
("2Y-AUG", "2A-AUG"),
214-
("2Y-AUG", "2A-aug"),
215-
],
216-
)
217-
def test_a_deprecated_from_time_series(self, freq, freq_depr):
218-
# GH#52536
219-
msg = f"'{freq_depr[1:]}' is deprecated and will be removed in a "
220-
f"future version. Please use '{freq[1:]}' instead."
221-
222-
with tm.assert_produces_warning(FutureWarning, match=msg):
223-
period_range(freq=freq_depr, start="1/1/2001", end="12/1/2009")
224-
225208
@pytest.mark.parametrize("freq_depr", ["2H", "2MIN", "2S", "2US", "2NS"])
226209
def test_uppercase_freq_deprecated_from_time_series(self, freq_depr):
227210
# GH#52536, GH#54939
@@ -239,3 +222,10 @@ def test_lowercase_freq_deprecated_from_time_series(self, freq_depr):
239222

240223
with tm.assert_produces_warning(FutureWarning, match=msg):
241224
period_range(freq=freq_depr, start="1/1/2001", end="12/1/2009")
225+
226+
@pytest.mark.parametrize("freq", ["2A", "2a", "2A-AUG", "2A-aug"])
227+
def test_A_raises_from_time_series(self, freq):
228+
msg = f"Invalid frequency: {freq}"
229+
230+
with pytest.raises(ValueError, match=msg):
231+
period_range(freq=freq, start="1/1/2001", end="12/1/2009")

pandas/tests/resample/test_datetime_index.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -2047,11 +2047,9 @@ def test_resample_empty_series_with_tz():
20472047
("2QE-SEP", "2Q-SEP"),
20482048
("1YE", "1Y"),
20492049
("2YE-MAR", "2Y-MAR"),
2050-
("1YE", "1A"),
2051-
("2YE-MAR", "2A-MAR"),
20522050
],
20532051
)
2054-
def test_resample_M_Q_Y_A_deprecated(freq, freq_depr):
2052+
def test_resample_M_Q_Y_deprecated(freq, freq_depr):
20552053
# GH#9586
20562054
depr_msg = f"'{freq_depr[1:]}' is deprecated and will be removed "
20572055
f"in a future version, please use '{freq[1:]}' instead."
@@ -2174,3 +2172,12 @@ def test_arrow_timestamp_resample(tz):
21742172
expected = Series(np.arange(5, dtype=np.float64), index=idx)
21752173
result = expected.resample("1D").mean()
21762174
tm.assert_series_equal(result, expected)
2175+
2176+
2177+
@pytest.mark.parametrize("freq", ["1A", "2A-MAR"])
2178+
def test_resample_A_raises(freq):
2179+
msg = f"Invalid frequency: {freq[1:]}"
2180+
2181+
s = Series(range(10), index=date_range("20130101", freq="d", periods=10))
2182+
with pytest.raises(ValueError, match=msg):
2183+
s.resample(freq).mean()

pandas/tests/tslibs/test_resolution.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ def test_get_attrname_from_abbrev(freqstr, expected):
4848
assert reso.attrname == expected
4949

5050

51-
@pytest.mark.parametrize("freq", ["A", "H", "T", "S", "L", "U", "N"])
52-
def test_units_A_H_T_S_L_U_N_deprecated_from_attrname_to_abbrevs(freq):
51+
@pytest.mark.parametrize("freq", ["H", "T", "S", "L", "U", "N"])
52+
def test_units_H_T_S_L_U_N_deprecated_from_attrname_to_abbrevs(freq):
5353
# GH#52536
5454
msg = f"'{freq}' is deprecated and will be removed in a future version."
5555

0 commit comments

Comments
 (0)