Skip to content

Commit 514d63f

Browse files
committed
add tests #53020
1 parent 414f1d3 commit 514d63f

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

pandas/tests/tslibs/test_parse_iso8601.py

+44
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,47 @@ def test_parsers_iso8601_leading_space():
7373
date_str, expected = ("2013-1-1 5:30:00", datetime(2013, 1, 1, 5, 30))
7474
actual = tslib._test_parse_iso8601(" " * 200 + date_str)
7575
assert actual == expected
76+
77+
78+
@pytest.mark.parametrize(
79+
"date_str, timespec, exp",
80+
[
81+
("2023-01-01 00:00:00", "auto", "2023-01-01T00:00:00"),
82+
("2023-01-01 00:00:00", "seconds", "2023-01-01T00:00:00"),
83+
("2023-01-01 00:00:00", "milliseconds", "2023-01-01T00:00:00.000"),
84+
("2023-01-01 00:00:00", "microseconds", "2023-01-01T00:00:00.000000"),
85+
("2023-01-01 00:00:00", "nanoseconds", "2023-01-01T00:00:00.000000000"),
86+
("2023-01-01 00:00:00.001", "auto", "2023-01-01T00:00:00.001000"),
87+
("2023-01-01 00:00:00.001", "seconds", "2023-01-01T00:00:00"),
88+
("2023-01-01 00:00:00.001", "milliseconds", "2023-01-01T00:00:00.001"),
89+
("2023-01-01 00:00:00.001", "microseconds", "2023-01-01T00:00:00.001000"),
90+
("2023-01-01 00:00:00.001", "nanoseconds", "2023-01-01T00:00:00.001000000"),
91+
("2023-01-01 00:00:00.000001", "auto", "2023-01-01T00:00:00.000001"),
92+
("2023-01-01 00:00:00.000001", "seconds", "2023-01-01T00:00:00"),
93+
("2023-01-01 00:00:00.000001", "milliseconds", "2023-01-01T00:00:00.000"),
94+
("2023-01-01 00:00:00.000001", "microseconds", "2023-01-01T00:00:00.000001"),
95+
("2023-01-01 00:00:00.000001", "nanoseconds", "2023-01-01T00:00:00.000001000"),
96+
("2023-01-01 00:00:00.000000001", "auto", "2023-01-01T00:00:00.000000001"),
97+
("2023-01-01 00:00:00.000000001", "seconds", "2023-01-01T00:00:00"),
98+
("2023-01-01 00:00:00.000000001", "milliseconds", "2023-01-01T00:00:00.000"),
99+
("2023-01-01 00:00:00.000000001", "microseconds", "2023-01-01T00:00:00.000000"),
100+
(
101+
"2023-01-01 00:00:00.000000001",
102+
"nanoseconds",
103+
"2023-01-01T00:00:00.000000001",
104+
),
105+
("2023-01-01 00:00:00.000001001", "auto", "2023-01-01T00:00:00.000001001"),
106+
("2023-01-01 00:00:00.000001001", "seconds", "2023-01-01T00:00:00"),
107+
("2023-01-01 00:00:00.000001001", "milliseconds", "2023-01-01T00:00:00.000"),
108+
("2023-01-01 00:00:00.000001001", "microseconds", "2023-01-01T00:00:00.000001"),
109+
(
110+
"2023-01-01 00:00:00.000001001",
111+
"nanoseconds",
112+
"2023-01-01T00:00:00.000001001",
113+
),
114+
],
115+
)
116+
def test_iso8601_formatter(date_str: str, timespec: str, exp: str):
117+
# GH#53020
118+
ts = Timestamp(date_str)
119+
assert ts.isoformat(timespec=timespec) == exp

0 commit comments

Comments
 (0)