diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 8628429f18b05..eba4a36315ba4 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -246,14 +246,18 @@ def __init__( @classmethod def _init_mgr( - cls, mgr, axes, dtype: Dtype | None = None, copy: bool_t = False + cls, + mgr: Manager, + axes, + dtype: Dtype | None = None, + copy: bool_t = False, ) -> Manager: """ passed a manager and a axes dict """ for a, axe in axes.items(): if axe is not None: axe = ensure_index(axe) bm_axis = cls._get_block_manager_axis(a) - mgr = mgr.reindex_axis(axe, axis=bm_axis, copy=False) + mgr = mgr.reindex_axis(axe, axis=bm_axis) # make a copy if explicitly requested if copy: diff --git a/pandas/core/indexing.py b/pandas/core/indexing.py index 04543da167fdd..b267472eba573 100644 --- a/pandas/core/indexing.py +++ b/pandas/core/indexing.py @@ -701,7 +701,7 @@ def _ensure_listlike_indexer(self, key, axis=None, value=None): keys = self.obj.columns.union(key, sort=False) self.obj._mgr = self.obj._mgr.reindex_axis( - keys, axis=0, copy=False, consolidate=False, only_slice=True + keys, axis=0, consolidate=False, only_slice=True ) def __setitem__(self, key, value): diff --git a/pandas/core/internals/base.py b/pandas/core/internals/base.py index 7afb6e5d7e544..3a8ff8237b62f 100644 --- a/pandas/core/internals/base.py +++ b/pandas/core/internals/base.py @@ -11,16 +11,14 @@ from pandas._typing import ( DtypeObj, Shape, + final, ) from pandas.errors import AbstractMethodError from pandas.core.dtypes.cast import find_common_type from pandas.core.base import PandasObject -from pandas.core.indexes.api import ( - Index, - ensure_index, -) +from pandas.core.indexes.api import Index T = TypeVar("T", bound="DataManager") @@ -59,31 +57,26 @@ def reindex_indexer( ) -> T: raise AbstractMethodError(self) + @final def reindex_axis( - self, - new_index, + self: T, + new_index: Index, axis: int, - method=None, - limit=None, fill_value=None, - copy: bool = True, consolidate: bool = True, only_slice: bool = False, - ): + ) -> T: """ Conform data manager to new index. """ - new_index = ensure_index(new_index) - new_index, indexer = self.axes[axis].reindex( - new_index, method=method, limit=limit - ) + new_index, indexer = self.axes[axis].reindex(new_index) return self.reindex_indexer( new_index, indexer, axis=axis, fill_value=fill_value, - copy=copy, + copy=False, consolidate=consolidate, only_slice=only_slice, )