Warn on unused model_config keys#2632
Open
MECoban wants to merge 2 commits into
Open
Conversation
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.
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
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.
Closes #1256.
Problem
ModelBuilder.__init__merges user config withself.default_model_config | model_config. Any key the user passes that is not part ofdefault_model_configis silently merged in and then ignored by the model. A typo likemodel_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:
UserWarningrather than raising, to stay backward compatible (existing code passing extra keys keeps working). Happy to switch to raising aModelConfigErrorif you'd prefer stricter behavior.default_model_configis cached in a local so the property isn't evaluated twice.model_configdocstring 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_configenumerates 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/