Skip to content

BUG: Reindex casting to object in certain situation #48190

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 7 commits into from
Sep 2, 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
1 change: 1 addition & 0 deletions doc/source/whatsnew/v1.6.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ Interval
Indexing
^^^^^^^^
- Bug in :meth:`DataFrame.reindex` filling with wrong values when indexing columns and index for ``uint`` dtypes (:issue:`48184`)
- Bug in :meth:`DataFrame.reindex` casting dtype to ``object`` when :class:`DataFrame` has single extension array column when re-indexing ``columns`` and ``index`` (:issue:`48190`)
-

Missing
Expand Down
5 changes: 5 additions & 0 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -5345,6 +5345,11 @@ def _needs_reindex_multi(self, axes, method, level) -> bool_t:
and method is None
and level is None
and not self._is_mixed_type
and not (
self.ndim == 2
and len(self.dtypes) == 1
and is_extension_array_dtype(self.dtypes.iloc[0])
)
)

def _reindex_multi(self, axes, copy, fill_value):
Expand Down
9 changes: 9 additions & 0 deletions pandas/tests/frame/methods/test_reindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,15 @@ def test_reindex_uint_dtypes_fill_value(self, any_unsigned_int_numpy_dtype):
)
tm.assert_frame_equal(result, expected)

def test_reindex_single_column_ea_index_and_columns(self, any_numeric_ea_dtype):
# GH#48190
df = DataFrame({"a": [1, 2]}, dtype=any_numeric_ea_dtype)
result = df.reindex(columns=list("ab"), index=[0, 1, 2], fill_value=10)
expected = DataFrame(
{"a": Series([1, 2, 10], dtype=any_numeric_ea_dtype), "b": 10}
)
tm.assert_frame_equal(result, expected)

def test_reindex_dups(self):

# GH4746, reindex on duplicate index error messages
Expand Down