Skip to content

Commit 7ec95e4

Browse files
authored
DEPR: 'A' for yearly frequency and YearEnd in favour of 'Y' (#55252)
1 parent 40f219c commit 7ec95e4

File tree

81 files changed

+490
-413
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+490
-413
lines changed

asv_bench/benchmarks/tslibs/period.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def time_now(self, freq):
7272
self.per.now(freq)
7373

7474
def time_asfreq(self, freq):
75-
self.per.asfreq("A")
75+
self.per.asfreq("Y")
7676

7777
def time_str(self, freq):
7878
str(self.per)

doc/source/user_guide/io.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -2332,7 +2332,7 @@ A few notes on the generated table schema:
23322332

23332333
.. ipython:: python
23342334
2335-
s_per = pd.Series(1, index=pd.period_range("2016", freq="A-DEC", periods=4))
2335+
s_per = pd.Series(1, index=pd.period_range("2016", freq="Y-DEC", periods=4))
23362336
build_table_schema(s_per)
23372337
23382338
* Categoricals use the ``any`` type and an ``enum`` constraint listing

doc/source/user_guide/timeseries.rst

+24-24
Original file line numberDiff line numberDiff line change
@@ -895,7 +895,7 @@ into ``freq`` keyword arguments. The available date offsets and associated frequ
895895
:class:`~pandas.tseries.offsets.BQuarterEnd`, ``'BQ``, "business quarter end"
896896
:class:`~pandas.tseries.offsets.BQuarterBegin`, ``'BQS'``, "business quarter begin"
897897
:class:`~pandas.tseries.offsets.FY5253Quarter`, ``'REQ'``, "retail (aka 52-53 week) quarter"
898-
:class:`~pandas.tseries.offsets.YearEnd`, ``'A'``, "calendar year end"
898+
:class:`~pandas.tseries.offsets.YearEnd`, ``'Y'``, "calendar year end"
899899
:class:`~pandas.tseries.offsets.YearBegin`, ``'AS'`` or ``'BYS'``,"calendar year begin"
900900
:class:`~pandas.tseries.offsets.BYearEnd`, ``'BA'``, "business year end"
901901
:class:`~pandas.tseries.offsets.BYearBegin`, ``'BAS'``, "business year begin"
@@ -1258,7 +1258,7 @@ frequencies. We will refer to these aliases as *offset aliases*.
12581258
"BQ", "business quarter end frequency"
12591259
"QS", "quarter start frequency"
12601260
"BQS", "business quarter start frequency"
1261-
"A, Y", "year end frequency"
1261+
"Y", "year end frequency"
12621262
"BA, BY", "business year end frequency"
12631263
"AS, YS", "year start frequency"
12641264
"BAS, BYS", "business year start frequency"
@@ -1321,7 +1321,7 @@ frequencies. We will refer to these aliases as *period aliases*.
13211321
"W", "weekly frequency"
13221322
"M", "monthly frequency"
13231323
"Q", "quarterly frequency"
1324-
"A, Y", "yearly frequency"
1324+
"Y", "yearly frequency"
13251325
"H", "hourly frequency"
13261326
"min", "minutely frequency"
13271327
"s", "secondly frequency"
@@ -1331,8 +1331,8 @@ frequencies. We will refer to these aliases as *period aliases*.
13311331

13321332
.. deprecated:: 2.2.0
13331333

1334-
Aliases ``T``, ``S``, ``L``, ``U``, and ``N`` are deprecated in favour of the aliases
1335-
``min``, ``s``, ``ms``, ``us``, and ``ns``.
1334+
Aliases ``A``, ``T``, ``S``, ``L``, ``U``, and ``N`` are deprecated in favour of the aliases
1335+
``Y``, ``min``, ``s``, ``ms``, ``us``, and ``ns``.
13361336

13371337

13381338
Combining aliases
@@ -1383,18 +1383,18 @@ For some frequencies you can specify an anchoring suffix:
13831383
"(B)Q(S)\-SEP", "quarterly frequency, year ends in September"
13841384
"(B)Q(S)\-OCT", "quarterly frequency, year ends in October"
13851385
"(B)Q(S)\-NOV", "quarterly frequency, year ends in November"
1386-
"(B)A(S)\-DEC", "annual frequency, anchored end of December. Same as 'A'"
1387-
"(B)A(S)\-JAN", "annual frequency, anchored end of January"
1388-
"(B)A(S)\-FEB", "annual frequency, anchored end of February"
1389-
"(B)A(S)\-MAR", "annual frequency, anchored end of March"
1390-
"(B)A(S)\-APR", "annual frequency, anchored end of April"
1391-
"(B)A(S)\-MAY", "annual frequency, anchored end of May"
1392-
"(B)A(S)\-JUN", "annual frequency, anchored end of June"
1393-
"(B)A(S)\-JUL", "annual frequency, anchored end of July"
1394-
"(B)A(S)\-AUG", "annual frequency, anchored end of August"
1395-
"(B)A(S)\-SEP", "annual frequency, anchored end of September"
1396-
"(B)A(S)\-OCT", "annual frequency, anchored end of October"
1397-
"(B)A(S)\-NOV", "annual frequency, anchored end of November"
1386+
"(B)Y(S)\-DEC", "annual frequency, anchored end of December. Same as 'Y'"
1387+
"(B)Y(S)\-JAN", "annual frequency, anchored end of January"
1388+
"(B)Y(S)\-FEB", "annual frequency, anchored end of February"
1389+
"(B)Y(S)\-MAR", "annual frequency, anchored end of March"
1390+
"(B)Y(S)\-APR", "annual frequency, anchored end of April"
1391+
"(B)Y(S)\-MAY", "annual frequency, anchored end of May"
1392+
"(B)Y(S)\-JUN", "annual frequency, anchored end of June"
1393+
"(B)Y(S)\-JUL", "annual frequency, anchored end of July"
1394+
"(B)Y(S)\-AUG", "annual frequency, anchored end of August"
1395+
"(B)Y(S)\-SEP", "annual frequency, anchored end of September"
1396+
"(B)Y(S)\-OCT", "annual frequency, anchored end of October"
1397+
"(B)Y(S)\-NOV", "annual frequency, anchored end of November"
13981398

13991399
These can be used as arguments to ``date_range``, ``bdate_range``, constructors
14001400
for ``DatetimeIndex``, as well as various other timeseries-related functions
@@ -1690,7 +1690,7 @@ the end of the interval.
16901690
.. warning::
16911691

16921692
The default values for ``label`` and ``closed`` is '**left**' for all
1693-
frequency offsets except for 'ME', 'A', 'Q', 'BM', 'BA', 'BQ', and 'W'
1693+
frequency offsets except for 'ME', 'Y', 'Q', 'BM', 'BA', 'BQ', and 'W'
16941694
which all have a default of 'right'.
16951695

16961696
This might unintendedly lead to looking ahead, where the value for a later
@@ -1995,7 +1995,7 @@ Because ``freq`` represents a span of ``Period``, it cannot be negative like "-3
19951995

19961996
.. ipython:: python
19971997
1998-
pd.Period("2012", freq="A-DEC")
1998+
pd.Period("2012", freq="Y-DEC")
19991999
20002000
pd.Period("2012-1-1", freq="D")
20012001
@@ -2008,7 +2008,7 @@ frequency. Arithmetic is not allowed between ``Period`` with different ``freq``
20082008

20092009
.. ipython:: python
20102010
2011-
p = pd.Period("2012", freq="A-DEC")
2011+
p = pd.Period("2012", freq="Y-DEC")
20122012
p + 1
20132013
p - 3
20142014
p = pd.Period("2012-01", freq="2M")
@@ -2050,7 +2050,7 @@ return the number of frequency units between them:
20502050

20512051
.. ipython:: python
20522052
2053-
pd.Period("2012", freq="A-DEC") - pd.Period("2002", freq="A-DEC")
2053+
pd.Period("2012", freq="Y-DEC") - pd.Period("2002", freq="Y-DEC")
20542054
20552055
PeriodIndex and period_range
20562056
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -2184,7 +2184,7 @@ method. Let's start with the fiscal year 2011, ending in December:
21842184

21852185
.. ipython:: python
21862186
2187-
p = pd.Period("2011", freq="A-DEC")
2187+
p = pd.Period("2011", freq="Y-DEC")
21882188
p
21892189
21902190
We can convert it to a monthly frequency. Using the ``how`` parameter, we can
@@ -2211,10 +2211,10 @@ input period:
22112211
22122212
p = pd.Period("2011-12", freq="M")
22132213
2214-
p.asfreq("A-NOV")
2214+
p.asfreq("Y-NOV")
22152215
22162216
Note that since we converted to an annual frequency that ends the year in
2217-
November, the monthly period of December 2011 is actually in the 2012 A-NOV
2217+
November, the monthly period of December 2011 is actually in the 2012 Y-NOV
22182218
period.
22192219

22202220
.. _timeseries.quarterly:

doc/source/whatsnew/v2.2.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ Other Deprecations
251251
- Deprecated downcasting behavior in :meth:`Series.where`, :meth:`DataFrame.where`, :meth:`Series.mask`, :meth:`DataFrame.mask`, :meth:`Series.clip`, :meth:`DataFrame.clip`; in a future version these will not infer object-dtype columns to non-object dtype, or all-round floats to integer dtype. Call ``result.infer_objects(copy=False)`` on the result for object inference, or explicitly cast floats to ints. To opt in to the future version, use ``pd.set_option("future.no_silent_downcasting", True)`` (:issue:`53656`)
252252
- Deprecated including the groups in computations when using :meth:`DataFrameGroupBy.apply` and :meth:`DataFrameGroupBy.resample`; pass ``include_groups=False`` to exclude the groups (:issue:`7155`)
253253
- Deprecated not passing a tuple to :class:`DataFrameGroupBy.get_group` or :class:`SeriesGroupBy.get_group` when grouping by a length-1 list-like (:issue:`25971`)
254+
- Deprecated string ``A`` denoting frequency in :class:`YearEnd` and strings ``A-DEC``, ``A-JAN``, etc. denoting annual frequencies with various fiscal year ends (:issue:`52536`)
254255
- Deprecated strings ``S``, ``U``, and ``N`` denoting units in :func:`to_timedelta` (:issue:`52536`)
255256
- Deprecated strings ``T``, ``S``, ``L``, ``U``, and ``N`` denoting frequencies in :class:`Minute`, :class:`Second`, :class:`Milli`, :class:`Micro`, :class:`Nano` (:issue:`52536`)
256257
- Deprecated strings ``T``, ``S``, ``L``, ``U``, and ``N`` denoting units in :class:`Timedelta` (:issue:`52536`)

pandas/_libs/tslibs/dtypes.pxd

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ cpdef bint is_supported_unit(NPY_DATETIMEUNIT reso)
1313

1414
cpdef freq_to_period_freqstr(freq_n, freq_name)
1515
cdef dict c_OFFSET_TO_PERIOD_FREQSTR
16+
cdef dict c_OFFSET_DEPR_FREQSTR
17+
cdef dict c_REVERSE_OFFSET_DEPR_FREQSTR
1618
cdef dict c_DEPR_ABBREVS
1719
cdef dict attrname_to_abbrevs
1820
cdef dict npy_unit_to_attrname

pandas/_libs/tslibs/dtypes.pyi

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ from pandas._libs.tslibs.timedeltas import UnitChoices
77
_attrname_to_abbrevs: dict[str, str]
88
_period_code_map: dict[str, int]
99
OFFSET_TO_PERIOD_FREQSTR: dict[str, str]
10+
OFFSET_DEPR_FREQSTR: dict[str, str]
1011
DEPR_ABBREVS: dict[str, UnitChoices]
1112

1213
def periods_per_day(reso: int) -> int: ...

pandas/_libs/tslibs/dtypes.pyx

+43-25
Original file line numberDiff line numberDiff line change
@@ -101,19 +101,19 @@ cdef class PeriodDtypeBase:
101101

102102
_period_code_map = {
103103
# Annual freqs with various fiscal year ends.
104-
# eg, 2005 for A-FEB runs Mar 1, 2004 to Feb 28, 2005
105-
"A-DEC": PeriodDtypeCode.A_DEC, # Annual - December year end
106-
"A-JAN": PeriodDtypeCode.A_JAN, # Annual - January year end
107-
"A-FEB": PeriodDtypeCode.A_FEB, # Annual - February year end
108-
"A-MAR": PeriodDtypeCode.A_MAR, # Annual - March year end
109-
"A-APR": PeriodDtypeCode.A_APR, # Annual - April year end
110-
"A-MAY": PeriodDtypeCode.A_MAY, # Annual - May year end
111-
"A-JUN": PeriodDtypeCode.A_JUN, # Annual - June year end
112-
"A-JUL": PeriodDtypeCode.A_JUL, # Annual - July year end
113-
"A-AUG": PeriodDtypeCode.A_AUG, # Annual - August year end
114-
"A-SEP": PeriodDtypeCode.A_SEP, # Annual - September year end
115-
"A-OCT": PeriodDtypeCode.A_OCT, # Annual - October year end
116-
"A-NOV": PeriodDtypeCode.A_NOV, # Annual - November year end
104+
# eg, 2005 for Y-FEB runs Mar 1, 2004 to Feb 28, 2005
105+
"Y-DEC": PeriodDtypeCode.A_DEC, # Annual - December year end
106+
"Y-JAN": PeriodDtypeCode.A_JAN, # Annual - January year end
107+
"Y-FEB": PeriodDtypeCode.A_FEB, # Annual - February year end
108+
"Y-MAR": PeriodDtypeCode.A_MAR, # Annual - March year end
109+
"Y-APR": PeriodDtypeCode.A_APR, # Annual - April year end
110+
"Y-MAY": PeriodDtypeCode.A_MAY, # Annual - May year end
111+
"Y-JUN": PeriodDtypeCode.A_JUN, # Annual - June year end
112+
"Y-JUL": PeriodDtypeCode.A_JUL, # Annual - July year end
113+
"Y-AUG": PeriodDtypeCode.A_AUG, # Annual - August year end
114+
"Y-SEP": PeriodDtypeCode.A_SEP, # Annual - September year end
115+
"Y-OCT": PeriodDtypeCode.A_OCT, # Annual - October year end
116+
"Y-NOV": PeriodDtypeCode.A_NOV, # Annual - November year end
117117

118118
# Quarterly frequencies with various fiscal year ends.
119119
# eg, Q42005 for Q-OCT runs Aug 1, 2005 to Oct 31, 2005
@@ -156,22 +156,22 @@ _reverse_period_code_map = {
156156
# Yearly aliases; careful not to put these in _reverse_period_code_map
157157
_period_code_map.update({"Y" + key[1:]: _period_code_map[key]
158158
for key in _period_code_map
159-
if key.startswith("A-")})
159+
if key.startswith("Y-")})
160160

161161
_period_code_map.update({
162162
"Q": 2000, # Quarterly - December year end (default quarterly)
163-
"A": PeriodDtypeCode.A, # Annual
163+
"Y": PeriodDtypeCode.A, # Annual
164164
"W": 4000, # Weekly
165165
"C": 5000, # Custom Business Day
166166
})
167167

168168
cdef set _month_names = {
169-
x.split("-")[-1] for x in _period_code_map.keys() if x.startswith("A-")
169+
x.split("-")[-1] for x in _period_code_map.keys() if x.startswith("Y-")
170170
}
171171

172172
# Map attribute-name resolutions to resolution abbreviations
173173
_attrname_to_abbrevs = {
174-
"year": "A",
174+
"year": "Y",
175175
"quarter": "Q",
176176
"month": "M",
177177
"day": "D",
@@ -192,9 +192,9 @@ OFFSET_TO_PERIOD_FREQSTR: dict = {
192192
"BQS": "Q",
193193
"QS": "Q",
194194
"BQ": "Q",
195-
"BA": "A",
196-
"AS": "A",
197-
"BAS": "A",
195+
"BA": "Y",
196+
"AS": "Y",
197+
"BAS": "Y",
198198
"MS": "M",
199199
"D": "D",
200200
"B": "B",
@@ -205,15 +205,19 @@ OFFSET_TO_PERIOD_FREQSTR: dict = {
205205
"ns": "ns",
206206
"H": "H",
207207
"Q": "Q",
208-
"A": "A",
208+
"Y": "Y",
209209
"W": "W",
210210
"ME": "M",
211-
"Y": "A",
212-
"BY": "A",
213-
"YS": "A",
214-
"BYS": "A",
211+
"BY": "Y",
212+
"YS": "Y",
213+
"BYS": "Y",
214+
}
215+
OFFSET_DEPR_FREQSTR: dict[str, str]= {
216+
"M": "ME",
215217
}
216218
cdef dict c_OFFSET_TO_PERIOD_FREQSTR = OFFSET_TO_PERIOD_FREQSTR
219+
cdef dict c_OFFSET_DEPR_FREQSTR = OFFSET_DEPR_FREQSTR
220+
cdef dict c_REVERSE_OFFSET_DEPR_FREQSTR = {v: k for k, v in OFFSET_DEPR_FREQSTR.items()}
217221

218222
cpdef freq_to_period_freqstr(freq_n, freq_name):
219223
if freq_n == 1:
@@ -226,6 +230,20 @@ cpdef freq_to_period_freqstr(freq_n, freq_name):
226230

227231
# Map deprecated resolution abbreviations to correct resolution abbreviations
228232
DEPR_ABBREVS: dict[str, str]= {
233+
"A": "Y",
234+
"a": "Y",
235+
"A-DEC": "Y-DEC",
236+
"A-JAN": "Y-JAN",
237+
"A-FEB": "Y-FEB",
238+
"A-MAR": "Y-MAR",
239+
"A-APR": "Y-APR",
240+
"A-MAY": "Y-MAY",
241+
"A-JUN": "Y-JUN",
242+
"A-JUL": "Y-JUL",
243+
"A-AUG": "Y-AUG",
244+
"A-SEP": "Y-SEP",
245+
"A-OCT": "Y-OCT",
246+
"A-NOV": "Y-NOV",
229247
"T": "min",
230248
"t": "min",
231249
"S": "s",

pandas/_libs/tslibs/offsets.pyx

+18-15
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ from cpython.datetime cimport (
1515
time as dt_time,
1616
timedelta,
1717
)
18+
1819
import warnings
1920

2021
import_datetime()
@@ -48,7 +49,6 @@ from pandas._libs.tslibs.ccalendar import (
4849
)
4950
from pandas.util._exceptions import find_stack_level
5051

51-
5252
from pandas._libs.tslibs.ccalendar cimport (
5353
dayofweek,
5454
get_days_in_month,
@@ -58,6 +58,8 @@ from pandas._libs.tslibs.ccalendar cimport (
5858
from pandas._libs.tslibs.conversion cimport localize_pydatetime
5959
from pandas._libs.tslibs.dtypes cimport (
6060
c_DEPR_ABBREVS,
61+
c_OFFSET_DEPR_FREQSTR,
62+
c_REVERSE_OFFSET_DEPR_FREQSTR,
6163
periods_per_day,
6264
)
6365
from pandas._libs.tslibs.nattype cimport (
@@ -2496,7 +2498,7 @@ cdef class YearEnd(YearOffset):
24962498
"""
24972499

24982500
_default_month = 12
2499-
_prefix = "A"
2501+
_prefix = "Y"
25002502
_day_opt = "end"
25012503

25022504
cdef readonly:
@@ -4539,7 +4541,7 @@ prefix_mapping = {
45394541
offset._prefix: offset
45404542
for offset in [
45414543
YearBegin, # 'AS'
4542-
YearEnd, # 'A'
4544+
YearEnd, # 'Y'
45434545
BYearBegin, # 'BAS'
45444546
BYearEnd, # 'BA'
45454547
BusinessDay, # 'B'
@@ -4581,8 +4583,7 @@ _lite_rule_alias = {
45814583
"W": "W-SUN",
45824584
"Q": "Q-DEC",
45834585

4584-
"A": "A-DEC", # YearEnd(month=12),
4585-
"Y": "A-DEC",
4586+
"Y": "Y-DEC", # YearEnd(month=12),
45864587
"AS": "AS-JAN", # YearBegin(month=1),
45874588
"YS": "AS-JAN",
45884589
"BA": "BA-DEC", # BYearEnd(month=12),
@@ -4707,21 +4708,22 @@ cpdef to_offset(freq, bint is_period=False):
47074708

47084709
tups = zip(split[0::4], split[1::4], split[2::4])
47094710
for n, (sep, stride, name) in enumerate(tups):
4710-
if is_period is False and name == "M":
4711+
if is_period is False and name in c_OFFSET_DEPR_FREQSTR:
47114712
warnings.warn(
4712-
"\'M\' will be deprecated, please use \'ME\' "
4713-
"for \'month end\'",
4713+
f"\'{name}\' will be deprecated, please use "
4714+
f"\'{c_OFFSET_DEPR_FREQSTR.get(name)}\' instead.",
47144715
UserWarning,
47154716
stacklevel=find_stack_level(),
47164717
)
4717-
name = "ME"
4718-
if is_period is True and name == "ME":
4718+
name = c_OFFSET_DEPR_FREQSTR[name]
4719+
if is_period is True and name in c_REVERSE_OFFSET_DEPR_FREQSTR:
47194720
raise ValueError(
4720-
r"for Period, please use \'M\' "
4721-
"instead of \'ME\'"
4721+
f"for Period, please use "
4722+
f"\'{c_REVERSE_OFFSET_DEPR_FREQSTR.get(name)}\' "
4723+
f"instead of \'{name}\'"
47224724
)
4723-
elif is_period is True and name == "M":
4724-
name = "ME"
4725+
elif is_period is True and name in c_OFFSET_DEPR_FREQSTR:
4726+
name = c_OFFSET_DEPR_FREQSTR.get(name)
47254727

47264728
if sep != "" and not sep.isspace():
47274729
raise ValueError("separator must be spaces")
@@ -4740,6 +4742,7 @@ cpdef to_offset(freq, bint is_period=False):
47404742
stacklevel=find_stack_level(),
47414743
)
47424744
prefix = c_DEPR_ABBREVS[prefix]
4745+
47434746
if prefix in {"D", "H", "min", "s", "ms", "us", "ns"}:
47444747
# For these prefixes, we have something like "3H" or
47454748
# "2.5T", so we can construct a Timedelta with the
@@ -4753,7 +4756,7 @@ cpdef to_offset(freq, bint is_period=False):
47534756
offset *= stride_sign
47544757
else:
47554758
stride = int(stride)
4756-
offset = _get_offset(name)
4759+
offset = _get_offset(prefix)
47574760
offset = offset * int(np.fabs(stride) * stride_sign)
47584761

47594762
if delta is None:

pandas/_libs/tslibs/timestamps.pyx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1249,7 +1249,7 @@ cdef class _Timestamp(ABCTimestamp):
12491249
>>> ts = pd.Timestamp('2020-03-14T15:32:52.192548651')
12501250
>>> # Year end frequency
12511251
>>> ts.to_period(freq='Y')
1252-
Period('2020', 'A-DEC')
1252+
Period('2020', 'Y-DEC')
12531253
12541254
>>> # Month end frequency
12551255
>>> ts.to_period(freq='M')

0 commit comments

Comments
 (0)