[Repo Assist] fix(gcm/ml): add clone() to SklearnRegressionModelWeighted to return correct type - #1723
Draft
github-actions[bot] wants to merge 1 commit into
Conversation
…correct type SklearnRegressionModelWeighted was inheriting clone() from SklearnRegressionModel, which returned a SklearnRegressionModel instance instead of SklearnRegressionModelWeighted. This caused the cloned model to lose the sample_weight support in fit(). The same bug was fixed for SklearnClassificationModelWeighted in #1664 (Bug fixes in GCM). This PR applies the identical fix to the regression counterpart. Test: add test_given_weighted_regression_model_when_clone_then_clone_type_is_weighted_and_supports_sample_weight to tests/gcm/ml/test_regression.py, which would fail before this fix (TypeError on cloned.fit(..., sample_weight=...)) and passes after. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
This was referenced Jul 31, 2026
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 pull request from Repo Assist, an AI assistant.
Problem
SklearnRegressionModelWeightedwas missing its ownclone()method, so it inheritedSklearnRegressionModel.clone(), which returns aSklearnRegressionModelinstead of aSklearnRegressionModelWeighted.This meant that cloning a weighted regression model silently dropped the
sample_weightsupport: the cloned object'sfit()would not accept thesample_weightkeyword argument (it only supportsXandY), causing aTypeErrorif the caller tried to use it.Root cause
The same class-hierarchy bug was present in
SklearnClassificationModelWeightedand was fixed in the broader bug-fix commit (PR #1664, commit6e8a31e):The regression counterpart was not included in that fix.
Fix
Added a
clone()override toSklearnRegressionModelWeighted:This is the exact same pattern used by
SklearnClassificationModelWeighted.When does this matter?
Any code path that:
SklearnRegressionModelWeightedas the prediction model, andmechanism.clone()(e.g.causal_model.clone(),model_evaluation.py,confidence_intervals_cms.py, ordistribution_change.py)...would silently produce a wrong-type clone. In the worst case, a subsequent
fit(..., sample_weight=...)call raises aTypeError.Test Status
1 new test added to
tests/gcm/ml/test_regression.py:test_given_weighted_regression_model_when_clone_then_clone_type_is_weighted_and_supports_sample_weight— asserts the clone is the correct type and thatfit(X, Y, sample_weight=...)succeeds on it (this wouldTypeErroron the old code).✅ Syntax check passes on both modified files.
Flake8 / black / isort: no hard errors on modified source file (one-liner addition in an already-clean module).