From 082e570e8740d95dc305bc13e807b98de69b5fce Mon Sep 17 00:00:00 2001 From: Joris Van den Bossche Date: Tue, 3 Nov 2020 15:55:24 +0100 Subject: [PATCH] ERR: fix error message in Period for invalid frequency --- pandas/_libs/tslibs/period.pyx | 2 +- pandas/tests/scalar/period/test_period.py | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/pandas/_libs/tslibs/period.pyx b/pandas/_libs/tslibs/period.pyx index b1f9ff71f5faa..b817d80c64ccd 100644 --- a/pandas/_libs/tslibs/period.pyx +++ b/pandas/_libs/tslibs/period.pyx @@ -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, diff --git a/pandas/tests/scalar/period/test_period.py b/pandas/tests/scalar/period/test_period.py index f150e5e5b18b2..46bc6421c2070 100644 --- a/pandas/tests/scalar/period/test_period.py +++ b/pandas/tests/scalar/period/test_period.py @@ -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: " + with pytest.raises(ValueError, match=msg): + Period("2012-01-02", freq="WOM-1MON")