@@ -68,22 +68,39 @@ def test_series_tz_localize_matching_index(self):
68
68
["foo" , "invalid" ],
69
69
],
70
70
)
71
- def test_series_tz_localize_nonexistent (self , tz , method , exp ):
71
+ def test_tz_localize_nonexistent (self , tz , method , exp ):
72
72
# GH 8917
73
73
n = 60
74
74
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
+
76
78
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 )
77
84
with tm .external_error_raised (pytz .NonExistentTimeError ):
78
- s .tz_localize (tz , nonexistent = method )
85
+ df .tz_localize (tz , nonexistent = method )
86
+
79
87
elif exp == "invalid" :
80
88
with pytest .raises (ValueError , match = "argument must be one of" ):
81
89
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
+
82
95
else :
83
- result = s .tz_localize (tz , nonexistent = method )
96
+ result = ser .tz_localize (tz , nonexistent = method )
84
97
expected = Series (1 , index = DatetimeIndex ([exp ] * n , tz = tz ))
85
98
tm .assert_series_equal (result , expected )
86
99
100
+ result = df .tz_localize (tz , nonexistent = method )
101
+ expected = expected .to_frame ()
102
+ tm .assert_frame_equal (result , expected )
103
+
87
104
@pytest .mark .parametrize ("tzstr" , ["US/Eastern" , "dateutil/US/Eastern" ])
88
105
def test_series_tz_localize_empty (self , tzstr ):
89
106
# GH#2248
0 commit comments