@@ -58,7 +58,6 @@ def test_series_tz_localize_matching_index(self):
5858 )
5959 tm .assert_series_equal (result , expected )
6060
61- @pytest .mark .parametrize ("tz" , ["Europe/Warsaw" , "dateutil/Europe/Warsaw" ])
6261 @pytest .mark .parametrize (
6362 "method, exp" ,
6463 [
@@ -68,8 +67,9 @@ def test_series_tz_localize_matching_index(self):
6867 ["foo" , "invalid" ],
6968 ],
7069 )
71- def test_tz_localize_nonexistent (self , tz , method , exp ):
70+ def test_tz_localize_nonexistent (self , warsaw , method , exp ):
7271 # GH 8917
72+ tz = warsaw
7373 n = 60
7474 dti = date_range (start = "2015-03-29 02:00:00" , periods = n , freq = "min" )
7575 ser = Series (1 , index = dti )
@@ -85,13 +85,27 @@ def test_tz_localize_nonexistent(self, tz, method, exp):
8585 df .tz_localize (tz , nonexistent = method )
8686
8787 elif exp == "invalid" :
88- with pytest .raises (ValueError , match = "argument must be one of" ):
88+ msg = (
89+ "The nonexistent argument must be one of "
90+ "'raise', 'NaT', 'shift_forward', 'shift_backward' "
91+ "or a timedelta object"
92+ )
93+ with pytest .raises (ValueError , match = msg ):
8994 dti .tz_localize (tz , nonexistent = method )
90- with pytest .raises (ValueError , match = "argument must be one of" ):
95+ with pytest .raises (ValueError , match = msg ):
9196 ser .tz_localize (tz , nonexistent = method )
92- with pytest .raises (ValueError , match = "argument must be one of" ):
97+ with pytest .raises (ValueError , match = msg ):
9398 df .tz_localize (tz , nonexistent = method )
9499
100+ elif method == "shift_forward" and type (tz ).__name__ == "ZoneInfo" :
101+ msg = "nonexistent shifting is not implemented with ZoneInfo tzinfos"
102+ with pytest .raises (NotImplementedError , match = msg ):
103+ ser .tz_localize (tz , nonexistent = method )
104+ with pytest .raises (NotImplementedError , match = msg ):
105+ df .tz_localize (tz , nonexistent = method )
106+ with pytest .raises (NotImplementedError , match = msg ):
107+ dti .tz_localize (tz , nonexistent = method )
108+
95109 else :
96110 result = ser .tz_localize (tz , nonexistent = method )
97111 expected = Series (1 , index = DatetimeIndex ([exp ] * n , tz = tz ))
@@ -101,6 +115,9 @@ def test_tz_localize_nonexistent(self, tz, method, exp):
101115 expected = expected .to_frame ()
102116 tm .assert_frame_equal (result , expected )
103117
118+ res_index = dti .tz_localize (tz , nonexistent = method )
119+ tm .assert_index_equal (res_index , expected .index )
120+
104121 @pytest .mark .parametrize ("tzstr" , ["US/Eastern" , "dateutil/US/Eastern" ])
105122 def test_series_tz_localize_empty (self , tzstr ):
106123 # GH#2248
0 commit comments