Skip to content

Bug fixes in GCM#1664

Merged
emrekiciman merged 3 commits into
mainfrom
gcm_fix
Jul 16, 2026
Merged

Bug fixes in GCM#1664
emrekiciman merged 3 commits into
mainfrom
gcm_fix

Conversation

@bloebp

@bloebp bloebp commented Jul 8, 2026

Copy link
Copy Markdown
Member

Fixes silent wrong-result bugs (GMM sampling correlation, bootstrap CI percentiles, distribution-change early stopping, unit_change intercept, adaptive RBF kernel, discretization entropy, uniform noise std, categorical mode collapse), crashes and dtype issues (multiclass log_loss, max_num_samples subsampling, is_categorical with NaN, int32 overflow, empty-graph refutation, quantile guard, single-player Shapley, zero-root DAG, positional eq-parser args), a wrong class mapping (bayesiangaussianmixture, weighted clone), and a dead warning. Also raises a clear error for categorical counterfactual abduction instead of a leaked AttributeError. Adds regression tests for each.

@bloebp
bloebp requested review from amit-sharma and emrekiciman July 8, 2026 21:39
@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

🤖 This is an automated response from Repo Assist.

Great work, @bloebp — this is a comprehensive collection of GCM correctness fixes with regression tests for each. The breadth of the changes (GMM sampling, bootstrap CI, distribution-change stopping, adaptive RBF, is_categorical NaN handling, single-player Shapley, categorical counterfactual abduction, and more) makes this a really valuable PR.

One heads-up for maintainers: my PR #1662 (fix(gcm): move NaN filter outside column loop in is_categorical()) addresses the same is_categorical NaN-indexing bug that is included here. Now that #1664 is open and covers the same issue (plus many more), PR #1662 should be closed in favour of this one. I've noted this in my memory and will close it once this PR merges (or maintainers can close #1662 directly).

A minor observation on the is_categorical patch in this PR: the current fix correctly hoists non_nan_X = X[~nan_mask] before the loop, which is exactly the right fix. The only difference from #1662 is that #1662 also restores the original loop variable name (Xnon_nan_X throughout), which avoids shadowing the outer X. Both approaches are correct.

Looking forward to seeing this merged! 🎉

Generated by 🌈 Repo Assist, see workflow run. Learn more.

To install this agentic workflow, run

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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses a broad set of correctness bugs in DoWhy’s GCM module (wrong results, crashes, and dtype edge cases) and adds targeted regression tests to prevent reintroductions.

Changes:

  • Fix multiple silent wrong-result issues in sampling, bootstrap confidence intervals, entropy estimation, distribution-change scoring, and unit-change attributions.
  • Harden several APIs against edge cases (empty-graph validation, single-player Shapley, categorical counterfactual abduction, NaNs in categorical detection, quantile input validation).
  • Add/adjust regression tests covering each fixed scenario.

Reviewed changes

