Skip to content

BUG: reindex using wrong fill value when indexing cols and index for uint dtypes #48185

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

Merged
merged 5 commits into from
Aug 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
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