Skip to content

Commit a9f76d7

Browse files
authored
REF: pass dtype explicitly to _from_sequence inside pd.array (pandas-dev#59773)
REF: pass dtype explicitly to _from_sequence
1 parent b87bf85 commit a9f76d7

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

pandas/core/construction.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -358,15 +358,17 @@ def array(
358358
return cls._from_sequence(data, dtype=dtype, copy=copy)
359359

360360
elif data.dtype.kind in "iu":
361-
return IntegerArray._from_sequence(data, copy=copy)
361+
dtype = IntegerArray._dtype_cls._get_dtype_mapping()[data.dtype]
362+
return IntegerArray._from_sequence(data, dtype=dtype, copy=copy)
362363
elif data.dtype.kind == "f":
363364
# GH#44715 Exclude np.float16 bc FloatingArray does not support it;
364365
# we will fall back to NumpyExtensionArray.
365366
if data.dtype == np.float16:
366367
return NumpyExtensionArray._from_sequence(
367368
data, dtype=data.dtype, copy=copy
368369
)
369-
return FloatingArray._from_sequence(data, copy=copy)
370+
dtype = FloatingArray._dtype_cls._get_dtype_mapping()[data.dtype]
371+
return FloatingArray._from_sequence(data, dtype=dtype, copy=copy)
370372

371373
elif data.dtype.kind == "b":
372374
return BooleanArray._from_sequence(data, dtype="boolean", copy=copy)

pandas/tests/extension/base/methods.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ def _test_searchsorted_bool_dtypes(self, data_for_sorting, as_series):
549549
dtype = data_for_sorting.dtype
550550
data_for_sorting = pd.array([True, False], dtype=dtype)
551551
b, a = data_for_sorting
552-
arr = type(data_for_sorting)._from_sequence([a, b])
552+
arr = type(data_for_sorting)._from_sequence([a, b], dtype=dtype)
553553

554554
if as_series:
555555
arr = pd.Series(arr)

0 commit comments

Comments
 (0)