Copilot reviewed 33 out of 33 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tests/gcm/util/test_general.py Adds regression test for informative error on categorical data with NaNs.
tests/gcm/test_whatif.py Adds regression test for categorical-node counterfactual abduction error message.
tests/gcm/test_validation.py Adds regression test for edgeless DAG refutation with FDR correction.
tests/gcm/test_unit_change.py Adds regression test ensuring intercept differences are attributed in linear unit change.
tests/gcm/test_uncertainty.py Updates entropy expectations and adds regression tests for small-range and constant data.
tests/gcm/test_stochastic_models.py Adds regression test for spurious correlation avoidance in GMM sampling.
tests/gcm/test_stats.py Adds regression test for quantile input validation error message.
tests/gcm/test_shapley.py Adds regression test for single-player subset sampling Shapley.
tests/gcm/test_equation_parser.py Adds tests for bayesiangaussianmixture mapping and positional arg parsing error.
tests/gcm/test_data_generator.py Adds regression tests for zero-roots DAG generation and uniform noise std.
tests/gcm/test_confidence_intervals.py Updates expected bootstrap CI bounds to correct two-sided percentiles.
tests/gcm/test_confidence_intervals_cms.py Updates expected bootstrap CI bounds to correct two-sided percentiles.
tests/gcm/test_anomaly_scorers.py Adds regression test for finite anomaly scores when MAD is zero.
tests/gcm/ml/test_classification.py Adds regression test ensuring weighted classification clone preserves type/weights support.
dowhy/gcm/validation.py Avoids FDR adjustment path on empty p-value lists.
dowhy/gcm/util/general.py Fixes NaN-mask handling for multi-column categorical detection and raises clearer error.
dowhy/gcm/unit_change.py Adds intercept support to linear mechanisms and attributes intercept deltas.
dowhy/gcm/uncertainty.py Fixes discretization binning for small ranges; handles constant-data entropy.
dowhy/gcm/stochastic_models.py Shuffles GMM samples to prevent spurious correlations between independently sampled nodes.
dowhy/gcm/stats.py Tightens quantile validation to enforce (0, 1].
dowhy/gcm/shapley.py Fixes subset-sampling approximation for single-player case.
dowhy/gcm/model_evaluation.py Fixes max_num_samples subsampling and categorical mode shape handling.
dowhy/gcm/ml/classification.py Ensures weighted classifier clone returns weighted clone.
dowhy/gcm/influence.py Fixes infinity check for results stored as Python list.
dowhy/gcm/independence_test/kernel_operation.py Fixes per-column adaptive RBF distance computation; updates delta-kernel handling.
dowhy/gcm/equation_parser.py Fixes bayesiangaussianmixture mapping; improves argument parsing and parent-name collision warning.
dowhy/gcm/distribution_change.py Fixes early stopping logic to track convergence of running average.
dowhy/gcm/data_generator.py Fixes zero-root DAG generation and corrects uniform noise std parameterization.
dowhy/gcm/confidence_intervals.py Fixes percentile bootstrap CI bounds to use two-sided percentiles.
dowhy/gcm/causal_mechanisms.py Prevents int32 overflow by using int64 in discrete ANM.
dowhy/gcm/auto.py Fixes multiclass log_loss usage by passing explicit label set.
dowhy/gcm/anomaly_scorers.py Avoids division-by-zero in MAD-based scorer by falling back to EPS.
dowhy/gcm/_noise.py Raises clear error when noise cannot be recovered for non-invertible mechanisms.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread dowhy/gcm/independence_test/kernel_operation.py
Fixes silent wrong-result bugs (GMM sampling correlation, bootstrap CI
percentiles, distribution-change early stopping, unit_change intercept,
adaptive RBF kernel incl. constant-column NaN, discretization entropy, uniform
noise std, categorical mode collapse), crashes and dtype issues (multiclass
log_loss, max_num_samples subsampling, is_categorical with NaN, int32 overflow,
empty-graph refutation, quantile guard, single-player Shapley, zero-root DAG,
positional eq-parser args), a wrong class mapping (bayesiangaussianmixture,
weighted clone), and a dead warning. Also raises a clear error for categorical
counterfactual abduction instead of a leaked AttributeError. Adds regression
tests for each.

Signed-off-by: Patrick Bloebaum <bloebp@amazon.com>
@bloebp

bloebp commented Jul 13, 2026

Copy link
Copy Markdown
Member Author

@emrekiciman any concerns left?

@emrekiciman
emrekiciman merged commit 6e8a31e into main Jul 16, 2026
37 checks passed
github-actions Bot added a commit that referenced this pull request Jul 17, 2026
fix(gcm): correct math/logic and robustness bugs across GCM

Fixes silent wrong-result bugs (GMM sampling correlation, bootstrap CI
percentiles, distribution-change early stopping, unit_change intercept,
adaptive RBF kernel incl. constant-column NaN, discretization entropy, uniform
noise std, categorical mode collapse), crashes and dtype issues (multiclass
log_loss, max_num_samples subsampling, is_categorical with NaN, int32 overflow,
empty-graph refutation, quantile guard, single-player Shapley, zero-root DAG,
positional eq-parser args), a wrong class mapping (bayesiangaussianmixture,
weighted clone), and a dead warning. Also raises a clear error for categorical
counterfactual abduction instead of a leaked AttributeError. Adds regression
tests for each.

Signed-off-by: Patrick Bloebaum <bloebp@amazon.com>
github-actions Bot added a commit that referenced this pull request Jul 17, 2026
fix(gcm): correct math/logic and robustness bugs across GCM

Fixes silent wrong-result bugs (GMM sampling correlation, bootstrap CI
percentiles, distribution-change early stopping, unit_change intercept,
adaptive RBF kernel incl. constant-column NaN, discretization entropy, uniform
noise std, categorical mode collapse), crashes and dtype issues (multiclass
log_loss, max_num_samples subsampling, is_categorical with NaN, int32 overflow,
empty-graph refutation, quantile guard, single-player Shapley, zero-root DAG,
positional eq-parser args), a wrong class mapping (bayesiangaussianmixture,
weighted clone), and a dead warning. Also raises a clear error for categorical
counterfactual abduction instead of a leaked AttributeError. Adds regression
tests for each.

Signed-off-by: Patrick Bloebaum <bloebp@amazon.com>
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.

3 participants