Skip to content

Commit 58a6a02

Browse files
authored
include :: in name prefix check (#5951)
* include :: in name prefix check ``` import pymc as pm with pm.Model("foo"): print(pm.Normal("foobar"), pm.Normal("baz")) ``` before: `foobar foo::baz` after: `foo::foobar foo::baz` * add a unit test
1 parent bc8e8cf commit 58a6a02

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

pymc/model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1568,7 +1568,7 @@ def name_for(self, name):
15681568
"""Checks if name has prefix and adds if needed"""
15691569
name = self._validate_name(name)
15701570
if self.prefix:
1571-
if not name.startswith(self.prefix):
1571+
if not name.startswith(self.prefix + "::"):
15721572
return f"{self.prefix}::{name}"
15731573
else:
15741574
return name

pymc/tests/test_model.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,11 @@ def test_model_root(self):
159159
with pm.Model() as sub:
160160
assert model is sub.root
161161

162+
def test_prefix_add_uses_separator(self):
163+
with pm.Model("foo"):
164+
foobar = pm.Normal("foobar")
165+
assert foobar.name == "foo::foobar"
166+
162167
def test_nested_named_model_repeated(self):
163168
with pm.Model("sub") as model:
164169
b = pm.Normal("var")

0 commit comments

Comments
 (0)