Re-adopt pymc-marketing transform delegation and expose MMM variants (#214) - #435
Re-adopt pymc-marketing transform delegation and expose MMM variants (#214)#435drbenvincent wants to merge 2 commits into
Conversation
…214) Add lazy pymc-marketing backend bridging with vendored fallbacks (upstream 1.0.0 is not yet compatible with pathmc's PyMC 6.2+ stack), and register delayed_adstock, weibull_adstock, and michaelis_menten transforms. Co-authored-by: Cursor <cursoragent@cursor.com>
Require rectangular panels for all convolution adstock transforms (not just scan path), give clear scan errors for vectorized-only variants, and emit Beta(2, 5) for delayed_adstock theta as documented. Co-authored-by: Cursor <cursoragent@cursor.com>
Review responseThanks for the review. Addressed all three findings in e33fc86: 1. Panel reshape skips rectangular checks (high)Fix: Added 2. Misleading scan error for variants (medium)Fix: 3. Theta prior string not applied (medium)Fix: Re: PyMC version pin — pathmc does not require PyMC 6.2 specifically ( |
|
@drbenvincent I am thinking about this: will pathmc depend on pymc-marketing, or vice versa? See pymc-labs/pymc-marketing#2642 🫠 |
|
@juanitorduz Good question — I read your concern less as “this PR will break imports” and more as the broader coupling between the two packages going forward. For this PR specifically, the delegation is lazy and optional (no hard dep on I’m very open to dropping the |
|
ok! at it is a lazy import it seems like a good step :) Thanks for the clarification |
drbenvincent
left a comment
There was a problem hiding this comment.
Review: good to merge (minor nits)
Reviewed e33fc86 locally — targeted tests pass (101/101), and prek/docs/wheel checks are green. Full CI test job was still running when I checked (likely slow MCMC), but nothing in the diff suggests it should fail.
What's solid
- Core feature (#214):
delayed_adstock,weibull_adstock, andmichaelis_mentenare registered, kernels have oracle/reference tests, andDelayedAdstock'sBeta(2, 5)theta prior is wired correctly. - Panel validation fix:
_requires_rectangular_panel()correctly extends the rectangular-panel guard to all convolution adstocks, not just the scan path. The regression test for ragged panels +delayed_adstockis the right check. - Refactor is clean:
_ConvAdstockBase+ shared_apply_conv_panelremoves duplication without changing geometric adstock behaviour. Geometric adstock still has its scanstep()with the existingl_max/normalizeguard. - pymc-marketing delegation is safe (if mostly inert today): Lazy imports, no declared dependency, vendored fallbacks always run in CI because the stacks can't co-install yet.
Minor nits (non-blocking)
- Phantom extra in error message — Weibull CDF fallback says
install pathmc[marketing], but no such extra exists inpyproject.toml. Should saypip install pymc-marketingor similar. - Scan-path limitation —
delayed_adstock/weibull_adstockare vectorized-only. If a panel model hits the scan compiler (because oflag()or geometricadstock()anywhere in the spec), these transforms will raiseNotImplementedErrorat compile time. Acceptable for v1, but worth documenting eventually. The main MMM case — panel + convolution adstock only — uses the vectorized path and works. - Docstring trimming — A lot of parameter docs were removed from
Transformbase methods. Small regression vs our docstring norms. - No user-guide update — New DSL transforms aren't documented in
docs/. Fine for closing #214 if that's follow-up scope. - Delegation code is currently dead —
_pmm_backend.pycan't run until pymc-marketing relaxes its pins. Given the thread above, a follow-up to drop it may be preferable to carrying unused complexity.
Summary
| Area | Status |
|---|---|
| Correctness (kernels, priors, panel guard) | ✅ |
| Tests | ✅ (101 targeted; CI full suite pending) |
| Lint / types | ✅ (prek green) |
| Architecture / coupling | |
| Docs / error messages | Minor gaps only |
Recommendation: merge once CI test goes green. None of the nits need to block; the pathmc[marketing] typo is the only one worth a one-line fix if we want to tidy before merge.
Summary
pymc-marketingfor built-in transforms now that upstream ships PyMC 6 support (1.0.0).pyproject.tomlpinspymc>=6.0,<7. The conflict ispytensor>=3.1.1(required since Revert exog-lag scan-carry workaround once PyTensor #2252 is fixed #333/fix: restore exog-lag scan carry after PyTensor fix #395 for exog-lag scan carry) vspymc-marketing1.0.0'spymc<6.1pin, which transitively constrainspytensor<3.1.pathmc/_pmm_backend.pywith lazy xtensor bridging helpers that delegate topymc_marketing.mmm.transformerswhen a compatible install is present, falling back to vendored pytensor kernels otherwise.delayed_adstock,weibull_adstock, andmichaelis_menten(the main motivation for re-adoption per Re-adopt pymc-marketing transform backends once it supports PyMC 6 #214).Adstockonto a shared convolution base class; geometric adstock retains scanstep()support with the existing non-defaultl_max/normalizeguard.Closes #214
Review fixes (post-Bugbot)
_requires_rectangular_panel()now triggers for all convolution adstock transforms (adstock,delayed_adstock,weibull_adstock), not just the scan path.delayed_adstock/weibull_adstockraise a clear vectorized-only error instead of suggesting a default config that still fails.DelayedAdstock.emit_priornow emitsBeta(2, 5)forthetaas documented inparam_specs.Test plan
uv run pytest tests/test_adstock_parity.py tests/test_mmm_transforms.py tests/test_transforms_parse.py tests/test_panel_shape_validation.py -v— 83+ passedmake lint— all hooks pass