@@ -68,22 +68,39 @@ def test_series_tz_localize_matching_index(self):
6868 ["foo" , "invalid" ],
6969 ],
7070 )
71- def test_series_tz_localize_nonexistent (self , tz , method , exp ):
71+ def test_tz_localize_nonexistent (self , tz , method , exp ):
7272 # GH 8917
7373 n = 60
7474 dti = date_range (start = "2015-03-29 02:00:00" , periods = n , freq = "min" )
75- s = Series (1 , dti )
75+ ser = Series (1 , index = dti )
76+ df = ser .to_frame ()
77+
7678 if method == "raise" :
79+
80+ with tm .external_error_raised (pytz .NonExistentTimeError ):
81+ dti .tz_localize (tz , nonexistent = method )
82+ with tm .external_error_raised (pytz .NonExistentTimeError ):
83+ ser .tz_localize (tz , nonexistent = method )
7784 with tm .external_error_raised (pytz .NonExistentTimeError ):
78- s .tz_localize (tz , nonexistent = method )
85+ df .tz_localize (tz , nonexistent = method )
86+
7987 elif exp == "invalid" :
8088 with pytest .raises (ValueError , match = "argument must be one of" ):
8189 dti .tz_localize (tz , nonexistent = method )
90+ with pytest .raises (ValueError , match = "argument must be one of" ):
91+ ser .tz_localize (tz , nonexistent = method )
92+ with pytest .raises (ValueError , match = "argument must be one of" ):
93+ df .tz_localize (tz , nonexistent = method )
94+
8295 else :
83- result = s .tz_localize (tz , nonexistent = method )
96+ result = ser .tz_localize (tz , nonexistent = method )
8497 expected = Series (1 , index = DatetimeIndex ([exp ] * n , tz = tz ))
8598 tm .assert_series_equal (result , expected )
8699
100+ result = df .tz_localize (tz , nonexistent = method )
101+ expected = expected .to_frame ()
102+ tm .assert_frame_equal (result , expected )
103+
87104 @pytest .mark .parametrize ("tzstr" , ["US/Eastern" , "dateutil/US/Eastern" ])
88105 def test_series_tz_localize_empty (self , tzstr ):
89106 # GH#2248
0 commit comments