Skip to content

Commit a4d86bd

Browse files
committed
add the specific exception message for CBH
1 parent cc68f8a commit a4d86bd

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

pandas/core/indexes/datetimes.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1134,11 +1134,13 @@ def bdate_range(
11341134
raise TypeError(msg)
11351135

11361136
if isinstance(freq, str) and freq.upper().startswith("C"):
1137+
msg = f"invalid custom frequency string: {freq}"
1138+
if freq == "CBH":
1139+
raise ValueError(f"{msg}, did you mean cbh?")
11371140
try:
11381141
weekmask = weekmask or "Mon Tue Wed Thu Fri"
11391142
freq = prefix_mapping[freq](holidays=holidays, weekmask=weekmask)
11401143
except (KeyError, TypeError) as err:
1141-
msg = f"invalid custom frequency string: {freq}"
11421144
raise ValueError(msg) from err
11431145
elif holidays or weekmask:
11441146
msg = (

pandas/tests/indexes/datetimes/test_date_range.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1305,6 +1305,14 @@ def test_cdaterange_cbh(self):
13051305
)
13061306
tm.assert_index_equal(result, expected)
13071307

1308+
def test_cdaterange_deprecated_error_CBH(self):
1309+
# GH#62849
1310+
msg = "invalid custom frequency string: CBH, did you mean cbh?"
1311+
with pytest.raises(ValueError, match=msg):
1312+
bdate_range(
1313+
START, END, freq="CBH", weekmask="Mon Wed Fri", holidays=["2009-03-14"]
1314+
)
1315+
13081316

13091317
class TestDateRangeNonNano:
13101318
def test_date_range_reso_validation(self):

0 commit comments

Comments
 (0)