Skip to content

Commit af02fb0

Browse files
author
Sylvain MARIE
committed
Added tests for period str and repr. Fixes pandas-dev#53000
1 parent a3c9a5c commit af02fb0

File tree

1 file changed

+35
-6
lines changed

1 file changed

+35
-6
lines changed

pandas/tests/scalar/period/test_period.py

+35-6
Original file line numberDiff line numberDiff line change
@@ -705,12 +705,41 @@ def test_to_timestamp_microsecond(self, ts, expected, freq):
705705
# --------------------------------------------------------------
706706
# Rendering: __repr__, strftime, etc
707707

708-
def test_repr(self):
709-
p = Period("Jan-2000")
710-
assert "2000-01" in repr(p)
711-
712-
p = Period("2000-12-15")
713-
assert "2000-12-15" in repr(p)
708+
@pytest.mark.parametrize("str_ts,freq,str_res", (
709+
("Jan-2000", None, "2000-01"),
710+
("2000-12-15", None, "2000-12-15"),
711+
("2000-12-15", "N", "2000-12-15 00:00:00.000000000"),
712+
("2000-12-15", "U", "2000-12-15 00:00:00.000000"),
713+
("2000-12-15", "L", "2000-12-15 00:00:00.000"),
714+
("2000-12-15", "S", "2000-12-15 00:00:00"),
715+
("2000-12-15", "T", "2000-12-15 00:00"),
716+
("2000-12-15", "H", "2000-12-15 00:00"),
717+
# ("2000-12-15", "BH", "2000-12-15"),
718+
# ("2000-12-15", "BYS", "2000-12-15"),
719+
# ("2000-12-15", "YS", "2000-12-15"),
720+
# ("2000-12-15", "BY", "2000-12-15"),
721+
("2000-12-15", "Y", "2000"),
722+
# ("2000-12-15", "BQS", "2000-12-15"),
723+
# ("2000-12-15", "QS", "2000-12-15"),
724+
# ("2000-12-15", "BQ", "2000-12-15"),
725+
("2000-12-15", "Q", "2000Q4"),
726+
# ("2000-12-15", "CBMS", "2000-12-15"),
727+
# ("2000-12-15", "BMS", "2000-12-15"),
728+
# ("2000-12-15", "SMS", "2000-12-15"),
729+
# ("2000-12-15", "MS", "2000-12-15"),
730+
# ("2000-12-15", "CBM", "2000-12-15"),
731+
# ("2000-12-15", "BM", "2000-12-15"),
732+
# ("2000-12-15", "SM", "2000-12-15"),
733+
("2000-12-15", "M", "2000-12"),
734+
("2000-12-15", "W", "2000-12-11/2000-12-17"),
735+
("2000-12-15", "D", "2000-12-15"),
736+
# ("2000-12-15", "C", "2000-12-15"),
737+
("2000-12-15", "B", "2000-12-15"),
738+
))
739+
def test_repr(self, str_ts, freq, str_res):
740+
p = Period(str_ts, freq=freq)
741+
assert str(p) == str_res
742+
assert str_res in repr(p)
714743

715744
def test_repr_nat(self):
716745
p = Period("nat", freq="M")

0 commit comments

Comments
 (0)