Skip to content

Commit 682c0c7

Browse files
committed
deprecate lowercase alias 'b', fix tests
1 parent 48706dd commit 682c0c7

File tree

13 files changed

+127
-57
lines changed

13 files changed

+127
-57
lines changed

pandas/_libs/tslibs/dtypes.pyx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,15 @@ cdef dict c_DEPR_ABBREVS = {
348348

349349
cdef dict c_PERIOD_AND_OFFSET_DEPR_FREQSTR = {
350350
"w": "W",
351+
"w-mon": "W-MON",
352+
"w-tue": "W-TUE",
353+
"w-wed": "W-WED",
354+
"w-thu": "W-THU",
355+
"w-fri": "W-FRI",
356+
"w-sat": "W-SAT",
357+
"w-sun": "W-SUN",
351358
"d": "D",
359+
"b": "B",
352360
"MIN": "min",
353361
}
354362

pandas/tests/arithmetic/test_period.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1086,7 +1086,7 @@ def test_parr_add_timedeltalike_minute_gt1(self, three_days, box_with_array):
10861086
with pytest.raises(TypeError, match=msg):
10871087
other - rng
10881088

1089-
@pytest.mark.parametrize("freqstr", ["5ns", "5us", "5ms", "5s", "5min", "5h", "5d"])
1089+
@pytest.mark.parametrize("freqstr", ["5ns", "5us", "5ms", "5s", "5min", "5h", "5D"])
10901090
def test_parr_add_timedeltalike_tick_gt1(self, three_days, freqstr, box_with_array):
10911091
# GH#23031 adding a time-delta-like offset to a PeriodArray that has
10921092
# tick-like frequency with n != 1

pandas/tests/groupby/test_groupby_dropna.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ def test_groupby_drop_nan_with_multi_index():
420420
),
421421
),
422422
"datetime64[ns]",
423-
"period[d]",
423+
"period[D]",
424424
"Sparse[float]",
425425
],
426426
)
@@ -437,7 +437,7 @@ def test_no_sort_keep_na(sequence_index, dtype, test_series, as_index):
437437
# Unique values to use for grouper, depends on dtype
438438
if dtype in ("string", "string[pyarrow]"):
439439
uniques = {"x": "x", "y": "y", "z": pd.NA}
440-
elif dtype in ("datetime64[ns]", "period[d]"):
440+
elif dtype in ("datetime64[ns]", "period[D]"):
441441
uniques = {"x": "2016-01-01", "y": "2017-01-01", "z": pd.NA}
442442
else:
443443
uniques = {"x": 1, "y": 2, "z": np.nan}

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import pandas._testing as tm
88

99

10+
@pytest.mark.filterwarnings(r"ignore:PeriodDtype\[B\] is deprecated:FutureWarning")
11+
@pytest.mark.filterwarnings("ignore:Period with BDay freq:FutureWarning")
1012
@pytest.mark.parametrize("tz", [None, "Asia/Shanghai", "Europe/Berlin"])
1113
@pytest.mark.parametrize("name", [None, "my_dti"])
1214
def test_dti_snap(name, tz, unit):
@@ -27,7 +29,9 @@ def test_dti_snap(name, tz, unit):
2729
dti = dti.as_unit(unit)
2830

2931
result = dti.snap(freq="W-MON")
30-
expected = date_range("12/31/2001", "1/7/2002", name=name, tz=tz, freq="w-mon")
32+
msg = "'w-mon' is deprecated and will be removed in a future version."
33+
with tm.assert_produces_warning(FutureWarning, match=msg):
34+
expected = date_range("12/31/2001", "1/7/2002", name=name, tz=tz, freq="w-mon")
3135
expected = expected.repeat([3, 4])
3236
expected = expected.as_unit(unit)
3337
tm.assert_index_equal(result, expected)
@@ -37,7 +41,9 @@ def test_dti_snap(name, tz, unit):
3741

3842
result = dti.snap(freq="B")
3943

40-
expected = date_range("1/1/2002", "1/7/2002", name=name, tz=tz, freq="b")
44+
msg = "'b' is deprecated and will be removed in a future version."
45+
with tm.assert_produces_warning(FutureWarning, match=msg):
46+
expected = date_range("1/1/2002", "1/7/2002", name=name, tz=tz, freq="b")
4147
expected = expected.repeat([1, 1, 1, 2, 2])
4248
expected = expected.as_unit(unit)
4349
tm.assert_index_equal(result, expected)

pandas/tests/indexes/datetimes/test_date_range.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,8 @@ def test_frequency_A_raises(self, freq):
792792
"freq,freq_depr",
793793
[
794794
("2W", "2w"),
795+
("2W-WED", "2w-wed"),
796+
("2B", "2b"),
795797
("2D", "2d"),
796798
],
797799
)

pandas/tests/indexes/period/test_constructors.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,12 @@ def test_period_index_T_L_U_N_raises(self, freq_depr):
7373
with pytest.raises(ValueError, match=msg):
7474
PeriodIndex(["2020-01", "2020-05"], freq=freq_depr)
7575

