EconML
EconML copied to clipboard
fix: Thread n_jobs to first-stage 'auto' selector (closes #1009)
Closes #1009.
Investigation comment with the full diagnosis and selector-tree evidence: https://github.com/py-why/EconML/issues/1009#issuecomment-4482313812
What changed
get_selector/_make_first_stage_selectorgain ann_jobskwarg and thread it through every estimator that supports it.DML/NonParamDMLusegetattr(self, 'n_jobs', None)so the fix applies toSparseLinearDMLwithout touching classes that don't exposen_jobs(LinearDML,KernelDML).CausalForestDMLpassesself.n_jobsdirectly.- Drive-by: gate the existing
n_jobscopy in_to_logisticRegressiononsklearn < 1.8. sklearn 1.8 deprecatedn_jobsonLogisticRegression; the copy triggered aFutureWarningoncen_jobsactually started reachingLogisticRegressionCV.
Out of scope
LinearDMLandKernelDMLdon't currently exposen_jobs. Adding it would be a separate API decision; flagged for follow up.DRLearnerfamily: the duplicate_make_first_stage_selectorineconml/dr/_drlearner.pygains the kwarg for API consistency, but no DR call site exercises it yet. Follow-up if/when those classes grow ann_jobsparameter.
Verification
New regression test test_n_jobs_propagates_to_first_stage_auto_selector:
- Pre fix: fails (
SparseLinearDML -> GridSearchCV.n_jobs = None, expected 3) - Post fix: passes
- Exercises
SparseLinearDML(continuous + discrete) andCausalForestDML