diff --git a/pandas/core/construction.py b/pandas/core/construction.py index 1172fd25de3e4..0c0084f2492d3 100644 --- a/pandas/core/construction.py +++ b/pandas/core/construction.py @@ -456,11 +456,29 @@ def sanitize_array( index: Optional[Index], dtype: Optional[DtypeObj] = None, copy: bool = False, - raise_cast_failure: bool = False, + raise_cast_failure: bool = True, ) -> ArrayLike: """ Sanitize input data to an ndarray or ExtensionArray, copy if specified, coerce to the dtype if specified. + + Parameters + ---------- + data : Any + index : Index or None, default None + dtype : np.dtype, ExtensionDtype, or None, default None + copy : bool, default False + raise_cast_failure : bool, default True + + Returns + ------- + np.ndarray or ExtensionArray + + Notes + ----- + raise_cast_failure=False is only intended to be True when called from the + DataFrame constructor, as the dtype keyword there may be interpreted as only + applying to a subset of columns, see GH#24435. """ if isinstance(data, ma.MaskedArray): diff --git a/pandas/core/internals/construction.py b/pandas/core/internals/construction.py index eb1a7a355f313..9903dab9976c4 100644 --- a/pandas/core/internals/construction.py +++ b/pandas/core/internals/construction.py @@ -403,7 +403,7 @@ def convert(v): return values -def _homogenize(data, index, dtype: Optional[DtypeObj]): +def _homogenize(data, index: Index, dtype: Optional[DtypeObj]): oindex = None homogenized = [] diff --git a/pandas/core/series.py b/pandas/core/series.py index 34e9464006b30..50a537aeb8623 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -395,7 +395,7 @@ def __init__( elif copy: data = data.copy() else: - data = sanitize_array(data, index, dtype, copy, raise_cast_failure=True) + data = sanitize_array(data, index, dtype, copy) data = SingleBlockManager.from_array(data, index)