Skip to content

Commit 0ec95f8

Browse files
committed
TST: add test for date_range normalize handling DST nonexistent/ambiguous times (GH#62602)
Add a test in `pandas/tests/arrays/test_datetimes.py` to ensure that `pd.date_range` with `normalize=True` correctly handles DST transitions when both `nonexistent` and `ambiguous` parameters are specified.
1 parent 386f4dc commit 0ec95f8

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

pandas/tests/arrays/test_datetimes.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -832,6 +832,28 @@ def test_date_range_uppercase_frequency_raises(self, freq):
832832
with pytest.raises(ValueError, match=msg):
833833
pd.date_range("1/1/2000", periods=4, freq=freq)
834834

835+
def test_date_range_normalize_nonexistent_ambiguous_dst(self):
836+
# GH#62602: Ensure normalize works with nonexistent/ambiguous times (DST)
837+
tz = "Africa/Cairo"
838+
start = pd.Timestamp("2024-04-26 01:00:00", tz=tz)
839+
end = pd.Timestamp("2024-04-27 00:00:00", tz=tz)
840+
841+
result = pd.date_range(
842+
start=start,
843+
end=end,
844+
freq="D",
845+
tz=tz,
846+
nonexistent="shift_forward",
847+
ambiguous=True,
848+
normalize=True,
849+
)
850+
851+
expected = pd.to_datetime(
852+
["2024-04-26 01:00:00", "2024-04-27 00:00:00"], unit="ns"
853+
).tz_localize(tz)
854+
855+
tm.assert_index_equal(result, expected)
856+
835857

836858
def test_factorize_sort_without_freq():
837859
dta = DatetimeArray._from_sequence([0, 2, 1], dtype="M8[ns]")

0 commit comments

Comments
 (0)