Skip to content

Commit 7187e67

Browse files
authored
BUG: disallow constructing Period with freq=C (#52567)
1 parent 0e1c237 commit 7187e67

File tree

5 files changed

+25
-1
lines changed

5 files changed

+25
-1
lines changed

doc/source/whatsnew/v2.1.0.rst

+2
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,8 @@ Period
339339
- Bug in :meth:`arrays.PeriodArray.map` and :meth:`PeriodIndex.map`, where the supplied callable operated array-wise instead of element-wise (:issue:`51977`)
340340
- Bug in :func:`read_csv` not processing empty strings as a null value, with ``engine="pyarrow"`` (:issue:`52087`)
341341
- Bug in :func:`read_csv` returning ``object`` dtype columns instead of ``float64`` dtype columns with ``engine="pyarrow"`` for columns that are all null with ``engine="pyarrow"`` (:issue:`52087`)
342+
- Bug in incorrectly allowing construction of :class:`Period` or :class:`PeriodDtype` with :class:`CustomBusinessDay` freq; use :class:`BusinessDay` instead (:issue:`52534`)
343+
-
342344

343345
Plotting
344346
^^^^^^^^

pandas/_libs/tslibs/offsets.pyx

+7
Original file line numberDiff line numberDiff line change
@@ -3778,6 +3778,13 @@ cdef class CustomBusinessDay(BusinessDay):
37783778
["n", "normalize", "weekmask", "holidays", "calendar", "offset"]
37793779
)
37803780

3781+
@property
3782+
def _period_dtype_code(self):
3783+
# GH#52534
3784+
raise TypeError(
3785+
"CustomBusinessDay cannot be used with Period or PeriodDtype"
3786+
)
3787+
37813788
_apply_array = BaseOffset._apply_array
37823789

37833790
def __init__(

pandas/tests/dtypes/test_dtypes.py

+8
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,14 @@ def test_construction(self):
438438
assert dt.freq == pd.tseries.offsets.Hour(26)
439439
assert is_period_dtype(dt)
440440

441+
def test_cannot_use_custom_businessday(self):
442+
# GH#52534
443+
msg = "CustomBusinessDay cannot be used with Period or PeriodDtype"
444+
with pytest.raises(TypeError, match=msg):
445+
PeriodDtype("C")
446+
with pytest.raises(TypeError, match=msg):
447+
PeriodDtype(pd.offsets.CustomBusinessDay())
448+
441449
def test_subclass(self):
442450
a = PeriodDtype("period[D]")
443451
b = PeriodDtype("period[3D]")

pandas/tests/scalar/period/test_period.py

+8
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@
3434

3535

3636
class TestPeriodConstruction:
37+
def test_custom_business_day_freq_raises(self):
38+
# GH#52534
39+
msg = "CustomBusinessDay cannot be used with Period or PeriodDtype"
40+
with pytest.raises(TypeError, match=msg):
41+
Period("2023-04-10", freq="C")
42+
with pytest.raises(TypeError, match=msg):
43+
Period("2023-04-10", freq=offsets.CustomBusinessDay())
44+
3745
def test_from_td64nat_raises(self):
3846
# GH#44507
3947
td = NaT.to_numpy("m8[ns]")

pandas/tseries/frequencies.py

-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@
6767
"BAS": "A",
6868
"MS": "M",
6969
"D": "D",
70-
"C": "C",
7170
"B": "B",
7271
"T": "T",
7372
"S": "S",

0 commit comments

Comments
 (0)