Expose matched index pairs as NearestNeighborMatch.matched_indexes_ (#621)#940
Open
jeongyoonlee wants to merge 1 commit into
Open
Expose matched index pairs as NearestNeighborMatch.matched_indexes_ (#621)#940jeongyoonlee wants to merge 1 commit into
jeongyoonlee wants to merge 1 commit into
Conversation
…621) Capture the (from, to) index pairs computed inside NearestNeighborMatch.match() and expose them as the fitted attribute `matched_indexes_` (a two-column DataFrame). Each row is one matched pair, so under ratio > 1 a single `from` index can appear against multiple `to` indices. Covers both the replacement (NearestNeighbors) and no-replacement (caliper-loop) paths. Reimplements the work of @jbbqqf in #897 (CLA-blocked). Closes #621.
jeongyoonlee
requested review from
alexander-pv,
huigangchen,
paullo0106,
ppstacy,
ras44,
t-tte,
vincewu51 and
zhenyuz0500
July 14, 2026 17:01
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Proposed changes
Expose the matched index pairs computed inside
NearestNeighborMatch.match()as a fitted attributematched_indexes_— a two-columnpandas.DataFrame(from,to) where each row is one matched pair. Useful for joining matched pairs back to upstream metadata or auditing the matching outcome without re-running the algorithm.Previously these
(from, to)pairs were computed and then discarded; only the joined DataFrame was returned. Underratio > 1a singlefromindex can appear multiple times against distincttoindices, so the attribute captures the pair mapping (not just the deduplicated from-set). Both the replacement (NearestNeighbors) and no-replacement (caliper-loop) paths are covered.match_by_groupcallsmatch()per group, so the attribute reflects the most recent call.Fixes #621.
Credit
Reimplements the work of @jbbqqf in #897, which is CLA-blocked and cannot be merged directly. Full credit to @jbbqqf for the original implementation and analysis; this PR re-lands the same feature against current
masterunder a CLA-clean author.Types of changes
Tests
test_nearest_neighbor_match_exposes_matched_indexesintests/test_match.pycovering both branches (schema, consistency with the returned matched frame, and pair-level granularity underreplace=True, ratio=2). Fails onmasterwithAttributeError, passes here.tests/test_match.py— 6 passed.