diff --git a/pandas/core/construction.py b/pandas/core/construction.py index 3dc7acc6cf0b5..5f67db0244a4a 100644 --- a/pandas/core/construction.py +++ b/pandas/core/construction.py @@ -481,6 +481,7 @@ def sanitize_array( return subarr elif isinstance(data, (list, tuple, abc.Set, abc.ValuesView)) and len(data) > 0: + # TODO: deque, array.array if isinstance(data, set): # Raise only for unordered sets, e.g., not for dict_keys raise TypeError("Set type is unordered") diff --git a/pandas/core/dtypes/cast.py b/pandas/core/dtypes/cast.py index 034fd927a8017..1725a8de53e67 100644 --- a/pandas/core/dtypes/cast.py +++ b/pandas/core/dtypes/cast.py @@ -1339,6 +1339,9 @@ def maybe_cast_to_datetime(value, dtype: Optional[DtypeObj]): from pandas.core.tools.datetimes import to_datetime from pandas.core.tools.timedeltas import to_timedelta + if not is_list_like(value): + raise TypeError("value must be listlike") + if dtype is not None: is_datetime64 = is_datetime64_dtype(dtype) is_datetime64tz = is_datetime64tz_dtype(dtype) @@ -1367,13 +1370,6 @@ def maybe_cast_to_datetime(value, dtype: Optional[DtypeObj]): raise TypeError( f"cannot convert datetimelike to dtype [{dtype}]" ) - elif is_datetime64tz: - - # our NaT doesn't support tz's - # this will coerce to DatetimeIndex with - # a matching dtype below - if is_scalar(value) and isna(value): - value = [value] elif is_timedelta64 and not is_dtype_equal(dtype, TD64NS_DTYPE): @@ -1386,9 +1382,7 @@ def maybe_cast_to_datetime(value, dtype: Optional[DtypeObj]): else: raise TypeError(f"cannot convert timedeltalike to dtype [{dtype}]") - if is_scalar(value): - value = maybe_unbox_datetimelike(value, dtype) - elif not is_sparse(value): + if not is_sparse(value): value = np.array(value, copy=False) # have a scalar array-like (e.g. NaT)