Skip to content

Commit

Permalink
BUG: reindex using wrong fill value when indexing cols and index for …
Browse files Browse the repository at this point in the history
…uint dtypes (#48185)
  • Loading branch information
phofl authored Aug 31, 2022
1 parent bfdb524 commit d0268e7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v1.6.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ Interval

Indexing
^^^^^^^^
-
- Bug in :meth:`DataFrame.reindex` filling with wrong values when indexing columns and index for ``uint`` dtypes (:issue:`48184`)
-

Missing
Expand Down
10 changes: 7 additions & 3 deletions pandas/core/array_algos/take.py
Original file line number Diff line number Diff line change
Expand Up @@ -546,9 +546,13 @@ def _take_2d_multi_object(
out[:, col_mask] = fill_value
for i in range(len(row_idx)):
u_ = row_idx[i]
for j in range(len(col_idx)):
v = col_idx[j]
out[i, j] = arr[u_, v]

if u_ != -1:
for j in range(len(col_idx)):
v = col_idx[j]

if v != -1:
out[i, j] = arr[u_, v]


def _take_preprocess_indexer_and_fill_value(
Expand Down
10 changes: 10 additions & 0 deletions pandas/tests/frame/methods/test_reindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,16 @@ def test_reindex_fill_value(self):
expected = df.reindex(range(15)).fillna(0)
tm.assert_frame_equal(result, expected)

def test_reindex_uint_dtypes_fill_value(self, any_unsigned_int_numpy_dtype):
# GH#48184
df = DataFrame({"a": [1, 2], "b": [1, 2]}, dtype=any_unsigned_int_numpy_dtype)
result = df.reindex(columns=list("abcd"), index=[0, 1, 2, 3], fill_value=10)
expected = DataFrame(
{"a": [1, 2, 10, 10], "b": [1, 2, 10, 10], "c": 10, "d": 10},
dtype=any_unsigned_int_numpy_dtype,
)
tm.assert_frame_equal(result, expected)

def test_reindex_dups(self):

# GH4746, reindex on duplicate index error messages
Expand Down

0 comments on commit d0268e7

Please sign in to comment.