EconML icon indicating copy to clipboard operation
EconML copied to clipboard

fix: Thread n_jobs to first-stage 'auto' selector (closes #1009)

Open immu4989 opened this issue 6 months ago • 0 comments

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_selector gain an n_jobs kwarg and thread it through every estimator that supports it.
  • DML / NonParamDML use getattr(self, 'n_jobs', None) so the fix applies to SparseLinearDML without touching classes that don't expose n_jobs (LinearDML, KernelDML).
  • CausalForestDML passes self.n_jobs directly.
  • Drive-by: gate the existing n_jobs copy in _to_logisticRegression on sklearn < 1.8. sklearn 1.8 deprecated n_jobs on LogisticRegression; the copy triggered a FutureWarning once n_jobs actually started reaching LogisticRegressionCV.

Out of scope

  • LinearDML and KernelDML don't currently expose n_jobs. Adding it would be a separate API decision; flagged for follow up.
  • DRLearner family: the duplicate _make_first_stage_selector in econml/dr/_drlearner.py gains the kwarg for API consistency, but no DR call site exercises it yet. Follow-up if/when those classes grow an n_jobs parameter.

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) and CausalForestDML

immu4989 avatar May 18 '26 21:05 immu4989