diff --git a/doc/source/whatsnew/v1.6.0.rst b/doc/source/whatsnew/v1.6.0.rst index 67e65cfc26764..6eea5daa3ac3e 100644 --- a/doc/source/whatsnew/v1.6.0.rst +++ b/doc/source/whatsnew/v1.6.0.rst @@ -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 diff --git a/pandas/core/generic.py b/pandas/core/generic.py index f91d15e1a6487..a6e58a0c90dc7 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -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): diff --git a/pandas/tests/frame/methods/test_reindex.py b/pandas/tests/frame/methods/test_reindex.py index daa60be085fd8..a132519970721 100644 --- a/pandas/tests/frame/methods/test_reindex.py +++ b/pandas/tests/frame/methods/test_reindex.py @@ -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