Skip to content

Commit 1584530

Browse files
jorisvandenbosschejreback
authored andcommitted
BUG fix IntegerArray.astype int -> uint (#22441)
1 parent decef78 commit 1584530

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

doc/source/whatsnew/v0.24.0.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Pandas has gained the ability to hold integer dtypes with missing values. This l
4242
Here is an example of the usage.
4343

4444
We can construct a ``Series`` with the specified dtype. The dtype string ``Int64`` is a pandas ``ExtensionDtype``. Specifying a list or array using the traditional missing value
45-
marker of ``np.nan`` will infer to integer dtype. The display of the ``Series`` will also use the ``NaN`` to indicate missing values in string outputs. (:issue:`20700`, :issue:`20747`)
45+
marker of ``np.nan`` will infer to integer dtype. The display of the ``Series`` will also use the ``NaN`` to indicate missing values in string outputs. (:issue:`20700`, :issue:`20747`, :issue:`22441`)
4646

4747
.. ipython:: python
4848

pandas/core/arrays/integer.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -409,8 +409,7 @@ def astype(self, dtype, copy=True):
409409

410410
# if we are astyping to an existing IntegerDtype we can fastpath
411411
if isinstance(dtype, _IntegerDtype):
412-
result = self._data.astype(dtype.numpy_dtype,
413-
casting='same_kind', copy=False)
412+
result = self._data.astype(dtype.numpy_dtype, copy=False)
414413
return type(self)(result, mask=self._mask, copy=False)
415414

416415
# coerce

pandas/tests/extension/integer/test_integer.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -566,16 +566,17 @@ def test_astype(self, all_data):
566566
expected = pd.Series(np.asarray(mixed))
567567
tm.assert_series_equal(result, expected)
568568

569-
@pytest.mark.parametrize('dtype', [Int8Dtype(), 'Int8'])
569+
@pytest.mark.parametrize('dtype', [Int8Dtype(), 'Int8',
570+
UInt32Dtype(), 'UInt32'])
570571
def test_astype_specific_casting(self, dtype):
571572
s = pd.Series([1, 2, 3], dtype='Int64')
572573
result = s.astype(dtype)
573-
expected = pd.Series([1, 2, 3], dtype='Int8')
574+
expected = pd.Series([1, 2, 3], dtype=dtype)
574575
self.assert_series_equal(result, expected)
575576

576577
s = pd.Series([1, 2, 3, None], dtype='Int64')
577578
result = s.astype(dtype)
578-
expected = pd.Series([1, 2, 3, None], dtype='Int8')
579+
expected = pd.Series([1, 2, 3, None], dtype=dtype)
579580
self.assert_series_equal(result, expected)
580581

581582
def test_construct_cast_invalid(self, dtype):

0 commit comments

Comments
 (0)