Skip to content

Commit 0cdb37c

Browse files
authored
CI: parametrize and xfail (#55804)
1 parent 4e5576d commit 0cdb37c

File tree

1 file changed

+24
-24
lines changed

1 file changed

+24
-24
lines changed

pandas/tests/indexes/datetimes/test_constructors.py

+24-24
Original file line numberDiff line numberDiff line change
@@ -1013,35 +1013,35 @@ def test_dti_convert_datetime_list(self, tzstr):
10131013
dr2 = DatetimeIndex(list(dr), name="foo", freq="D")
10141014
tm.assert_index_equal(dr, dr2)
10151015

1016-
def test_dti_ambiguous_matches_timestamp(self):
1016+
@pytest.mark.parametrize(
1017+
"tz",
1018+
[
1019+
pytz.timezone("US/Eastern"),
1020+
gettz("US/Eastern"),
1021+
],
1022+
)
1023+
@pytest.mark.parametrize("use_str", [True, False])
1024+
@pytest.mark.parametrize("box_cls", [Timestamp, DatetimeIndex])
1025+
def test_dti_ambiguous_matches_timestamp(self, tz, use_str, box_cls, request):
10171026
# GH#47471 check that we get the same raising behavior in the DTI
10181027
# constructor and Timestamp constructor
10191028
dtstr = "2013-11-03 01:59:59.999999"
1020-
dtobj = Timestamp(dtstr).to_pydatetime()
1021-
1022-
tz = pytz.timezone("US/Eastern")
1023-
with pytest.raises(pytz.AmbiguousTimeError, match=dtstr):
1024-
Timestamp(dtstr, tz=tz)
1025-
with pytest.raises(pytz.AmbiguousTimeError, match=dtstr):
1026-
Timestamp(dtobj, tz=tz)
1027-
with pytest.raises(pytz.AmbiguousTimeError, match=dtstr):
1028-
DatetimeIndex([dtstr], tz=tz)
1029-
with pytest.raises(pytz.AmbiguousTimeError, match=dtstr):
1030-
DatetimeIndex([dtobj], tz=tz)
1029+
item = dtstr
1030+
if not use_str:
1031+
item = Timestamp(dtstr).to_pydatetime()
1032+
if box_cls is not Timestamp:
1033+
item = [item]
1034+
1035+
if not use_str and isinstance(tz, dateutil.tz.tzfile):
1036+
# FIXME: The Timestamp constructor here behaves differently than all
1037+
# the other cases bc with dateutil/zoneinfo tzinfos we implicitly
1038+
# get fold=0. Having this raise is not important, but having the
1039+
# behavior be consistent across cases is.
1040+
mark = pytest.mark.xfail(reason="We implicitly get fold=0.")
1041+
request.applymarker(mark)
10311042

1032-
tz2 = gettz("US/Eastern")
1033-
with pytest.raises(pytz.AmbiguousTimeError, match=dtstr):
1034-
Timestamp(dtstr, tz=tz2)
1035-
# FIXME: The Timestamp constructor here behaves differently than all
1036-
# the other cases bc with dateutil/zoneinfo tzinfos we implicitly
1037-
# get fold=0. Having this raise is not important, but having the
1038-
# behavior be consistent across cases is.
1039-
# with pytest.raises(pytz.AmbiguousTimeError, match=dtstr):
1040-
# Timestamp(dtobj, tz=tz2)
1041-
with pytest.raises(pytz.AmbiguousTimeError, match=dtstr):
1042-
DatetimeIndex([dtstr], tz=tz2)
10431043
with pytest.raises(pytz.AmbiguousTimeError, match=dtstr):
1044-
DatetimeIndex([dtobj], tz=tz2)
1044+
box_cls(item, tz=tz)
10451045

10461046
@pytest.mark.parametrize("tz", [None, "UTC", "US/Pacific"])
10471047
def test_dti_constructor_with_non_nano_dtype(self, tz):

0 commit comments

Comments
 (0)