Skip to content

Expose matched index pairs as NearestNeighborMatch.matched_indexes_ (#621)#940

Open
jeongyoonlee wants to merge 1 commit into
masterfrom
feature/621-matched-indexes
Open

Expose matched index pairs as NearestNeighborMatch.matched_indexes_ (#621)#940
jeongyoonlee wants to merge 1 commit into
masterfrom
feature/621-matched-indexes

Conversation

@jeongyoonlee

Copy link
Copy Markdown
Collaborator

Proposed changes

Expose the matched index pairs computed inside NearestNeighborMatch.match() as a fitted attribute matched_indexes_ — a two-column pandas.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. Under ratio > 1 a single from index can appear multiple times against distinct to indices, 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_group calls match() 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 master under a CLA-clean author.

Types of changes

  • New feature (non-breaking change which adds functionality)

Tests

  • New test_nearest_neighbor_match_exposes_matched_indexes in tests/test_match.py covering both branches (schema, consistency with the returned matched frame, and pair-level granularity under replace=True, ratio=2). Fails on master with AttributeError, passes here.
  • Full tests/test_match.py — 6 passed.

…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add matched indexes as NearestNeighborMatch class attribute

1 participant