Skip to content

Fix ValueError on read-only arrays in BaseSLearner.predict()#878

Merged
jeongyoonlee merged 2 commits intouber:masterfrom
mohsinm-dev:fix/856-readonly-array-slearner
Feb 23, 2026
Merged

Fix ValueError on read-only arrays in BaseSLearner.predict()#878
jeongyoonlee merged 2 commits intouber:masterfrom
mohsinm-dev:fix/856-readonly-array-slearner

Conversation

@mohsinm-dev
Copy link
Contributor

Changes

Fixes #856.

Learners like CatBoost set flags.writeable=False on arrays passed to predict() as a side effect. In BaseSLearner.predict() and BaseSClassifier.predict(), the code was mutating X_new in place (X_new[:, 0] = 1) after the learner had already made it read-only, raising ValueError: assignment destination is read-only.

This PR builds separate control and treatment arrays instead of mutating in place.

Tests

Added test_BaseSLearner_predict_with_readonly_arrays with a ReadOnlyLinearRegression wrapper that simulates CatBoost's behavior. All 27 existing meta-learner tests continue to pass.

References

Learners like CatBoost set flags.writeable=False on arrays passed to
predict(), causing the subsequent in-place mutation (X_new[:, 0] = 1)
to raise ValueError. Build separate control and treatment arrays
instead of mutating in place.
Adds ReadOnlyLinearRegression wrapper that simulates CatBoost's
behavior of setting flags.writeable=False on arrays after fit/predict.
Verifies BaseSLearner.predict() succeeds without ValueError.
@jeongyoonlee jeongyoonlee added bug Something isn't working labels Feb 23, 2026
Copy link
Collaborator

@jeongyoonlee jeongyoonlee left a comment

Choose a reason for hiding this comment

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

LGTM

@jeongyoonlee jeongyoonlee merged commit 1e52a33 into uber:master Feb 23, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ValueError: assignment destination is read-only in BaseSLearner.predict with catboost and polars

2 participants