@@ -497,26 +497,20 @@ def _to_datetime_with_format(
497
497
return _box_as_indexlike (result , utc = utc , name = name )
498
498
499
499
# fallback
500
- if result is None :
501
- res = _array_strptime_with_fallback (
502
- arg , name , tz , fmt , exact , errors , infer_datetime_format
503
- )
504
- if res is not None :
505
- return res
500
+ res = _array_strptime_with_fallback (
501
+ arg , name , tz , fmt , exact , errors , infer_datetime_format
502
+ )
503
+ return res
506
504
507
- except ValueError as e :
505
+ except ValueError as err :
508
506
# Fallback to try to convert datetime objects if timezone-aware
509
507
# datetime objects are found without passing `utc=True`
510
508
try :
511
509
values , tz = conversion .datetime_to_datetime64 (arg )
512
510
dta = DatetimeArray (values , dtype = tz_to_dtype (tz ))
513
511
return DatetimeIndex ._simple_new (dta , name = name )
514
512
except (ValueError , TypeError ):
515
- raise e
516
-
517
- # error: Incompatible return value type (got "Optional[ndarray]", expected
518
- # "Optional[Index]")
519
- return result # type: ignore[return-value]
513
+ raise err
520
514
521
515
522
516
def _to_datetime_with_unit (arg , unit , name , tz , errors : str ) -> Index :
0 commit comments