Skip to content

Commit 935a8c0

Browse files
authored
sanitize_array raise_cast_failure default to True (#40012)
1 parent 8ceec8b commit 935a8c0

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

pandas/core/construction.py

+19-1
Original file line numberDiff line numberDiff line change
@@ -456,11 +456,29 @@ def sanitize_array(
456456
index: Optional[Index],
457457
dtype: Optional[DtypeObj] = None,
458458
copy: bool = False,
459-
raise_cast_failure: bool = False,
459+
raise_cast_failure: bool = True,
460460
) -> ArrayLike:
461461
"""
462462
Sanitize input data to an ndarray or ExtensionArray, copy if specified,
463463
coerce to the dtype if specified.
464+
465+
Parameters
466+
----------
467+
data : Any
468+
index : Index or None, default None
469+
dtype : np.dtype, ExtensionDtype, or None, default None
470+
copy : bool, default False
471+
raise_cast_failure : bool, default True
472+
473+
Returns
474+
-------
475+
np.ndarray or ExtensionArray
476+
477+
Notes
478+
-----
479+
raise_cast_failure=False is only intended to be True when called from the
480+
DataFrame constructor, as the dtype keyword there may be interpreted as only
481+
applying to a subset of columns, see GH#24435.
464482
"""
465483

466484
if isinstance(data, ma.MaskedArray):

pandas/core/internals/construction.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ def convert(v):
403403
return values
404404

405405

406-
def _homogenize(data, index, dtype: Optional[DtypeObj]):
406+
def _homogenize(data, index: Index, dtype: Optional[DtypeObj]):
407407
oindex = None
408408
homogenized = []
409409

pandas/core/series.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ def __init__(
395395
elif copy:
396396
data = data.copy()
397397
else:
398-
data = sanitize_array(data, index, dtype, copy, raise_cast_failure=True)
398+
data = sanitize_array(data, index, dtype, copy)
399399

400400
data = SingleBlockManager.from_array(data, index)
401401

0 commit comments

Comments
 (0)