pymc icon indicating copy to clipboard operation
pymc copied to clipboard

Fix: Prevent name collision between coords and data variables

Open twiecki opened this issue 6 months ago • 1 comments

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_variable to check if the proposed variable name already exists as a coordinate name.
  • Modified Model.add_coord to check if the proposed coordinate name already exists as a variable name.
  • Added a test case to tests/model/test_core.py to verify these checks.

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

twiecki avatar May 21 '25 02:05 twiecki

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

ricardoV94 avatar May 21 '25 02:05 ricardoV94