Skip to content

Commit b8eadbd

Browse files
smarieSylvain MARIE
authored andcommitted
Added tests for period str and repr. (pandas-dev#53003)
* Added tests for period str and repr. Fixes pandas-dev#53000 * Removed commented params in test, improved test for repr, and blackened. * Better tests * Moved the two independent tests into parametrized test --------- Co-authored-by: Sylvain MARIE <[email protected]>
1 parent 19305cc commit b8eadbd

File tree

1 file changed

+30
-16
lines changed

1 file changed

+30
-16
lines changed

pandas/tests/scalar/period/test_period.py

+30-16
Original file line numberDiff line numberDiff line change
@@ -705,27 +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(
709+
"str_ts,freq,str_res,str_freq",
710+
(
711+
("Jan-2000", None, "2000-01", "M"),
712+
("2000-12-15", None, "2000-12-15", "D"),
713+
(
714+
"2000-12-15 13:45:26.123456789",
715+
"N",
716+
"2000-12-15 13:45:26.123456789",
717+
"N",
718+
),
719+
("2000-12-15 13:45:26.123456789", "U", "2000-12-15 13:45:26.123456", "U"),
720+
("2000-12-15 13:45:26.123456", None, "2000-12-15 13:45:26.123456", "U"),
721+
("2000-12-15 13:45:26.123456789", "L", "2000-12-15 13:45:26.123", "L"),
722+
("2000-12-15 13:45:26.123", None, "2000-12-15 13:45:26.123", "L"),
723+
("2000-12-15 13:45:26", "S", "2000-12-15 13:45:26", "S"),
724+
("2000-12-15 13:45:26", "T", "2000-12-15 13:45", "T"),
725+
("2000-12-15 13:45:26", "H", "2000-12-15 13:00", "H"),
726+
("2000-12-15", "Y", "2000", "A-DEC"),
727+
("2000-12-15", "Q", "2000Q4", "Q-DEC"),
728+
("2000-12-15", "M", "2000-12", "M"),
729+
("2000-12-15", "W", "2000-12-11/2000-12-17", "W-SUN"),
730+
("2000-12-15", "D", "2000-12-15", "D"),
731+
("2000-12-15", "B", "2000-12-15", "B"),
732+
),
733+
)
734+
def test_repr(self, str_ts, freq, str_res, str_freq):
735+
p = Period(str_ts, freq=freq)
736+
assert str(p) == str_res
737+
assert repr(p) == f"Period('{str_res}', '{str_freq}')"
714738

715739
def test_repr_nat(self):
716740
p = Period("nat", freq="M")
717741
assert repr(NaT) in repr(p)
718742

719-
def test_millisecond_repr(self):
720-
p = Period("2000-01-01 12:15:02.123")
721-
722-
assert repr(p) == "Period('2000-01-01 12:15:02.123', 'L')"
723-
724-
def test_microsecond_repr(self):
725-
p = Period("2000-01-01 12:15:02.123567")
726-
727-
assert repr(p) == "Period('2000-01-01 12:15:02.123567', 'U')"
728-
729743
def test_strftime(self):
730744
# GH#3363
731745
p = Period("2000-1-1 12:34:12", freq="S")

0 commit comments

Comments
 (0)