[Repo Assist] fix: forward distance_metric_params from kwargs to NearestNeighbors (issue #1390)#1406
Open
github-actions[bot] wants to merge 2 commits intomainfrom
Conversation
The DistanceMatchingEstimator.__init__ accepted **kwargs for extra distance metric params (V, VI, p, w) but never stored them, because getattr(self, param_name) returned None for params that are only in kwargs. The base CausalEstimator.__init__ uses **_ so they were silently dropped. Additionally, NearestNeighbors requires these params via its metric_params= keyword argument, not as top-level kwargs. Fix both issues: - Build distance_metric_params dict directly from kwargs - Pass it as metric_params=... to NearestNeighbors Add regression test for Mahalanobis distance with V matrix. Closes #1390 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This was referenced Mar 19, 2026
Open
Member
|
the core fix is a duplicate of #1391 . We should accept that PR and then keep the regression tests from this PR |
25 tasks
…arams-5a63c188091d350c Signed-off-by: Emre Kıcıman <emrek@microsoft.com>
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.
🤖 This is an automated fix from Repo Assist.
Closes #1390
Root Cause
Two bugs prevented
distance_metric_params(e.g.Vfor Mahalanobis) from reachingsklearn.neighbors.NearestNeighbors:Params silently dropped:
DistanceMatchingEstimator.__init__accepted**kwargsfor the extra metric params but then tried to recover them viagetattr(self, param_name, None). This always returnedNonebecause the base classCausalEstimator.__init__uses**_(discards all kwargs), so those params were never stored as instance attributes.Wrong argument name:
NearestNeighborstakes metric-specific params via itsmetric_params=keyword, not as top-level kwargs. The old code did**self.distance_metric_params, which would have raisedTypeErroreven if the params had been captured.Fix
self.distance_metric_paramsdirectly fromkwargsusing a dict comprehension overValid_Dist_Metric_Params.metric_params=self.distance_metric_paramsto everyNearestNeighborsconstructor call (three sites: ATT without exact-match cols, ATT with exact-match cols, and ATC).Changes
dowhy/causal_estimators/distance_matching_estimator.py— two-part fixtests/causal_estimators/test_distance_matching_estimator.py— new test file with a regression test for Mahalanobis +Vend-to-endTest Status
The regression test passes locally: