Skip to content

Commit ccfdcda

Browse files
jorisvandenbosschepull[bot]
authored andcommitted
ERR: fix error message in Period for invalid frequency (#37602)
1 parent ac479eb commit ccfdcda

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

pandas/_libs/tslibs/period.pyx

+1-1
Original file line numberDiff line numberDiff line change
@@ -2438,7 +2438,7 @@ cpdef int freq_to_dtype_code(BaseOffset freq) except? -1:
24382438
try:
24392439
return freq._period_dtype_code
24402440
except AttributeError as err:
2441-
raise ValueError(INVALID_FREQ_ERR_MSG) from err
2441+
raise ValueError(INVALID_FREQ_ERR_MSG.format(freq)) from err
24422442

24432443

24442444
cdef int64_t _ordinal_from_fields(int year, int month, quarter, int day,

pandas/tests/scalar/period/test_period.py

+6
Original file line numberDiff line numberDiff line change
@@ -1554,3 +1554,9 @@ def test_negone_ordinals():
15541554
repr(period)
15551555
period = Period(ordinal=-1, freq="W")
15561556
repr(period)
1557+
1558+
1559+
def test_invalid_frequency_error_message():
1560+
msg = "Invalid frequency: <WeekOfMonth: week=0, weekday=0>"
1561+
with pytest.raises(ValueError, match=msg):
1562+
Period("2012-01-02", freq="WOM-1MON")

0 commit comments

Comments
 (0)