fix: complete sklearn 1.9 support — drop self.alphas overwrite (closes #1032)
Closes #1032.
What's happening
#1032 (filed by @jakevdp) reports that import econml.orf errors on scikit-learn 1.9 because n_alphas was removed from LassoCV.__init__.
The recent commit e546416 added a >= 1.7 version dispatch in WeightedLassoCV.__init__ / WeightedMultiTaskLassoCV.__init__ that translates n_alphas=<int> into alphas=<int> on the super().__init__() call. That fixes the import-time TypeError jakevdp reported.
But e546416 also added self.alphas = alphas at the end of the dispatch, which clobbers the value sklearn's __init__ had correctly recorded back to the constructor's alphas kwarg (None by default):
if parse(sklearn.__version__) >= parse("1.7"):
super().__init__(
eps=eps, alphas=alphas if alphas is not None else n_alphas, # alphas=100 ✓
...)
self.n_alphas = n_alphas
self.alphas = alphas # ← overwrites sklearn's alphas=100 back to None
On sklearn 1.7–1.8 the loose param-validation tolerated the resulting self.alphas = None. On sklearn 1.9 the stricter _param_validation rejects it, so SparseLinearDML.fit (via _DebiasedLasso.fit → WeightedLassoCV) and DebiasedLasso.fit raise:
sklearn.utils._param_validation.InvalidParameterError:
The 'alphas' parameter of WeightedLassoCV must be an int in the range [1, inf)
or an array-like. Got None instead.
Fix
Drop the overwrite. super().__init__(...) already records self.alphas from the translated value. self.n_alphas is still set so callers can introspect the original wrapper kwarg.
Same edit applied to both WeightedLassoCV.__init__ and WeightedMultiTaskLassoCV.__init__.
Also bumps pyproject.toml scikit-learn >= 1.0, < 1.9 → < 1.10 so users can actually install sklearn 1.9.
Verification (locally, sklearn 1.9.0 + narwhals)
import econml.orf✓ (jakevdp's exact repro)- Smoke fits all succeed on sklearn 1.9:
LinearDML,SparseLinearDML,CausalForestDML,DMLOrthoForest,LinearDRLearner,SparseLinearDRLearner - New
test_default_alphas_fits_on_strict_sklearnregression test inTestLassoExtensions:- Asserts
WeightedLassoCV().alphas is not NoneandWeightedMultiTaskLassoCV().alphas is not None(the dispatched value must survive) - Calls
.fit(...)on each, verifying sklearn 1.9 strict validation accepts the result - Pre-fix on sklearn 1.9: fails with
AssertionError: WeightedLassoCV.alphas was clobbered to None by __init__ (#1032) - Post-fix: passes
- Asserts
- Broader sweep: 48 passed, 0 failed across
test_linear_model.py+test_dml.py+test_treatment_featurization.pyon sklearn 1.9.