76-
@pytest.mark.parametrize("freq,freq_depr", [("2W", "2w"), ("2D", "2d")])
76+
@pytest.mark.filterwarnings(r"ignore:PeriodDtype\[B\] is deprecated:FutureWarning")
77+
@pytest.mark.filterwarnings("ignore:Period with BDay freq:FutureWarning")
78+
@pytest.mark.parametrize(
79+
"freq,freq_depr",
80+
[("2W", "2w"), ("2W-FRI", "2w-fri"), ("2D", "2d"), ("2B", "2b")],
81+
)
7782
def test_period_index_depr_lowercase_frequency(self, freq, freq_depr):
7883
# GH#58998
7984
msg = (

pandas/tests/indexes/timedeltas/test_scalar_compat.py

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -103,30 +103,34 @@ def test_round(self):
103103
t1c = TimedeltaIndex(np.array([1, 1, 1], "m8[D]")).as_unit("ns")
104104

105105
# note that negative times round DOWN! so don't give whole numbers
106-
for freq, s1, s2 in [
107-
("ns", t1, t2),
108-
("us", t1, t2),
109-
(
110-
"ms",
111-
t1a,
112-
TimedeltaIndex(
113-
["-1 days +00:00:00", "-2 days +23:58:58", "-2 days +23:57:56"]
106+
msg = "'d' is deprecated and will be removed in a future version."
107+
108+
with tm.assert_produces_warning(FutureWarning, match=msg):
109+
for freq, s1, s2 in [
110+
("ns", t1, t2),
111+
("us", t1, t2),
112+
(
113+
"ms",
114+
t1a,
115+
TimedeltaIndex(
116+
["-1 days +00:00:00", "-2 days +23:58:58", "-2 days +23:57:56"]
117+
),
114118
),
115-
),
116-
(
117-
"s",
118-
t1a,
119-
TimedeltaIndex(
120-
["-1 days +00:00:00", "-2 days +23:58:58", "-2 days +23:57:56"]
119+
(
120+
"s",
121+
t1a,
122+
TimedeltaIndex(
123+
["-1 days +00:00:00", "-2 days +23:58:58", "-2 days +23:57:56"]
124+
),
121125
),
122-
),
123-
("12min", t1c, TimedeltaIndex(["-1 days", "-1 days", "-1 days"])),
124-
("h", t1c, TimedeltaIndex(["-1 days", "-1 days", "-1 days"])),
125-
("d", t1c, -1 * t1c),
126-
]:
127-
r1 = t1.round(freq)
126+
("12min", t1c, TimedeltaIndex(["-1 days", "-1 days", "-1 days"])),
127+
("h", t1c, TimedeltaIndex(["-1 days", "-1 days", "-1 days"])),
128+
("d", t1c, -1 * t1c),
129+
]:
130+
r1 = t1.round(freq)
131+
r2 = t2.round(freq)
132+
128133
tm.assert_index_equal(r1, s1)
129-
r2 = t2.round(freq)
130134
tm.assert_index_equal(r2, s2)
131135

132136
def test_components(self):

pandas/tests/resample/test_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ def test_resample_empty_dtypes(index, dtype, resample_method):
436436

437437
empty_series_dti = Series([], index, dtype)
438438
with tm.assert_produces_warning(warn, match=msg):
439-
rs = empty_series_dti.resample("d", group_keys=False)
439+
rs = empty_series_dti.resample("D", group_keys=False)
440440
try:
441441
getattr(rs, resample_method)()
442442
except DataError:

pandas/tests/resample/test_datetime_index.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,9 @@ def test_resample_basic_from_daily(unit):
336336
s = Series(np.random.default_rng(2).random(len(dti)), dti)
337337

338338
# to weekly
339-
result = s.resample("w-sun").last()
339+
msg = "'w-sun' is deprecated and will be removed in a future version."
340+
with tm.assert_produces_warning(FutureWarning, match=msg):
341+
result = s.resample("w-sun").last()
340342

341343
assert len(result) == 3
342344
assert (result.index.dayofweek == [6, 6, 6]).all()
@@ -2038,7 +2040,11 @@ def test_resample_BM_BQ_raises(freq):
20382040

20392041
@pytest.mark.parametrize(
20402042
"freq,freq_depr,data",
2041-
[("1W-SUN", "1w", ["2013-01-06"]), ("1D", "1d", ["2013-01-01"])],
2043+
[
2044+
("1W-SUN", "1w-sun", ["2013-01-06"]),
2045+
("1D", "1d", ["2013-01-01"]),
2046+
("1B", "1b", ["2013-01-01"]),
2047+
],
20422048
)
20432049
def test_resample_depr_lowercase_frequency(freq, freq_depr, data):
20442050
msg = f"'{freq_depr[1:]}' is deprecated and will be removed in a future version."

pandas/tests/scalar/period/test_period.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,25 @@ def test_period_large_ordinal(self, hour):
615615
p = Period(ordinal=2562048 + hour, freq="1h")
616616
assert p.hour == hour
617617

618+
@pytest.mark.filterwarnings(
619+
"ignore:Period with BDay freq is deprecated:FutureWarning"
620+
)
621+
@pytest.mark.parametrize(
622+
"freq,freq_depr",
623+
[("2W", "2w"), ("2W-FRI", "2w-fri"), ("2D", "2d"), ("2B", "2b")],
624+
)
625+
def test_period_deprecated_lowercase_freq(self, freq, freq_depr):
626+
# GH#58998
627+
msg = (
628+
f"'{freq_depr[1:]}' is deprecated and will be removed in a future version."
629+
)
630+
631+
with tm.assert_produces_warning(FutureWarning, match=msg):
632+
result = Period("2016-03-01 09:00", freq=freq_depr)
633+
634+
expected = Period("2016-03-01 09:00", freq=freq)
635+
assert result == expected
636+
618637

619638
class TestPeriodMethods:
620639
def test_round_trip(self):

0 commit comments

Comments
 (0)