Skip to content

Commit fbe024f

Browse files
authored
DEPR offsets: rename ‘BY’ to ‘BYE' (#56092)
1 parent 219bc5e commit fbe024f

File tree

13 files changed

+95
-34
lines changed

13 files changed

+95
-34
lines changed

doc/source/user_guide/timeseries.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -891,7 +891,7 @@ into ``freq`` keyword arguments. The available date offsets and associated frequ
891891
:class:`~pandas.tseries.offsets.FY5253Quarter`, ``'REQ'``, "retail (aka 52-53 week) quarter"
892892
:class:`~pandas.tseries.offsets.YearEnd`, ``'YE'``, "calendar year end"
893893
:class:`~pandas.tseries.offsets.YearBegin`, ``'YS'`` or ``'BYS'``,"calendar year begin"
894-
:class:`~pandas.tseries.offsets.BYearEnd`, ``'BY'``, "business year end"
894+
:class:`~pandas.tseries.offsets.BYearEnd`, ``'BYE'``, "business year end"
895895
:class:`~pandas.tseries.offsets.BYearBegin`, ``'BYS'``, "business year begin"
896896
:class:`~pandas.tseries.offsets.FY5253`, ``'RE'``, "retail (aka 52-53 week) year"
897897
:class:`~pandas.tseries.offsets.Easter`, None, "Easter holiday"
@@ -1253,7 +1253,7 @@ frequencies. We will refer to these aliases as *offset aliases*.
12531253
"QS", "quarter start frequency"
12541254
"BQS", "business quarter start frequency"
12551255
"YE", "year end frequency"
1256-
"BY", "business year end frequency"
1256+
"BYE", "business year end frequency"
12571257
"YS", "year start frequency"
12581258
"BYS", "business year start frequency"
12591259
"h", "hourly frequency"
@@ -1686,7 +1686,7 @@ the end of the interval.
16861686
.. warning::
16871687

16881688
The default values for ``label`` and ``closed`` is '**left**' for all
1689-
frequency offsets except for 'ME', 'YE', 'QE', 'BME', 'BY', 'BQE', and 'W'
1689+
frequency offsets except for 'ME', 'YE', 'QE', 'BME', 'BYE', 'BQE', and 'W'
16901690
which all have a default of 'right'.
16911691

16921692
This might unintendedly lead to looking ahead, where the value for a later

doc/source/whatsnew/v2.2.0.rst

+3-4
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,8 @@ Other API changes
233233
Deprecations
234234
~~~~~~~~~~~~
235235

236-
Deprecate aliases ``M``, ``SM``, ``BM``, ``CBM``, ``Q``, ``BQ``, and ``Y`` in favour of ``ME``, ``SME``, ``BME``, ``CBME``, ``QE``, ``BQE``, and ``YE`` for offsets
237-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
236+
Deprecate aliases ``M``, ``SM``, ``BM``, ``CBM``, ``Q``, ``BQ``, ``Y``, and ``BY`` in favour of ``ME``, ``SME``, ``BME``, ``CBME``, ``QE``, ``BQE``, ``YE``, and ``BYE`` for offsets
237+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
238238

239239
Deprecated the following frequency aliases (:issue:`9586`):
240240

@@ -245,6 +245,7 @@ Deprecated the following frequency aliases (:issue:`9586`):
245245
- ``Q`` (quarter end) has been renamed ``QE`` for offsets
246246
- ``BQ`` (business quarter end) has been renamed ``BQE`` for offsets
247247
- ``Y`` (year end) has been renamed ``YE`` for offsets
248+
- ``BY`` (business year end) has been renamed ``BYE`` for offsets
248249

249250
For example:
250251

