Deprecate positional treatment/y in meta-learner fit() for sklearn Pipeline compat (#854) - #975
Open
jeongyoonlee wants to merge 1 commit into
Open
Deprecate positional treatment/y in meta-learner fit() for sklearn Pipeline compat (#854)#975jeongyoonlee wants to merge 1 commit into
jeongyoonlee wants to merge 1 commit into
Conversation
Kick off the scikit-learn Pipeline-compatibility change for meta-learners: the positional fit() argument order will move from (X, treatment, y, ...) to (X, y, treatment, ...) in v1.0. This is the first, non-breaking step of a two-step deprecation. - Add a re-entrancy-guarded shim in BaseLearner that emits a FutureWarning when treatment/y are passed positionally to fit/fit_predict/estimate_ate, steering callers to order-independent keyword arguments. It is wired in via __init_subclass__ so every S/T/X/R/DR learner (and its subclasses) is covered with no per-method edits, and the real signatures are preserved via functools.wraps. The guard ensures internal delegation (fit_predict -> fit, subclass fit -> super().fit, estimate_ate -> fit_predict -> fit) warns at most once per top-level call. - The positional order is UNCHANGED for now, so no existing call silently breaks; keyword calls -- fit(X, y=y, treatment=treatment) -- are silent and stay correct across the v1.0 flip. - Add tests/test_fit_arg_order.py covering the warning on positional use, keyword silence, single-warning delegation, subclass super().fit, signature preservation, and positional==keyword equivalence (guarding against a silent y/treatment swap).
jeongyoonlee
marked this pull request as ready for review
July 27, 2026 01:05
jeongyoonlee
requested review from
alexander-pv,
huigangchen,
paullo0106,
ppstacy,
ras44,
t-tte,
vincewu51 and
zhenyuz0500
July 27, 2026 01:05
ras44
approved these changes
Jul 27, 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.
What & why
Kicks off #854 — making the meta-learners compatible with
sklearn.pipeline.Pipeline, the one intentional breaking change on the v1.0 roadmap (M1).Pipelinecalls the final estimator'sfit(X, y)positionally, but CausalML meta-learners takefit(X, treatment, y, ...)—yis third. In v1.0 the positional order becomesfit(X, y, treatment, ...).Reordering two required positional arguments can't be done in one step without risking a silent
y/treatmentswap for existing positional callers. So this is a two-step deprecation, and this PR is step one (non-breaking):fit(X, treatment, y)call keeps working exactly as before.treatment/ypositionally now emits aFutureWarningpointing callers to keyword arguments:fit(X, y=y, treatment=treatment). Keyword calls are order-independent, so code that migrates now keeps working unchanged across the v1.0 flip.(X, y, treatment, ...)and drop the shim.How
BaseLearner, wired in via__init_subclass__, wraps each subclass's ownfit/fit_predict/estimate_ate. This covers the whole S/T/X/R/DR family (and subclasses likeXGBTRegressor) with no per-method edits, andfunctools.wrapspreserves the real signatures for introspection.fit_predict → fit, subclassfit → super().fit(X, treatment, y, *args, **kwargs),estimate_ate → fit_predict → fit— warns at most once per top-level call.metrics/sensitivity.py,dataset/synthetic.py, …) already calls these methods with keywords.Scope
BaseLearnermeta-learner family (S/T/X/R/DR + subclasses).predictalready takesXfirst withtreatment/yoptional, soPipeline'spredict(X)already works — no change needed.TMLELearner(standalone, notBaseLearner, not Pipeline-usable) and the IV/NN learners are untouched here.Pipelinestep —treatmentstill needs to be threaded via sklearn metadata routing. That's a separate follow-up; this PR is the argument-order groundwork.Tests
tests/test_fit_arg_order.py(19 cases): positional-use warning across S/T/X/R/DR, keyword silence, single-warning delegation (fit_predict/estimate_ate/ subclasssuper().fit), signature preservation, and positional == keyword equivalence (guards against a silenty/treatmentswap). Fulltests/test_meta_learners.py(74) stays green.Refs #854.