@@ -495,7 +495,7 @@ def maybe_casted_values(
495
495
Parameters
496
496
----------
497
497
index : Index
498
- codes : sequence of integers (optional)
498
+ codes : np.ndarray[intp] or None, default None
499
499
500
500
Returns
501
501
-------
@@ -1330,7 +1330,7 @@ def maybe_infer_to_datetimelike(
1330
1330
return value
1331
1331
1332
1332
shape = v .shape
1333
- if not v .ndim = = 1 :
1333
+ if v .ndim ! = 1 :
1334
1334
v = v .ravel ()
1335
1335
1336
1336
if not len (v ):
@@ -1400,7 +1400,7 @@ def try_timedelta(v):
1400
1400
return value
1401
1401
1402
1402
1403
- def maybe_cast_to_datetime (value , dtype : DtypeObj , errors : str = "raise" ):
1403
+ def maybe_cast_to_datetime (value , dtype : Optional [ DtypeObj ] ):
1404
1404
"""
1405
1405
try to cast the array/value to a datetimelike dtype, converting float
1406
1406
nan to iNaT
@@ -1469,7 +1469,7 @@ def maybe_cast_to_datetime(value, dtype: DtypeObj, errors: str = "raise"):
1469
1469
elif np .prod (value .shape ) or not is_dtype_equal (value .dtype , dtype ):
1470
1470
try :
1471
1471
if is_datetime64 :
1472
- value = to_datetime (value , errors = errors )
1472
+ value = to_datetime (value , errors = "raise" )
1473
1473
# GH 25843: Remove tz information since the dtype
1474
1474
# didn't specify one
1475
1475
if value .tz is not None :
@@ -1481,7 +1481,7 @@ def maybe_cast_to_datetime(value, dtype: DtypeObj, errors: str = "raise"):
1481
1481
# datetime64tz is assumed to be naive which should
1482
1482
# be localized to the timezone.
1483
1483
is_dt_string = is_string_dtype (value .dtype )
1484
- value = to_datetime (value , errors = errors ).array
1484
+ value = to_datetime (value , errors = "raise" ).array
1485
1485
if is_dt_string :
1486
1486
# Strings here are naive, so directly localize
1487
1487
value = value .tz_localize (dtype .tz )
@@ -1490,7 +1490,7 @@ def maybe_cast_to_datetime(value, dtype: DtypeObj, errors: str = "raise"):
1490
1490
# so localize and convert
1491
1491
value = value .tz_localize ("UTC" ).tz_convert (dtype .tz )
1492
1492
elif is_timedelta64 :
1493
- value = to_timedelta (value , errors = errors )._values
1493
+ value = to_timedelta (value , errors = "raise" )._values
1494
1494
except OutOfBoundsDatetime :
1495
1495
raise
1496
1496
except (AttributeError , ValueError , TypeError ):
@@ -1522,7 +1522,7 @@ def maybe_cast_to_datetime(value, dtype: DtypeObj, errors: str = "raise"):
1522
1522
value = conversion .ensure_datetime64ns (value )
1523
1523
1524
1524
elif dtype .kind == "m" and dtype != TD64NS_DTYPE :
1525
- value = to_timedelta (value )
1525
+ value = conversion . ensure_timedelta64ns (value )
1526
1526
1527
1527
# only do this if we have an array and the dtype of the array is not
1528
1528
# setup already we are not an integer/object, so don't bother with this
@@ -1659,7 +1659,7 @@ def construct_1d_arraylike_from_scalar(
1659
1659
# GH36541: can't fill array directly with pd.NaT
1660
1660
# > np.empty(10, dtype="datetime64[64]").fill(pd.NaT)
1661
1661
# ValueError: cannot convert float NaN to integer
1662
- value = np . datetime64 ("NaT" )
1662
+ value = dtype . type ("NaT" , "ns " )
1663
1663
1664
1664
subarr = np .empty (length , dtype = dtype )
1665
1665
subarr .fill (value )
0 commit comments