@@ -212,51 +212,54 @@ def test_to_datetime_format_YYYYMMDD_with_none(self, input_s):
212212 [
213213 # NaN before strings with invalid date values
214214 [
215- Series ( ["19801222" , np .nan , "20010012" , "10019999" ]) ,
216- Series ( [Timestamp ("19801222" ), np .nan , np .nan , np .nan ]) ,
215+ ["19801222" , np .nan , "20010012" , "10019999" ],
216+ [Timestamp ("19801222" ), np .nan , np .nan , np .nan ],
217217 ],
218218 # NaN after strings with invalid date values
219219 [
220- Series ( ["19801222" , "20010012" , "10019999" , np .nan ]) ,
221- Series ( [Timestamp ("19801222" ), np .nan , np .nan , np .nan ]) ,
220+ ["19801222" , "20010012" , "10019999" , np .nan ],
221+ [Timestamp ("19801222" ), np .nan , np .nan , np .nan ],
222222 ],
223223 # NaN before integers with invalid date values
224224 [
225- Series ( [20190813 , np .nan , 20010012 , 20019999 ]) ,
226- Series ( [Timestamp ("20190813" ), np .nan , np .nan , np .nan ]) ,
225+ [20190813 , np .nan , 20010012 , 20019999 ],
226+ [Timestamp ("20190813" ), np .nan , np .nan , np .nan ],
227227 ],
228228 # NaN after integers with invalid date values
229229 [
230- Series ( [20190813 , 20010012 , np .nan , 20019999 ]) ,
231- Series ( [Timestamp ("20190813" ), np .nan , np .nan , np .nan ]) ,
230+ [20190813 , 20010012 , np .nan , 20019999 ],
231+ [Timestamp ("20190813" ), np .nan , np .nan , np .nan ],
232232 ],
233233 ],
234234 )
235235 def test_to_datetime_format_YYYYMMDD_overflow (self , input_s , expected ):
236236 # GH 25512
237237 # format='%Y%m%d', errors='coerce'
238+ input_s = Series (input_s )
238239 result = to_datetime (input_s , format = "%Y%m%d" , errors = "coerce" )
240+ expected = Series (expected )
239241 tm .assert_series_equal (result , expected )
240242
241243 @pytest .mark .parametrize (
242244 "data, format, expected" ,
243245 [
244- ([pd .NA ], "%Y%m%d%H%M%S" , DatetimeIndex ( ["NaT" ]) ),
245- ([pd .NA ], None , DatetimeIndex ( ["NaT" ]) ),
246+ ([pd .NA ], "%Y%m%d%H%M%S" , ["NaT" ]),
247+ ([pd .NA ], None , ["NaT" ]),
246248 (
247249 [pd .NA , "20210202202020" ],
248250 "%Y%m%d%H%M%S" ,
249- DatetimeIndex ( ["NaT" , "2021-02-02 20:20:20" ]) ,
251+ ["NaT" , "2021-02-02 20:20:20" ],
250252 ),
251- (["201010" , pd .NA ], "%y%m%d" , DatetimeIndex ( ["2020-10-10" , "NaT" ]) ),
252- (["201010" , pd .NA ], "%d%m%y" , DatetimeIndex ( ["2010-10-20" , "NaT" ]) ),
253- ([None , np .nan , pd .NA ], None , DatetimeIndex ( ["NaT" , "NaT" , "NaT" ]) ),
254- ([None , np .nan , pd .NA ], "%Y%m%d" , DatetimeIndex ( ["NaT" , "NaT" , "NaT" ]) ),
253+ (["201010" , pd .NA ], "%y%m%d" , ["2020-10-10" , "NaT" ]),
254+ (["201010" , pd .NA ], "%d%m%y" , ["2010-10-20" , "NaT" ]),
255+ ([None , np .nan , pd .NA ], None , ["NaT" , "NaT" , "NaT" ]),
256+ ([None , np .nan , pd .NA ], "%Y%m%d" , ["NaT" , "NaT" , "NaT" ]),
255257 ],
256258 )
257259 def test_to_datetime_with_NA (self , data , format , expected ):
258260 # GH#42957
259261 result = to_datetime (data , format = format )
262+ expected = DatetimeIndex (expected )
260263 tm .assert_index_equal (result , expected )
261264
262265 def test_to_datetime_with_NA_with_warning (self ):
@@ -422,12 +425,12 @@ def test_parse_nanoseconds_with_formula(self, cache, arg):
422425 @pytest .mark .parametrize (
423426 "value,fmt,expected" ,
424427 [
425- ["2009324" , "%Y%W%w" , Timestamp ( "2009-08-13" ) ],
426- ["2013020" , "%Y%U%w" , Timestamp ( "2013-01-13" ) ],
428+ ["2009324" , "%Y%W%w" , "2009-08-13" ],
429+ ["2013020" , "%Y%U%w" , "2013-01-13" ],
427430 ],
428431 )
429432 def test_to_datetime_format_weeks (self , value , fmt , expected , cache ):
430- assert to_datetime (value , format = fmt , cache = cache ) == expected
433+ assert to_datetime (value , format = fmt , cache = cache ) == Timestamp ( expected )
431434
432435 @pytest .mark .parametrize (
433436 "fmt,dates,expected_dates" ,
@@ -715,24 +718,20 @@ def test_to_datetime_mixed_datetime_and_string_with_format_mixed_offsets_utc_fal
715718 [
716719 pytest .param (
717720 "%Y-%m-%d %H:%M:%S%z" ,
718- Index (
719- [
720- Timestamp ("2000-01-01 09:00:00+0100" , tz = "UTC+01:00" ),
721- Timestamp ("2000-01-02 02:00:00+0200" , tz = "UTC+02:00" ),
722- NaT ,
723- ]
724- ),
721+ [
722+ Timestamp ("2000-01-01 09:00:00+0100" , tz = "UTC+01:00" ),
723+ Timestamp ("2000-01-02 02:00:00+0200" , tz = "UTC+02:00" ),
724+ NaT ,
725+ ],
725726 id = "ISO8601, non-UTC" ,
726727 ),
727728 pytest .param (
728729 "%Y-%d-%m %H:%M:%S%z" ,
729- Index (
730- [
731- Timestamp ("2000-01-01 09:00:00+0100" , tz = "UTC+01:00" ),
732- Timestamp ("2000-02-01 02:00:00+0200" , tz = "UTC+02:00" ),
733- NaT ,
734- ]
735- ),
730+ [
731+ Timestamp ("2000-01-01 09:00:00+0100" , tz = "UTC+01:00" ),
732+ Timestamp ("2000-02-01 02:00:00+0200" , tz = "UTC+02:00" ),
733+ NaT ,
734+ ],
736735 id = "non-ISO8601, non-UTC" ,
737736 ),
738737 ],
@@ -747,6 +746,7 @@ def test_to_datetime_mixed_offsets_with_none_tz(self, fmt, expected):
747746 format = fmt ,
748747 utc = False ,
749748 )
749+ expected = Index (expected )
750750 tm .assert_index_equal (result , expected )
751751
752752 @pytest .mark .parametrize (
0 commit comments