Skip to content

Commit 923d322

Browse files
joordiaztwiecki
authored andcommitted
ENH Prevent duplicate variable names in model by raising exception at model creation. Fix #1161 (#1286)
1 parent 313ad0d commit 923d322

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

pymc3/model.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,8 @@ def Var(self, name, dist, data=None):
316316

317317
def add_random_variable(self, var):
318318
"""Add a random variable to the named variables of the model."""
319+
if var.name in self.named_vars:
320+
raise ValueError("Variable name {} already exists.".format(var.name))
319321
self.named_vars[var.name] = var
320322
if not hasattr(self, var.name):
321323
setattr(self, var.name, var)

0 commit comments

Comments
 (0)