From 7ca470d8d02f00dc27160a7586f2a0ea2db1e9da Mon Sep 17 00:00:00 2001 From: morotti Date: Fri, 3 Nov 2023 12:55:46 +0000 Subject: [PATCH] PERF: avoid unnecessary method call in get_indexer_non_unique() on MultiIndex --- pandas/core/indexes/base.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index ebf4f2d515956..9db1c7706149f 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -6041,12 +6041,13 @@ def get_indexer_non_unique( # Note: _maybe_downcast_for_indexing ensures we never get here # with MultiIndex self and non-Multi target - tgt_values = target._get_engine_target() if self._is_multi and target._is_multi: engine = self._engine # Item "IndexEngine" of "Union[IndexEngine, ExtensionEngine]" has # no attribute "_extract_level_codes" tgt_values = engine._extract_level_codes(target) # type: ignore[union-attr] + else: + tgt_values = target._get_engine_target() indexer, missing = self._engine.get_indexer_non_unique(tgt_values) return ensure_platform_int(indexer), ensure_platform_int(missing)