Skip to content

Commit fedb49e

Browse files
committed
Add test for nontick offsets with ambiguous time error
1 parent d914467 commit fedb49e

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

pandas/tests/tseries/offsets/test_dst.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from datetime import timedelta
55

66
import pytest
7+
import pytz
78

89
from pandas._libs.tslibs import Timestamp
910
from pandas._libs.tslibs.offsets import (
@@ -15,6 +16,7 @@
1516
BYearEnd,
1617
CBMonthBegin,
1718
CBMonthEnd,
19+
CustomBusinessDay,
1820
DateOffset,
1921
Day,
2022
MonthBegin,
@@ -173,3 +175,48 @@ def test_all_offset_classes(self, tup):
173175
first = Timestamp(test_values[0], tz="US/Eastern") + offset()
174176
second = Timestamp(test_values[1], tz="US/Eastern")
175177
assert first == second
178+
179+
180+
@pytest.mark.parametrize(
181+
"original_dt, target_dt, offset, tz",
182+
[
183+
(
184+
Timestamp("1900-01-01"),
185+
Timestamp("1905-07-01"),
186+
MonthBegin(66),
187+
"Africa/Kinshasa",
188+
), # GH41906
189+
(
190+
Timestamp("2021-10-01 01:15"),
191+
Timestamp("2021-10-31 01:15"),
192+
MonthEnd(1),
193+
"Europe/London",
194+
),
195+
(
196+
Timestamp("2010-12-05 02:59"),
197+
Timestamp("2010-10-31 02:59"),
198+
SemiMonthEnd(-3),
199+
"Europe/Paris",
200+
),
201+
(
202+
Timestamp("2021-10-31 01:20"),
203+
Timestamp("2021-11-07 01:20"),
204+
CustomBusinessDay(2, weekmask="Sun Mon"),
205+
"US/Eastern",
206+
),
207+
(
208+
Timestamp("2020-04-03 01:30"),
209+
Timestamp("2020-11-01 01:30"),
210+
YearBegin(1, month=11),
211+
"America/Chicago",
212+
),
213+
],
214+
)
215+
def test_nontick_offset_with_ambiguous_time_error(original_dt, target_dt, offset, tz):
216+
# .apply for non-Tick offsets throws AmbiguousTimeError when the target dt
217+
# is dst-ambiguous
218+
localized_dt = original_dt.tz_localize(tz)
219+
220+
msg = f"Cannot infer dst time from {target_dt}, try using the 'ambiguous' argument"
221+
with pytest.raises(pytz.AmbiguousTimeError, match=msg):
222+
localized_dt + offset

0 commit comments

Comments
 (0)