Skip to content

Warn on unused model_config keys#2632

Open
MECoban wants to merge 2 commits into
pymc-labs:mainfrom
MECoban:warn-unused-model-config-keys
Open

Warn on unused model_config keys#2632
MECoban wants to merge 2 commits into
pymc-labs:mainfrom
MECoban:warn-unused-model-config-keys

Conversation

@MECoban

@MECoban MECoban commented Jun 14, 2026

Copy link
Copy Markdown

Closes #1256.

Problem

ModelBuilder.__init__ merges user config with self.default_model_config | model_config. Any key the user passes that is not part of default_model_config is silently merged in and then ignored by the model. A typo like model_config={"alphaa": ...} (instead of "alpha") leaves the user wondering why their model didn't change.

Change

After the merge, warn about keys that the model does not use:

unused_model_config_keys = set(model_config) - set(default_model_config)
if unused_model_config_keys:
    warnings.warn(
        "The following model_config keys are not used by the model "
        f"and will be ignored: {sorted(unused_model_config_keys)}. "
        f"Valid keys are: {sorted(default_model_config)}.",
        UserWarning,
        stacklevel=2,
    )
  • Chose a UserWarning rather than raising, to stay backward compatible (existing code passing extra keys keeps working). Happy to switch to raising a ModelConfigError if you'd prefer stricter behavior.
  • default_model_config is cached in a local so the property isn't evaluated twice.
  • Updated the model_config docstring to mention the warning.

Tests

Added to tests/test_model_builder.py:

  • test_model_config_warns_on_unused_keys — unknown key triggers the warning.
  • test_model_config_no_warning_for_valid_keys — valid-only config stays silent.

This assumes default_model_config enumerates every key a model uses (per its docstring). If some model intentionally accepts keys outside it, the warning is harmless (no break) and we can refine the check.


📚 Documentation preview 📚: https://pymc-marketing--2632.org.readthedocs.build/en/2632/

Closes pymc-labs#1256. When a user passes a model_config key that is not part of
default_model_config (e.g. a typo like "alphaa"), it was silently
merged in and ignored by the model. Emit a UserWarning listing the
unused keys and the valid ones so mistakes are visible.

Caches default_model_config in a local to avoid evaluating the property
twice, and adds tests for the warning and the no-warning paths.
@github-actions github-actions Bot added tests ModelBuilder Related to the ModelBuilder class and its children enhancement New feature or request MMM labels Jun 14, 2026

@juanitorduz juanitorduz left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thnks @MECoban !

@codecov

codecov Bot commented Jun 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.59%. Comparing base (649547e) to head (00227b5).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2632      +/-   ##
==========================================
- Coverage   94.19%   92.59%   -1.60%     
==========================================
  Files         100      100              
  Lines       15384    15388       +4     
==========================================
- Hits        14491    14249     -242     
- Misses        893     1139     +246     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request MMM ModelBuilder Related to the ModelBuilder class and its children tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Raise or warn when model_config keys are not used

2 participants