Skip to content

Commit 0711b7a

Browse files
authored
CLN: dtypes.cast (#38327)
1 parent d34bd0b commit 0711b7a

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

pandas/_libs/lib.pyx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1483,7 +1483,7 @@ def infer_dtype(value: object, skipna: bool = True) -> str:
14831483
return "mixed"
14841484

14851485

1486-
def infer_datetimelike_array(arr: object) -> object:
1486+
def infer_datetimelike_array(arr: ndarray[object]) -> str:
14871487
"""
14881488
Infer if we have a datetime or timedelta array.
14891489
- date: we have *only* date and maybe strings, nulls
@@ -1496,7 +1496,7 @@ def infer_datetimelike_array(arr: object) -> object:
14961496

14971497
Parameters
14981498
----------
1499-
arr : object array
1499+
arr : ndarray[object]
15001500

15011501
Returns
15021502
-------

pandas/core/dtypes/cast.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ def maybe_casted_values(
495495
Parameters
496496
----------
497497
index : Index
498-
codes : sequence of integers (optional)
498+
codes : np.ndarray[intp] or None, default None
499499
500500
Returns
501501
-------
@@ -1330,7 +1330,7 @@ def maybe_infer_to_datetimelike(
13301330
return value
13311331

13321332
shape = v.shape
1333-
if not v.ndim == 1:
1333+
if v.ndim != 1:
13341334
v = v.ravel()
13351335

13361336
if not len(v):
@@ -1400,7 +1400,7 @@ def try_timedelta(v):
14001400
return value
14011401

14021402

1403-
def maybe_cast_to_datetime(value, dtype: DtypeObj, errors: str = "raise"):
1403+
def maybe_cast_to_datetime(value, dtype: Optional[DtypeObj]):
14041404
"""
14051405
try to cast the array/value to a datetimelike dtype, converting float
14061406
nan to iNaT
@@ -1469,7 +1469,7 @@ def maybe_cast_to_datetime(value, dtype: DtypeObj, errors: str = "raise"):
14691469
elif np.prod(value.shape) or not is_dtype_equal(value.dtype, dtype):
14701470
try:
14711471
if is_datetime64:
1472-
value = to_datetime(value, errors=errors)
1472+
value = to_datetime(value, errors="raise")
14731473
# GH 25843: Remove tz information since the dtype
14741474
# didn't specify one
14751475
if value.tz is not None:
@@ -1481,7 +1481,7 @@ def maybe_cast_to_datetime(value, dtype: DtypeObj, errors: str = "raise"):
14811481
# datetime64tz is assumed to be naive which should
14821482
# be localized to the timezone.
14831483
is_dt_string = is_string_dtype(value.dtype)
1484-
value = to_datetime(value, errors=errors).array
1484+
value = to_datetime(value, errors="raise").array
14851485
if is_dt_string:
14861486
# Strings here are naive, so directly localize
14871487
value = value.tz_localize(dtype.tz)
@@ -1490,7 +1490,7 @@ def maybe_cast_to_datetime(value, dtype: DtypeObj, errors: str = "raise"):
14901490
# so localize and convert
14911491
value = value.tz_localize("UTC").tz_convert(dtype.tz)
14921492
elif is_timedelta64:
1493-
value = to_timedelta(value, errors=errors)._values
1493+
value = to_timedelta(value, errors="raise")._values
14941494
except OutOfBoundsDatetime:
14951495
raise
14961496
except (AttributeError, ValueError, TypeError):
@@ -1522,7 +1522,7 @@ def maybe_cast_to_datetime(value, dtype: DtypeObj, errors: str = "raise"):
15221522
value = conversion.ensure_datetime64ns(value)
15231523

15241524
elif dtype.kind == "m" and dtype != TD64NS_DTYPE:
1525-
value = to_timedelta(value)
1525+
value = conversion.ensure_timedelta64ns(value)
15261526

15271527
# only do this if we have an array and the dtype of the array is not
15281528
# setup already we are not an integer/object, so don't bother with this
@@ -1659,7 +1659,7 @@ def construct_1d_arraylike_from_scalar(
16591659
# GH36541: can't fill array directly with pd.NaT
16601660
# > np.empty(10, dtype="datetime64[64]").fill(pd.NaT)
16611661
# ValueError: cannot convert float NaN to integer
1662-
value = np.datetime64("NaT")
1662+
value = dtype.type("NaT", "ns")
16631663

16641664
subarr = np.empty(length, dtype=dtype)
16651665
subarr.fill(value)

pandas/core/internals/construction.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ def _list_of_series_to_arrays(
611611

612612

613613
def _list_of_dict_to_arrays(
614-
data: List,
614+
data: List[Dict],
615615
columns: Union[Index, List],
616616
coerce_float: bool = False,
617617
dtype: Optional[DtypeObj] = None,

0 commit comments

Comments
 (0)