Skip to content

Commit 42898c6

Browse files
committed
Added conditional to handle integer arrays in take method as special case.
1 parent 65511cd commit 42898c6

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

pandas/core/arrays/_mixins.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
from pandas.core.dtypes.dtypes import (
4141
DatetimeTZDtype,
4242
ExtensionDtype,
43+
NumpyEADtype,
4344
PeriodDtype,
4445
)
4546
from pandas.core.dtypes.missing import array_equivalent
@@ -173,8 +174,14 @@ def take(
173174
fill_value=fill_value,
174175
axis=axis,
175176
)
176-
177-
return type(self)._simple_new(new_data, new_data.dtype)
177+
if self.dtype in [
178+
NumpyEADtype(np.uint32),
179+
NumpyEADtype(np.uint64),
180+
NumpyEADtype(np.int32),
181+
NumpyEADtype(np.int64),
182+
]:
183+
return type(self)(new_data)
184+
return self._from_backing_data(new_data)
178185

179186
# ------------------------------------------------------------------------
180187

pandas/tests/arrays/numpy_/test_numpy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ def test_take_assigns_correct_dtype(dtype):
331331

332332
result = array.take([-1], allow_fill=True)
333333

334-
assert result.dtype == np.float64
334+
assert result.dtype == NumpyEADtype(np.float64)
335335

336336

337337
# ----------------------------------------------------------------------------

0 commit comments

Comments
 (0)