pandas/core/construction.py
def _sanitize_str_dtypes(
    result: np.ndarray, data, dtype: Optional[DtypeObj], copy: bool
) -> np.ndarray:
    """
    Ensure we have a dtype that is supported by pandas.
    """

    # This is to prevent mixed-type Series getting all casted to
    # NumPy string type, e.g. NaN --> '-1#IND'.
    if issubclass(result.dtype.type, str):
        # GH#16605
        # If not empty convert the data to dtype
        # GH#19853: If data is a scalar, result has already the result
        if not lib.is_scalar(data):
            if not np.all(isna(data)):
                data = np.array(data, dtype=dtype, copy=False)
            result = np.array(data, dtype=object, copy=copy)
    return result

    Ensure we have a dtype that is supported by pandas.
    
Ensure we have a dtype that is supported by pandas.
Ensure we have a dtype that is supported by pandas .
def _sanitize_str_dtypes(
    result: np.ndarray, data, dtype: Optional[DtypeObj], copy: bool
) -> np.ndarray:
    if issubclass(result.dtype.type, str):
        if not lib.is_scalar(data):
            if not np.all(isna(data)):
                data = np.array(data, dtype=dtype, copy=False)
            result = np.array(data, dtype=object, copy=copy)
    return result
def _sanitize_str_dtypes ( result : np . ndarray , data , dtype : Optional [ DtypeObj ] , copy : bool ) -> np . ndarray : if issubclass ( result . dtype . type , str ) : if not lib . is_scalar ( data ) : if not np . all ( isna ( data ) ) : data = np . array ( data , dtype = dtype , copy = False ) result = np . array ( data , dtype = object , copy = copy ) return result
Ensure we have a dtype that is supported by pandas.
Ensure we have a dtype that is supported by pandas .
"""
    Ensure we have a dtype that is supported by pandas.
    """ # This is to prevent mixed-type Series getting all casted to # NumPy string type, e.g. NaN --> '-1#IND'. # GH#16605 # If not empty convert the data to dtype # GH#19853: If data is a scalar, result has already the result
result
np.ndarray
data
dtype
Optional[DtypeObj]
copy
bool