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