Skip to content

Commit 8e4fe37

Browse files
authored
CLN: unnecessary checks (#38467)
1 parent 7dccda5 commit 8e4fe37

File tree

3 files changed

+7
-12
lines changed

3 files changed

+7
-12
lines changed

pandas/core/arrays/categorical.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ def __init__(
321321
if is_categorical_dtype(values):
322322
if dtype.categories is None:
323323
dtype = CategoricalDtype(values.categories, dtype.ordered)
324-
elif not isinstance(values, (ABCIndex, ABCSeries)):
324+
elif not isinstance(values, (ABCIndex, ABCSeries, ExtensionArray)):
325325
# sanitize_array coerces np.nan to a string under certain versions
326326
# of numpy
327327
values = maybe_infer_to_datetimelike(values, convert_dates=True)

pandas/core/dtypes/cast.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,8 @@
8080
)
8181
from pandas.core.dtypes.generic import (
8282
ABCDataFrame,
83-
ABCDatetimeArray,
84-
ABCDatetimeIndex,
8583
ABCExtensionArray,
86-
ABCPeriodArray,
87-
ABCPeriodIndex,
84+
ABCIndex,
8885
ABCSeries,
8986
)
9087
from pandas.core.dtypes.inference import is_list_like
@@ -1252,11 +1249,9 @@ def maybe_infer_to_datetimelike(
12521249
leave inferred dtype 'date' alone
12531250
12541251
"""
1255-
# TODO: why not timedelta?
1256-
if isinstance(
1257-
value, (ABCDatetimeIndex, ABCPeriodIndex, ABCDatetimeArray, ABCPeriodArray)
1258-
):
1259-
return value
1252+
if isinstance(value, (ABCIndex, ABCExtensionArray)):
1253+
if not is_object_dtype(value.dtype):
1254+
raise ValueError("array-like value must be object-dtype")
12601255

12611256
v = value
12621257

@@ -1431,7 +1426,7 @@ def maybe_cast_to_datetime(value, dtype: Optional[DtypeObj]):
14311426
value = to_timedelta(value, errors="raise")._values
14321427
except OutOfBoundsDatetime:
14331428
raise
1434-
except (AttributeError, ValueError, TypeError):
1429+
except (ValueError, TypeError):
14351430
pass
14361431

14371432
# coerce datetimelike to object

pandas/core/internals/construction.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ def init_ndarray(values, index, columns, dtype: Optional[DtypeObj], copy: bool):
212212
# if we don't have a dtype specified, then try to convert objects
213213
# on the entire block; this is to convert if we have datetimelike's
214214
# embedded in an object type
215-
if dtype is None and is_object_dtype(values):
215+
if dtype is None and is_object_dtype(values.dtype):
216216

217217
if values.ndim == 2 and values.shape[0] != 1:
218218
# transpose and separate blocks

0 commit comments

Comments
 (0)