Skip to content

Commit

Permalink
ERR: fix error message in Period for invalid frequency (#37602)
Browse files Browse the repository at this point in the history
  • Loading branch information
jorisvandenbossche authored Nov 3, 2020
1 parent 1c2de61 commit 67b087f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pandas/_libs/tslibs/period.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2438,7 +2438,7 @@ cpdef int freq_to_dtype_code(BaseOffset freq) except? -1:
try:
return freq._period_dtype_code
except AttributeError as err:
raise ValueError(INVALID_FREQ_ERR_MSG) from err
raise ValueError(INVALID_FREQ_ERR_MSG.format(freq)) from err


cdef int64_t _ordinal_from_fields(int year, int month, quarter, int day,
Expand Down
6 changes: 6 additions & 0 deletions pandas/tests/scalar/period/test_period.py
Original file line number Diff line number Diff line change
Expand Up @@ -1554,3 +1554,9 @@ def test_negone_ordinals():
repr(period)
period = Period(ordinal=-1, freq="W")
repr(period)


def test_invalid_frequency_error_message():
msg = "Invalid frequency: <WeekOfMonth: week=0, weekday=0>"
with pytest.raises(ValueError, match=msg):
Period("2012-01-02", freq="WOM-1MON")

0 comments on commit 67b087f

Please sign in to comment.