Skip to content

Commit a1e30eb

Browse files
committed
Fix brittle check in test_marginal_likelihood
This would fail when the chains do not have the same length, resulting in the marginal_likelihood being wrapped in a numpy array of `object` dtype. This led the nanmean call to fail with an AttributeError
1 parent 16d91f2 commit a1e30eb

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

pymc/tests/test_smc.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,16 @@ def test_marginal_likelihood(self):
144144
marginals.append(trace.report.log_marginal_likelihood)
145145

146146
# compare to the analytical result
147-
assert abs(np.exp(np.nanmean(marginals[1]) - np.nanmean(marginals[0])) - 4.0) <= 1
147+
assert (
148+
np.abs(
149+
np.exp(
150+
np.nanmean(np.array(marginals[1], dtype=float))
151+
- np.nanmean(np.array(marginals[0], dtype=float))
152+
- 4.0
153+
)
154+
)
155+
<= 1
156+
)
148157

149158
def test_start(self):
150159
with pm.Model() as model:

0 commit comments

Comments
 (0)