@@ -297,8 +298,6 @@ Other Deprecations
297298
- Deprecated string ``A`` denoting frequency in :class:`YearEnd` and strings ``A-DEC``, ``A-JAN``, etc. denoting annual frequencies with various fiscal year ends (:issue:`54275`)
298299
- Deprecated string ``BAS`` denoting frequency in :class:`BYearBegin` and strings ``BAS-DEC``, ``BAS-JAN``, etc. denoting annual frequencies with various fiscal year starts (:issue:`54275`)
299300
- Deprecated string ``BA`` denoting frequency in :class:`BYearEnd` and strings ``BA-DEC``, ``BA-JAN``, etc. denoting annual frequencies with various fiscal year ends (:issue:`54275`)
300-
- Deprecated string ``BQ`` denoting frequency in :class:`BQuarterEnd` (:issue:`52064`)
301-
- Deprecated strings ``BM``, ``CBM``, and ``SM`` denoting frequencies in :class:`BusinessMonthEnd`, :class:`CustomBusinessMonthEnd, :class:`SemiMonthEnd` (:issue:`52064`)
302301
- Deprecated strings ``H``, ``BH``, and ``CBH`` denoting frequencies in :class:`Hour`, :class:`BusinessHour`, :class:`CustomBusinessHour` (:issue:`52536`)
303302
- Deprecated strings ``H``, ``S``, ``U``, and ``N`` denoting units in :func:`to_timedelta` (:issue:`52536`)
304303
- Deprecated strings ``H``, ``T``, ``S``, ``L``, ``U``, and ``N`` denoting units in :class:`Timedelta` (:issue:`52536`)

pandas/_libs/tslibs/dtypes.pyx

+39-1
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,19 @@ OFFSET_TO_PERIOD_FREQSTR: dict = {
229229
"W": "W",
230230
"ME": "M",
231231
"Y": "Y",
232-
"BY": "Y",
232+
"BYE": "Y",
233+
"BYE-DEC": "Y-DEC",
234+
"BYE-JAN": "Y-JAN",
235+
"BYE-FEB": "Y-FEB",
236+
"BYE-MAR": "Y-MAR",
237+
"BYE-APR": "Y-APR",
238+
"BYE-MAY": "Y-MAY",
239+
"BYE-JUN": "Y-JUN",
240+
"BYE-JUL": "Y-JUL",
241+
"BYE-AUG": "Y-AUG",
242+
"BYE-SEP": "Y-SEP",
243+
"BYE-OCT": "Y-OCT",
244+
"BYE-NOV": "Y-NOV",
233245
"YS": "Y",
234246
"BYS": "Y",
235247
}
@@ -274,6 +286,32 @@ cdef dict c_OFFSET_DEPR_FREQSTR = {
274286
"A-SEP": "YE-SEP",
275287
"A-OCT": "YE-OCT",
276288
"A-NOV": "YE-NOV",
289+
"BY": "BYE",
290+
"BY-DEC": "BYE-DEC",
291+
"BY-JAN": "BYE-JAN",
292+
"BY-FEB": "BYE-FEB",
293+
"BY-MAR": "BYE-MAR",
294+
"BY-APR": "BYE-APR",
295+
"BY-MAY": "BYE-MAY",
296+
"BY-JUN": "BYE-JUN",
297+
"BY-JUL": "BYE-JUL",
298+
"BY-AUG": "BYE-AUG",
299+
"BY-SEP": "BYE-SEP",
300+
"BY-OCT": "BYE-OCT",
301+
"BY-NOV": "BYE-NOV",
302+
"BA": "BYE",
303+
"BA-DEC": "BYE-DEC",
304+
"BA-JAN": "BYE-JAN",
305+
"BA-FEB": "BYE-FEB",
306+
"BA-MAR": "BYE-MAR",
307+
"BA-APR": "BYE-APR",
308+
"BA-MAY": "BYE-MAY",
309+
"BA-JUN": "BYE-JUN",
310+
"BA-JUL": "BYE-JUL",
311+
"BA-AUG": "BYE-AUG",
312+
"BA-SEP": "BYE-SEP",
313+
"BA-OCT": "BYE-OCT",
314+
"BA-NOV": "BYE-NOV",
277315
"BM": "BME",
278316
"CBM": "CBME",
279317
"SM": "SME",

pandas/_libs/tslibs/offsets.pyx

+3-3
Original file line numberDiff line numberDiff line change
@@ -2405,7 +2405,7 @@ cdef class BYearEnd(YearOffset):
24052405

24062406
_outputName = "BusinessYearEnd"
24072407
_default_month = 12
2408-
_prefix = "BY"
2408+
_prefix = "BYE"
24092409
_day_opt = "business_end"
24102410

24112411

@@ -4535,7 +4535,7 @@ prefix_mapping = {
45354535
YearBegin, # 'YS'
45364536
YearEnd, # 'YE'
45374537
BYearBegin, # 'BYS'
4538-
BYearEnd, # 'BY'
4538+
BYearEnd, # 'BYE'
45394539
BusinessDay, # 'B'
45404540
BusinessMonthBegin, # 'BMS'
45414541
BusinessMonthEnd, # 'BME'
@@ -4577,7 +4577,7 @@ _lite_rule_alias = {
45774577

45784578
"YE": "YE-DEC", # YearEnd(month=12),
45794579
"YS": "YS-JAN", # YearBegin(month=1),
4580-
"BY": "BY-DEC", # BYearEnd(month=12),
4580+
"BYE": "BYE-DEC", # BYearEnd(month=12),
45814581
"BYS": "BYS-JAN", # BYearBegin(month=1),
45824582

45834583
"Min": "min",

pandas/core/resample.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2130,7 +2130,7 @@ def __init__(
21302130
else:
21312131
freq = to_offset(freq)
21322132

2133-
end_types = {"ME", "YE", "QE", "BME", "BY", "BQE", "W"}
2133+
end_types = {"ME", "YE", "QE", "BME", "BYE", "BQE", "W"}
21342134
rule = freq.rule_code
21352135
if rule in end_types or ("-" in rule and rule[: rule.find("-")] in end_types):
21362136
if closed is None:
@@ -2328,7 +2328,7 @@ def _adjust_bin_edges(
23282328

23292329
if self.freq.name in ("BME", "ME", "W") or self.freq.name.split("-")[0] in (
23302330
"BQE",
2331-
"BY",
2331+
"BYE",
23322332
"QE",
23332333
"YE",
23342334
"W",

pandas/tests/frame/methods/test_asfreq.py

+1
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ def test_asfreq_2ME(self, freq, freq_half):
247247
("2YE-MAR", "2Y-MAR"),
248248
("1YE", "1A"),
249249
("2YE-MAR", "2A-MAR"),
250+
("2BYE-MAR", "2BA-MAR"),
250251
],
251252
)
252253
def test_asfreq_frequency_M_Q_Y_A_deprecated(self, freq, freq_depr):

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

+17-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def test_to_period_quarterlyish(self, off):
5656
prng = rng.to_period()
5757
assert prng.freq == "QE-DEC"
5858

59-
@pytest.mark.parametrize("off", ["BY", "YS", "BYS"])
59+
@pytest.mark.parametrize("off", ["BYE", "YS", "BYS"])
6060
def test_to_period_annualish(self, off):
6161
rng = date_range("01-Jan-2012", periods=8, freq=off)
6262
prng = rng.to_period()
@@ -110,6 +110,22 @@ def test_to_period_frequency_M_Q_Y_A_deprecated(self, freq, freq_depr):
110110
with tm.assert_produces_warning(FutureWarning, match=msg):
111111
assert prng.freq == freq_depr
112112

113+
@pytest.mark.parametrize(
114+
"freq, freq_depr",
115+
[
116+
("2BQE-SEP", "2BQ-SEP"),
117+
("2BYE-MAR", "2BY-MAR"),
118+
],
119+
)
120+
def test_to_period_frequency_BQ_BY_deprecated(self, freq, freq_depr):
121+
# GH#9586
122+
msg = f"'{freq_depr[1:]}' is deprecated, please use '{freq[1:]}' instead."
123+
124+
rng = date_range("01-Jan-2012", periods=8, freq=freq)
125+
prng = rng.to_period()
126+
with tm.assert_produces_warning(FutureWarning, match=msg):
127+
prng.freq == freq_depr
128+
113129
def test_to_period_infer(self):
114130
# https://github.com/pandas-dev/pandas/issues/33358
115131
rng = date_range(

pandas/tests/indexes/datetimes/test_date_range.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,11 @@ def test_date_range_fractional_period(self):
151151
[
152152
("2ME", "2M"),
153153
("2SME", "2SM"),
154+
("2BQE", "2BQ"),
155+
("2BYE", "2BY"),
154156
],
155157
)
156-
def test_date_range_frequency_M_SM_deprecated(self, freq, freq_depr):
158+
def test_date_range_frequency_M_SM_BQ_BY_deprecated(self, freq, freq_depr):
157159
# GH#52064
158160
depr_msg = f"'{freq_depr[1:]}' is deprecated, please use '{freq[1:]}' instead."
159161

@@ -1541,11 +1543,11 @@ def test_date_range_negative_freq_year_end(self, unit):
15411543

15421544
def test_date_range_business_year_end_year(self, unit):
15431545
# see GH#9313
1544-
rng = date_range("1/1/2013", "7/1/2017", freq="BY", unit=unit)
1546+
rng = date_range("1/1/2013", "7/1/2017", freq="BYE", unit=unit)
15451547
exp = DatetimeIndex(
15461548
["2013-12-31", "2014-12-31", "2015-12-31", "2016-12-30"],
15471549
dtype=f"M8[{unit}]",
1548-
freq="BY",
1550+
freq="BYE",
15491551
)
15501552
tm.assert_index_equal(rng, exp)
15511553

pandas/tests/indexes/datetimes/test_datetime.py

+4-7
Original file line numberDiff line numberDiff line change
@@ -161,11 +161,6 @@ def test_CBH_deprecated(self):
161161
@pytest.mark.parametrize(
162162
"freq_depr, expected_values, expected_freq",
163163
[
164-
(
165-
"2BA",
166-
["2020-12-31", "2022-12-30"],
167-
"2BY-DEC",
168-
),
169164
(
170165
"AS-AUG",
171166
["2021-08-01", "2022-08-01", "2023-08-01"],
@@ -178,7 +173,7 @@ def test_CBH_deprecated(self):
178173
),
179174
],
180175
)
181-
def test_AS_BA_BAS_deprecated(self, freq_depr, expected_values, expected_freq):
176+
def test_AS_BAS_deprecated(self, freq_depr, expected_values, expected_freq):
182177
# GH#55479
183178
freq_msg = re.split("[0-9]*", freq_depr, maxsplit=1)[1]
184179
msg = f"'{freq_msg}' is deprecated and will be removed in a future version."
@@ -198,12 +193,14 @@ def test_AS_BA_BAS_deprecated(self, freq_depr, expected_values, expected_freq):
198193
@pytest.mark.parametrize(
199194
"freq, expected_values, freq_depr",
200195
[
196+
("2BYE-MAR", ["2016-03-31"], "2BA-MAR"),
197+
("2BYE-JUN", ["2016-06-30"], "2BY-JUN"),
201198
("2BME", ["2016-02-29", "2016-04-29", "2016-06-30"], "2BM"),
202199
("2BQE", ["2016-03-31"], "2BQ"),
203200
("1BQE-MAR", ["2016-03-31", "2016-06-30"], "1BQ-MAR"),
204201
],
205202
)
206-
def test_BM_BQ_deprecated(self, freq, expected_values, freq_depr):
203+
def test_BM_BQ_BY_deprecated(self, freq, expected_values, freq_depr):
207204
# GH#52064
208205
msg = f"'{freq_depr[1:]}' is deprecated, please use '{freq[1:]}' instead."
209206

pandas/tests/resample/test_period_index.py

+13-5
Original file line numberDiff line numberDiff line change
@@ -953,13 +953,21 @@ def test_resample_t_l_deprecated(self):
953953

954954

955955
@pytest.mark.parametrize(
956-
"freq_depr", ["2ME", "2QE", "2QE-FEB", "2BQE", "2BQE-FEB", "2YE", "2YE-MAR"]
956+
"freq,freq_depr",
957+
[
958+
("2M", "2ME"),
959+
("2Q", "2QE"),
960+
("2Q-FEB", "2QE-FEB"),
961+
("2BQ", "2BQE"),
962+
("2BQ-FEB", "2BQE-FEB"),
963+
("2Y", "2YE"),
964+
("2Y-MAR", "2YE-MAR"),
965+
("2BA-MAR", "2BYE-MAR"),
966+
],
957967
)
958-
def test_resample_frequency_ME_QE_error_message(series_and_frame, freq_depr):
968+
def test_resample_frequency_ME_QE_YE_error_message(series_and_frame, freq, freq_depr):
959969
# GH#9586
960-
pos_e = freq_depr.index("E")
961-
msg = f"for Period, please use '{freq_depr[1:pos_e]}{freq_depr[pos_e+1:]}' "
962-
f"instead of '{freq_depr[1:]}'"
970+
msg = f"for Period, please use '{freq[1:]}' instead of '{freq_depr[1:]}'"
963971

964972
obj = series_and_frame
965973
with pytest.raises(ValueError, match=msg):

pandas/tests/tseries/frequencies/test_inference.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def base_delta_code_pair(request):
5252

5353
freqs = (
5454
[f"QE-{month}" for month in MONTHS]
55-
+ [f"{annual}-{month}" for annual in ["YE", "BY"] for month in MONTHS]
55+
+ [f"{annual}-{month}" for annual in ["YE", "BYE"] for month in MONTHS]
5656
+ ["ME", "BME", "BMS"]
5757
+ [f"WOM-{count}{day}" for count in range(1, 5) for day in DAYS]
5858
+ [f"W-{day}" for day in DAYS]

pandas/tests/tseries/offsets/test_offsets.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -847,7 +847,7 @@ def test_rule_code(self):
847847
"NOV",
848848
"DEC",
849849
]
850-
base_lst = ["YE", "YS", "BY", "BYS", "QE", "QS", "BQE", "BQS"]
850+
base_lst = ["YE", "YS", "BYE", "BYS", "QE", "QS", "BQE", "BQS"]
851851
for base in base_lst:
852852
for v in suffix_lst:
853853
alias = "-".join([base, v])
@@ -866,7 +866,7 @@ def test_freq_offsets():
866866
class TestReprNames:
867867
def test_str_for_named_is_name(self):
868868
# look at all the amazing combinations!
869-
month_prefixes = ["YE", "YS", "BY", "BYS", "QE", "BQE", "BQS", "QS"]
869+
month_prefixes = ["YE", "YS", "BYE", "BYS", "QE", "BQE", "BQS", "QS"]
870870
names = [
871871
prefix + "-" + month
872872
for prefix in month_prefixes

pandas/tseries/frequencies.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
# --------------------------------------------------------------------
6060
# Offset related functions
6161

62-
_need_suffix = ["QS", "BQE", "BQS", "YS", "BY", "BYS"]
62+
_need_suffix = ["QS", "BQE", "BQS", "YS", "BYE", "BYS"]
6363

6464
for _prefix in _need_suffix:
6565
for _m in MONTHS:
@@ -345,7 +345,7 @@ def _get_annual_rule(self) -> str | None:
345345
if pos_check is None:
346346
return None
347347
else:
348-
return {"cs": "YS", "bs": "BYS", "ce": "YE", "be": "BY"}.get(pos_check)
348+
return {"cs": "YS", "bs": "BYS", "ce": "YE", "be": "BYE"}.get(pos_check)
349349

350350
def _get_quarterly_rule(self) -> str | None:
351351
if len(self.mdiffs) > 1:

0 commit comments

Comments
 (0)