Skip to content

REF: De-duplicate MultiIndex._get_indexer #41976

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 3 commits into from
Jun 15, 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
7 changes: 7 additions & 0 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3497,6 +3497,13 @@ def _get_fill_indexer(
self, target: Index, method: str_t, limit: int | None = None, tolerance=None
) -> np.ndarray:

if self._is_multi:
# TODO: get_indexer_with_fill docstring says values must be _sorted_
# but that doesn't appear to be enforced
return self._engine.get_indexer_with_fill(
target=target._values, values=self._values, method=method, limit=limit
)

target_values = target._get_engine_target()

if self.is_monotonic_increasing and target.is_monotonic_increasing:
Expand Down
11 changes: 1 addition & 10 deletions pandas/core/indexes/multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -2672,18 +2672,9 @@ def _get_indexer(
# TODO: explicitly raise here? we only have one test that
# gets here, and it is checking that we raise with method="nearest"

if method == "pad" or method == "backfill":
# TODO: get_indexer_with_fill docstring says values must be _sorted_
# but that doesn't appear to be enforced
indexer = self._engine.get_indexer_with_fill(
target=target._values, values=self._values, method=method, limit=limit
)
else:
indexer = self._engine.get_indexer(target._values)

# Note: we only get here (in extant tests at least) with
# target.nlevels == self.nlevels
return ensure_platform_int(indexer)
return super()._get_indexer(target, method, limit, tolerance)

def get_slice_bound(
self, label: Hashable | Sequence[Hashable], side: str, kind: str | None = None
Expand Down