diff --git a/pandas/core/arrays/masked.py b/pandas/core/arrays/masked.py index b90ceb7c2074d..8c9b45bd452a0 100644 --- a/pandas/core/arrays/masked.py +++ b/pandas/core/arrays/masked.py @@ -75,7 +75,11 @@ from pandas.core.array_algos.quantile import quantile_with_mask from pandas.core.arraylike import OpsMixin from pandas.core.arrays.base import ExtensionArray -from pandas.core.construction import ensure_wrapped_if_datetimelike +from pandas.core.construction import ( + array as pd_array, + ensure_wrapped_if_datetimelike, + extract_array, +) from pandas.core.indexers import check_array_indexer from pandas.core.ops import invalid_comparison @@ -645,20 +649,8 @@ def _arith_method(self, other, op): and len(other) == len(self) ): # Try inferring masked dtype instead of casting to object - inferred_dtype = lib.infer_dtype(other, skipna=True) - if inferred_dtype == "integer": - from pandas.core.arrays import IntegerArray - - other = IntegerArray._from_sequence(other) - elif inferred_dtype in ["floating", "mixed-integer-float"]: - from pandas.core.arrays import FloatingArray - - other = FloatingArray._from_sequence(other) - - elif inferred_dtype in ["boolean"]: - from pandas.core.arrays import BooleanArray - - other = BooleanArray._from_sequence(other) + other = pd_array(other) + other = extract_array(other, extract_numpy=True) if isinstance(other, BaseMaskedArray): other, omask = other._data, other._mask diff --git a/pandas/core/dtypes/common.py b/pandas/core/dtypes/common.py index f27941331e7f9..2c426187c83e8 100644 --- a/pandas/core/dtypes/common.py +++ b/pandas/core/dtypes/common.py @@ -1654,9 +1654,8 @@ def is_all_strings(value: ArrayLike) -> bool: dtype = value.dtype if isinstance(dtype, np.dtype): - return ( - dtype == np.dtype("object") - and lib.infer_dtype(value, skipna=False) == "string" + return dtype == np.dtype("object") and lib.is_string_array( + np.asarray(value), skipna=False ) elif isinstance(dtype, CategoricalDtype): return dtype.categories.inferred_type == "string" diff --git a/pandas/core/internals/construction.py b/pandas/core/internals/construction.py index ca8dc1da1aae2..29e0bb11be4dc 100644 --- a/pandas/core/internals/construction.py +++ b/pandas/core/internals/construction.py @@ -27,8 +27,6 @@ ) from pandas.core.dtypes.common import ( is_1d_only_ea_dtype, - is_bool_dtype, - is_float_dtype, is_integer_dtype, is_list_like, is_named_tuple, @@ -44,14 +42,10 @@ algorithms, common as com, ) -from pandas.core.arrays import ( - BooleanArray, - ExtensionArray, - FloatingArray, - IntegerArray, -) +from pandas.core.arrays import ExtensionArray from pandas.core.arrays.string_ import StringDtype from pandas.core.construction import ( + array as pd_array, ensure_wrapped_if_datetimelike, extract_array, range_to_ndarray, @@ -1027,12 +1021,8 @@ def convert(arr): if dtype_backend != "numpy" and arr.dtype == np.dtype("O"): arr = StringDtype().construct_array_type()._from_sequence(arr) elif dtype_backend != "numpy" and isinstance(arr, np.ndarray): - if is_integer_dtype(arr.dtype): - arr = IntegerArray(arr, np.zeros(arr.shape, dtype=np.bool_)) - elif is_bool_dtype(arr.dtype): - arr = BooleanArray(arr, np.zeros(arr.shape, dtype=np.bool_)) - elif is_float_dtype(arr.dtype): - arr = FloatingArray(arr, np.isnan(arr)) + if arr.dtype.kind in "iufb": + arr = pd_array(arr, copy=False) elif isinstance(dtype, ExtensionDtype): # TODO: test(s) that get here diff --git a/pandas/io/parsers/base_parser.py b/pandas/io/parsers/base_parser.py index 315bfbee8572e..4c0cffffb423e 100644 --- a/pandas/io/parsers/base_parser.py +++ b/pandas/io/parsers/base_parser.py @@ -757,8 +757,7 @@ def _infer_types( result = BooleanArray(result, bool_mask) elif result.dtype == np.object_ and non_default_dtype_backend: # read_excel sends array of datetime objects - inferred_type = lib.infer_dtype(result) - if inferred_type != "datetime": + if not lib.is_datetime_array(result, skipna=True): result = StringDtype().construct_array_type()._from_sequence(values) if dtype_backend == "pyarrow":