Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

REF: pass dtype explicitly to _from_sequence inside pd.array #59773

Merged
merged 2 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions pandas/core/construction.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,15 +358,17 @@ 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]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
dtype = IntegerArray._dtype_cls._get_dtype_mapping()[data.dtype]
dtype = NUMPY_INT_TO_DTYPE[data.dtype]

?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thatd work too. i chose to do it this way to avoid the extra import

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.
if data.dtype == np.float16:
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)
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/extension/base/methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading