@@ -252,9 +252,7 @@ def _convert_and_box_cache(
252252 from pandas import Series
253253
254254 result = Series (arg ).map (cache_array )
255- # error: Argument 1 to "_box_as_indexlike" has incompatible type "Series"; expected
256- # "Union[ExtensionArray, ndarray]"
257- return _box_as_indexlike (result , utc = None , name = name ) # type: ignore[arg-type]
255+ return _box_as_indexlike (result ._values , utc = None , name = name )
258256
259257
260258def _return_parsed_timezone_results (result : np .ndarray , timezones , tz , name ) -> Index :
@@ -368,13 +366,11 @@ def _convert_listlike_datetimes(
368366 arg , _ = maybe_convert_dtype (arg , copy = False )
369367 except TypeError :
370368 if errors == "coerce" :
371- result = np .array (["NaT" ], dtype = "datetime64[ns]" ).repeat (len (arg ))
372- return DatetimeIndex (result , name = name )
369+ npvalues = np .array (["NaT" ], dtype = "datetime64[ns]" ).repeat (len (arg ))
370+ return DatetimeIndex (npvalues , name = name )
373371 elif errors == "ignore" :
374- # error: Incompatible types in assignment (expression has type
375- # "Index", variable has type "ExtensionArray")
376- result = Index (arg , name = name ) # type: ignore[assignment]
377- return result
372+ idx = Index (arg , name = name )
373+ return idx
378374 raise
379375
380376 arg = ensure_object (arg )
@@ -393,37 +389,30 @@ def _convert_listlike_datetimes(
393389 require_iso8601 = not infer_datetime_format
394390 format = None
395391
396- # error: Incompatible types in assignment (expression has type "None", variable has
397- # type "ExtensionArray")
398- result = None # type: ignore[assignment]
399-
400392 if format is not None :
401- # error: Incompatible types in assignment (expression has type
402- # "Optional[Index]", variable has type "ndarray")
403- result = _to_datetime_with_format ( # type: ignore[assignment]
393+ res = _to_datetime_with_format (
404394 arg , orig_arg , name , tz , format , exact , errors , infer_datetime_format
405395 )
406- if result is not None :
407- return result
408-
409- if result is None :
410- assert format is None or infer_datetime_format
411- utc = tz == "utc"
412- result , tz_parsed = objects_to_datetime64ns (
413- arg ,
414- dayfirst = dayfirst ,
415- yearfirst = yearfirst ,
416- utc = utc ,
417- errors = errors ,
418- require_iso8601 = require_iso8601 ,
419- allow_object = True ,
420- )
396+ if res is not None :
397+ return res
421398
422- if tz_parsed is not None :
423- # We can take a shortcut since the datetime64 numpy array
424- # is in UTC
425- dta = DatetimeArray (result , dtype = tz_to_dtype (tz_parsed ))
426- return DatetimeIndex ._simple_new (dta , name = name )
399+ assert format is None or infer_datetime_format
400+ utc = tz == "utc"
401+ result , tz_parsed = objects_to_datetime64ns (
402+ arg ,
403+ dayfirst = dayfirst ,
404+ yearfirst = yearfirst ,
405+ utc = utc ,
406+ errors = errors ,
407+ require_iso8601 = require_iso8601 ,
408+ allow_object = True ,
409+ )
410+
411+ if tz_parsed is not None :
412+ # We can take a shortcut since the datetime64 numpy array
413+ # is in UTC
414+ dta = DatetimeArray (result , dtype = tz_to_dtype (tz_parsed ))
415+ return DatetimeIndex ._simple_new (dta , name = name )
427416
428417 utc = tz == "utc"
429418 return _box_as_indexlike (result , utc = utc , name = name )
@@ -509,13 +498,11 @@ def _to_datetime_with_format(
509498
510499 # fallback
511500 if result is None :
512- # error: Incompatible types in assignment (expression has type
513- # "Optional[Index]", variable has type "Optional[ndarray]")
514- result = _array_strptime_with_fallback ( # type: ignore[assignment]
501+ res = _array_strptime_with_fallback (
515502 arg , name , tz , fmt , exact , errors , infer_datetime_format
516503 )
517- if result is not None :
518- return result
504+ if res is not None :
505+ return res
519506
520507 except ValueError as e :
521508 # Fallback to try to convert datetime objects if timezone-aware
0 commit comments