Fix: Prevent name collision between coords and data variables
Fix: Prevent name collision between coords and data variables
Adds checks to prevent you from defining a coordinate with the same name as a data variable, or vice-versa.
This addresses issue #7788, where such name collisions could lead to downstream errors, particularly with sample_posterior_predictive returning prior predictive samples instead of posterior predictive samples.
The following changes were made:
- Modified
Model.add_named_variableto check if the proposed variable name already exists as a coordinate name. - Modified
Model.add_coordto check if the proposed coordinate name already exists as a variable name. - Added a test case to
tests/model/test_core.pyto verify these checks.
📚 Documentation preview 📚: https://pymc--7794.org.readthedocs.build/en/7794/
There is a pre-existing test that is failing due to the new error message. Importantly it suggests there was already some code to handle this. Should check why it wasn't sufficient and remove because it's now probably duplicated