Skip to content

Commit 7a72a06

Browse files
committed
Added test to check the dtype of the result of take method. Modified take method to return correct dtype.
1 parent 4ee17b3 commit 7a72a06

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

pandas/core/arrays/_mixins.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,8 @@ def take(
173173
fill_value=fill_value,
174174
axis=axis,
175175
)
176-
return self._from_backing_data(new_data)
176+
177+
return type(self)._simple_new(new_data, new_data.dtype)
177178

178179
# ------------------------------------------------------------------------
179180

pandas/tests/arrays/numpy_/test_numpy.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,15 @@ def test_factorize_unsigned():
325325
tm.assert_extension_array_equal(res_unique, NumpyExtensionArray(exp_unique))
326326

327327

328+
@pytest.mark.parametrize("dtype", [np.uint32, np.uint64, np.int32, np.int64])
329+
def test_take_assigns_correct_dtype(dtype):
330+
array = NumpyExtensionArray(np.array([1, 2, 3], dtype=dtype))
331+
332+
result = array.take([-1], allow_fill=True)
333+
334+
assert result.dtype == np.float64
335+
336+
328337
# ----------------------------------------------------------------------------
329338
# Output formatting
330339

0 commit comments

Comments
 (0)