Closes #5155: Bug: MultiIndex .lookup() attempts illegal dtype cast for tuple keys #5156
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR Description: Improve
Index.lookupandMultiIndex.lookupsemanticsThis pull request refines type-handling, error messaging, and row/column matching
behavior for both
Index.containsandMultiIndex.lookup.It also adds a regression test ensuring that mixed-dtype tuple keys do not
trigger incorrect scalar casting.
The changes improve correctness, readability, and alignment with Pandas semantics.
Summary of Changes
1.
Index.lookupFile:
arkouda/pandas/index.pyboolean
pdarrayof lengthlen(self).TypeErrordescription to reflect that the function expects avalue convertible into an Arkouda array.
akint64).Motivation:
Clarifies semantics and avoids stale / unused imports.
2.
MultiIndex.lookupFile:
arkouda/pandas/index.pyMajor improvements to validation, dtype behavior, and membership logic:
Validation
listortuple.nlevelswith a clearValueError.Two explicit code paths
Per-level arkouda arrays (e.g. list of
pdarray/Strings)Delegated directly to
in1d(self.index, key)for vectorized matching.Scalar tuple keys (e.g.,
(1, "red"))This behavior aligns better with Pandas and eliminates subtle dtype bugs.
3. New Test: Mixed-dtype tuple lookup
File:
tests/pandas/index_test.pyAdded test
test_multiindex_lookup_tuple_mixed_dtypes:(1, "red"):"red"into numeric types.[True, False, False, False]for the provided example.Motivation:
Prevents regressions and captures a real-world bug scenario.
Why This Matters
MultiIndex.lookup.Backward Compatibility
Closes #5155: Bug: MultiIndex .lookup() attempts illegal dtype cast for tuple keys