@@ -252,9 +252,7 @@ def _convert_and_box_cache(
252
252
from pandas import Series
253
253
254
254
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 )
258
256
259
257
260
258
def _return_parsed_timezone_results (result : np .ndarray , timezones , tz , name ) -> Index :
@@ -368,13 +366,11 @@ def _convert_listlike_datetimes(
368
366
arg , _ = maybe_convert_dtype (arg , copy = False )
369
367
except TypeError :
370
368
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 )
373
371
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
378
374
raise
379
375
380
376
arg = ensure_object (arg )
@@ -393,37 +389,30 @@ def _convert_listlike_datetimes(
393
389
require_iso8601 = not infer_datetime_format
394
390
format = None
395
391
396
- # error: Incompatible types in assignment (expression has type "None", variable has
397
- # type "ExtensionArray")
398
- result = None # type: ignore[assignment]
399
-
400
392
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 (
404
394
arg , orig_arg , name , tz , format , exact , errors , infer_datetime_format
405
395
)
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
421
398
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 )
427
416
428
417
utc = tz == "utc"
429
418
return _box_as_indexlike (result , utc = utc , name = name )
@@ -509,13 +498,11 @@ def _to_datetime_with_format(
509
498
510
499
# fallback
511
500
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 (
515
502
arg , name , tz , fmt , exact , errors , infer_datetime_format
516
503
)
517
- if result is not None :
518
- return result
504
+ if res is not None :
505
+ return res
519
506
520
507
except ValueError as e :
521
508
# Fallback to try to convert datetime objects if timezone-aware
0 commit comments