From 86520241eb8134af781abd6e500b53e4e3caa9f9 Mon Sep 17 00:00:00 2001 From: Brock Date: Tue, 10 Sep 2024 14:32:28 -0700 Subject: [PATCH] REF: pass dtype explicitly to _from_sequence --- pandas/core/construction.py | 6 ++++-- pandas/tests/extension/base/methods.py | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/pandas/core/construction.py b/pandas/core/construction.py index bb3aa3867ab08..1e1292f8ef089 100644 --- a/pandas/core/construction.py +++ b/pandas/core/construction.py @@ -358,7 +358,8 @@ def array( return cls._from_sequence(data, dtype=dtype, copy=copy) elif data.dtype.kind in "iu": - return IntegerArray._from_sequence(data, copy=copy) + dtype = IntegerArray._dtype_cls._get_dtype_mapping()[data.dtype] + return IntegerArray._from_sequence(data, dtype=dtype, copy=copy) elif data.dtype.kind == "f": # GH#44715 Exclude np.float16 bc FloatingArray does not support it; # we will fall back to NumpyExtensionArray. @@ -366,7 +367,8 @@ def array( return NumpyExtensionArray._from_sequence( data, dtype=data.dtype, copy=copy ) - return FloatingArray._from_sequence(data, copy=copy) + dtype = FloatingArray._dtype_cls._get_dtype_mapping()[data.dtype] + return FloatingArray._from_sequence(data, dtype=dtype, copy=copy) elif data.dtype.kind == "b": return BooleanArray._from_sequence(data, dtype="boolean", copy=copy) diff --git a/pandas/tests/extension/base/methods.py b/pandas/tests/extension/base/methods.py index dd2ed0bd62a02..fd9fec0cb490c 100644 --- a/pandas/tests/extension/base/methods.py +++ b/pandas/tests/extension/base/methods.py @@ -549,7 +549,7 @@ def _test_searchsorted_bool_dtypes(self, data_for_sorting, as_series): dtype = data_for_sorting.dtype data_for_sorting = pd.array([True, False], dtype=dtype) b, a = data_for_sorting - arr = type(data_for_sorting)._from_sequence([a, b]) + arr = type(data_for_sorting)._from_sequence([a, b], dtype=dtype) if as_series: arr = pd.Series(arr)