Skip to content

CLN: unnecessary checks #38467

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pandas/core/arrays/categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ def __init__(
if is_categorical_dtype(values):
if dtype.categories is None:
dtype = CategoricalDtype(values.categories, dtype.ordered)
elif not isinstance(values, (ABCIndex, ABCSeries)):
elif not isinstance(values, (ABCIndex, ABCSeries, ExtensionArray)):
# sanitize_array coerces np.nan to a string under certain versions
# of numpy
values = maybe_infer_to_datetimelike(values, convert_dates=True)
Expand Down
15 changes: 5 additions & 10 deletions pandas/core/dtypes/cast.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,8 @@
)
from pandas.core.dtypes.generic import (
ABCDataFrame,
ABCDatetimeArray,
ABCDatetimeIndex,
ABCExtensionArray,
ABCPeriodArray,
ABCPeriodIndex,
ABCIndex,
ABCSeries,
)
from pandas.core.dtypes.inference import is_list_like
Expand Down Expand Up @@ -1252,11 +1249,9 @@ def maybe_infer_to_datetimelike(
leave inferred dtype 'date' alone

"""
# TODO: why not timedelta?
if isinstance(
value, (ABCDatetimeIndex, ABCPeriodIndex, ABCDatetimeArray, ABCPeriodArray)
):
return value
if isinstance(value, (ABCIndex, ABCExtensionArray)):
if not is_object_dtype(value.dtype):
raise ValueError("array-like value must be object-dtype")

v = value

Expand Down Expand Up @@ -1431,7 +1426,7 @@ def maybe_cast_to_datetime(value, dtype: Optional[DtypeObj]):
value = to_timedelta(value, errors="raise")._values
except OutOfBoundsDatetime:
raise
except (AttributeError, ValueError, TypeError):
except (ValueError, TypeError):
pass

# coerce datetimelike to object
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/internals/construction.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ def init_ndarray(values, index, columns, dtype: Optional[DtypeObj], copy: bool):
# if we don't have a dtype specified, then try to convert objects
# on the entire block; this is to convert if we have datetimelike's
# embedded in an object type
if dtype is None and is_object_dtype(values):
if dtype is None and is_object_dtype(values.dtype):

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