Skip to content

Commit e7d15f0

Browse files
committed
add tests
1 parent feca574 commit e7d15f0

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

pandas/tests/scalar/timestamp/methods/test_tz_localize.py

+38
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,44 @@ def test_tz_localize_nonexistent(self, stamp, tz):
123123
ts.tz_localize(tz, nonexistent="raise")
124124
assert ts.tz_localize(tz, nonexistent="NaT") is NaT
125125

126+
@pytest.mark.parametrize(
127+
"stamp, tz, forward_expected, backward_expected",
128+
[
129+
(
130+
"2015-03-29 02:00:00",
131+
"Europe/Warsaw",
132+
"2015-03-29 03:00:00",
133+
"2015-03-29 01:59:59",
134+
), # utc+1 -> utc+2
135+
(
136+
"2023-03-12 02:00:00",
137+
"America/Los_Angeles",
138+
"2023-03-12 03:00:00",
139+
"2023-03-12 01:59:59",
140+
), # utc-8 -> utc-7
141+
(
142+
"2023-03-26 01:00:00",
143+
"Europe/London",
144+
"2023-03-26 02:00:00",
145+
"2023-03-26 00:59:59",
146+
), # utc+0 -> utc+1
147+
(
148+
"2023-03-26 00:00:00",
149+
"Atlantic/Azores",
150+
"2023-03-26 01:00:00",
151+
"2023-03-25 23:59:59",
152+
), # utc-1 -> utc+0
153+
],
154+
)
155+
def test_tz_localize_nonexistent_shift(
156+
self, stamp, tz, forward_expected, backward_expected
157+
):
158+
ts = Timestamp(stamp)
159+
forward_ts = ts.tz_localize(tz, nonexistent="shift_forward")
160+
assert forward_ts == Timestamp(forward_expected, tz=tz)
161+
backward_ts = ts.tz_localize(tz, nonexistent="shift_backward")
162+
assert backward_ts == Timestamp(backward_expected, tz=tz)
163+
126164
def test_tz_localize_ambiguous_raise(self):
127165
# GH#13057
128166
ts = Timestamp("2015-11-1 01:00")

0 commit comments

Comments
 (0)