Skip to content

Commit 8eaa9be

Browse files
lucianopazricardoV94
authored andcommitted
Print OP name for unnamed RVs instead of raising AssertionErrors
1 parent e988bc5 commit 8eaa9be

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

pymc/printing.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,12 @@ def _expand(x):
232232
if x.owner and isinstance(x.owner.op, RandomVariable | SymbolicRandomVariable):
233233
parents.append(x)
234234
xname = x.name
235+
if xname is None:
236+
# If the variable is unnamed, we show the op's name as we do
237+
# with constants
238+
opname = x.owner.op.name
239+
if opname is not None:
240+
xname = rf"<{opname}>"
235241
assert xname is not None
236242
names.append(xname)
237243

tests/test_printing.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,11 @@ def setup_class(self):
125125
# add a potential as well
126126
pot = Potential("pot", mu**2)
127127

128+
# add a deterministic that depends on an unnamed random variable
129+
pred = Deterministic("pred", Normal.dist(0, 1))
130+
128131
self.distributions = [alpha, sigma, mu, b, Z, nb2, zip, w, nested_mix, Y_obs, pot]
129-
self.deterministics_or_potentials = [mu, pot]
132+
self.deterministics_or_potentials = [mu, pot, pred]
130133
# tuples of (formatting, include_params)
131134
self.formats = [("plain", True), ("plain", False), ("latex", True), ("latex", False)]
132135
self.expected = {
@@ -146,6 +149,7 @@ def setup_class(self):
146149
),
147150
r"Y_obs ~ Normal(mu, sigma)",
148151
r"pot ~ Potential(f(beta, alpha))",
152+
r"pred ~ Deterministic(f(<normal>))",
149153
],
150154
("plain", False): [
151155
r"alpha ~ Normal",
@@ -159,6 +163,7 @@ def setup_class(self):
159163
r"nested_mix ~ MarginalMixture",
160164
r"Y_obs ~ Normal",
161165
r"pot ~ Potential",
166+
r"pred ~ Deterministic",
162167
],
163168
("latex", True): [
164169
r"$\text{alpha} \sim \operatorname{Normal}(0,~10)$",
@@ -176,6 +181,7 @@ def setup_class(self):
176181
),
177182
r"$\text{Y_obs} \sim \operatorname{Normal}(\text{mu},~\text{sigma})$",
178183
r"$\text{pot} \sim \operatorname{Potential}(f(\text{beta},~\text{alpha}))$",
184+
r"$\text{pred} \sim \operatorname{Deterministic}(f(\text{<normal>}))",
179185
],
180186
("latex", False): [
181187
r"$\text{alpha} \sim \operatorname{Normal}$",
@@ -189,6 +195,7 @@ def setup_class(self):
189195
r"$\text{nested_mix} \sim \operatorname{MarginalMixture}$",
190196
r"$\text{Y_obs} \sim \operatorname{Normal}$",
191197
r"$\text{pot} \sim \operatorname{Potential}$",
198+
r"$\text{pred} \sim \operatorname{Deterministic}",
192199
],
193200
}
194201

0 commit comments

Comments
 (0)