Skip to content

CLN: reindex_axis remove unnecessary args, always copy=False #41190

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 1 commit into from
Apr 28, 2021
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
8 changes: 6 additions & 2 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
23 changes: 8 additions & 15 deletions pandas/core/internals/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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,
)
Expand Down