Skip to content

Commit

Permalink
CLN: reindex_axis remove unnecessary args, always copy=False (pandas-…
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrockmendel authored and JulianWgs committed Jul 3, 2021
1 parent d64d928 commit ce50e99
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 18 deletions.
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

0 comments on commit ce50e99

Please sign in to comment.