diff --git a/pandas/tests/scalar/period/test_period.py b/pandas/tests/scalar/period/test_period.py index a17079d0e76cb..d908c641a30c6 100644 --- a/pandas/tests/scalar/period/test_period.py +++ b/pandas/tests/scalar/period/test_period.py @@ -705,27 +705,41 @@ def test_to_timestamp_microsecond(self, ts, expected, freq): # -------------------------------------------------------------- # Rendering: __repr__, strftime, etc - def test_repr(self): - p = Period("Jan-2000") - assert "2000-01" in repr(p) - - p = Period("2000-12-15") - assert "2000-12-15" in repr(p) + @pytest.mark.parametrize( + "str_ts,freq,str_res,str_freq", + ( + ("Jan-2000", None, "2000-01", "M"), + ("2000-12-15", None, "2000-12-15", "D"), + ( + "2000-12-15 13:45:26.123456789", + "N", + "2000-12-15 13:45:26.123456789", + "N", + ), + ("2000-12-15 13:45:26.123456789", "U", "2000-12-15 13:45:26.123456", "U"), + ("2000-12-15 13:45:26.123456", None, "2000-12-15 13:45:26.123456", "U"), + ("2000-12-15 13:45:26.123456789", "L", "2000-12-15 13:45:26.123", "L"), + ("2000-12-15 13:45:26.123", None, "2000-12-15 13:45:26.123", "L"), + ("2000-12-15 13:45:26", "S", "2000-12-15 13:45:26", "S"), + ("2000-12-15 13:45:26", "T", "2000-12-15 13:45", "T"), + ("2000-12-15 13:45:26", "H", "2000-12-15 13:00", "H"), + ("2000-12-15", "Y", "2000", "A-DEC"), + ("2000-12-15", "Q", "2000Q4", "Q-DEC"), + ("2000-12-15", "M", "2000-12", "M"), + ("2000-12-15", "W", "2000-12-11/2000-12-17", "W-SUN"), + ("2000-12-15", "D", "2000-12-15", "D"), + ("2000-12-15", "B", "2000-12-15", "B"), + ), + ) + def test_repr(self, str_ts, freq, str_res, str_freq): + p = Period(str_ts, freq=freq) + assert str(p) == str_res + assert repr(p) == f"Period('{str_res}', '{str_freq}')" def test_repr_nat(self): p = Period("nat", freq="M") assert repr(NaT) in repr(p) - def test_millisecond_repr(self): - p = Period("2000-01-01 12:15:02.123") - - assert repr(p) == "Period('2000-01-01 12:15:02.123', 'L')" - - def test_microsecond_repr(self): - p = Period("2000-01-01 12:15:02.123567") - - assert repr(p) == "Period('2000-01-01 12:15:02.123567', 'U')" - def test_strftime(self): # GH#3363 p = Period("2000-1-1 12:34:12", freq="S")