@@ -1013,35 +1013,35 @@ def test_dti_convert_datetime_list(self, tzstr):
1013
1013
dr2 = DatetimeIndex (list (dr ), name = "foo" , freq = "D" )
1014
1014
tm .assert_index_equal (dr , dr2 )
1015
1015
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 ):
1017
1026
# GH#47471 check that we get the same raising behavior in the DTI
1018
1027
# constructor and Timestamp constructor
1019
1028
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 )
1031
1042
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 )
1043
1043
with pytest .raises (pytz .AmbiguousTimeError , match = dtstr ):
1044
- DatetimeIndex ([ dtobj ] , tz = tz2 )
1044
+ box_cls ( item , tz = tz )
1045
1045
1046
1046
@pytest .mark .parametrize ("tz" , [None , "UTC" , "US/Pacific" ])
1047
1047
def test_dti_constructor_with_non_nano_dtype (self , tz ):
0 commit comments