Skip to content

[Repo Assist] fix: forward distance_metric_params from kwargs to NearestNeighbors (issue #1390)#1406

Open
github-actions[bot] wants to merge 2 commits intomainfrom
repo-assist/fix-issue-1390-distance-metric-params-5a63c188091d350c
Open

[Repo Assist] fix: forward distance_metric_params from kwargs to NearestNeighbors (issue #1390)#1406
github-actions[bot] wants to merge 2 commits intomainfrom
repo-assist/fix-issue-1390-distance-metric-params-5a63c188091d350c

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

🤖 This is an automated fix from Repo Assist.

Closes #1390

Root Cause

Two bugs prevented distance_metric_params (e.g. V for Mahalanobis) from reaching sklearn.neighbors.NearestNeighbors:

  1. Params silently dropped: DistanceMatchingEstimator.__init__ accepted **kwargs for the extra metric params but then tried to recover them via getattr(self, param_name, None). This always returned None because the base class CausalEstimator.__init__ uses **_ (discards all kwargs), so those params were never stored as instance attributes.

  2. Wrong argument name: NearestNeighbors takes metric-specific params via its metric_params= keyword, not as top-level kwargs. The old code did **self.distance_metric_params, which would have raised TypeError even if the params had been captured.

Fix

  • Build self.distance_metric_params directly from kwargs using a dict comprehension over Valid_Dist_Metric_Params.
  • Pass the dict as metric_params=self.distance_metric_params to every NearestNeighbors constructor 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 fix
  • tests/causal_estimators/test_distance_matching_estimator.py — new test file with a regression test for Mahalanobis + V end-to-end

Test Status

The regression test passes locally:

tests/causal_estimators/test_distance_matching_estimator.py::TestDistanceMatchingEstimator::test_distance_metric_params_passed_to_estimator PASSED

Generated by Repo Assist for issue #1390 ·

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@b897c2f3e43bde9ff7923c8fa9211055b26e27cc

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>
@emrekiciman
Copy link
Copy Markdown
Member

the core fix is a duplicate of #1391 . We should accept that PR and then keep the regression tests from this PR

…arams-5a63c188091d350c

Signed-off-by: Emre Kıcıman <emrek@microsoft.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

automation bug Something isn't working repo-assist

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Issue with distance_metric_params for dowhy.causal_estimators.distance_matching_estimator

1 participant