Skip to content

Commit

Permalink
fix #822 and add tests to prevent it (#823)
Browse files Browse the repository at this point in the history
  • Loading branch information
OriolAbril authored and ahartikainen committed Oct 21, 2019
1 parent 24f8268 commit 4815daa
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions arviz/tests/test_data_pymc.py
Expand Up @@ -152,3 +152,29 @@ def test_constant_data(self):
test_dict = {"posterior": ["beta"], "observed_data": ["obs"], "constant_data": ["x"]}
fails = check_multiple_attrs(test_dict, inference_data)
assert not fails

def test_no_trace(self):
with pm.Model():
x = pm.Data("x", [1.0, 2.0, 3.0])
y = pm.Data("y", [1.0, 2.0, 3.0])
beta = pm.Normal("beta", 0, 1)
obs = pm.Normal("obs", x * beta, 1, observed=y) # pylint: disable=unused-variable
trace = pm.sample(100, tune=100)
prior = pm.sample_prior_predictive()
posterior_predictive = pm.sample_posterior_predictive(trace)

# Only prior
inference_data = from_pymc3(prior=prior)
test_dict = {"prior": ["beta", "obs"]}
fails = check_multiple_attrs(test_dict, inference_data)
assert not fails
# Only posterior_predictive
inference_data = from_pymc3(posterior_predictive=posterior_predictive)
test_dict = {"posterior_predictive": ["obs"]}
fails = check_multiple_attrs(test_dict, inference_data)
assert not fails
# Prior and posterior_predictive but no trace
inference_data = from_pymc3(prior=prior, posterior_predictive=posterior_predictive)
test_dict = {"prior": ["beta", "obs"], "posterior_predictive": ["obs"]}
fails = check_multiple_attrs(test_dict, inference_data)
assert not fails

0 comments on commit 4815daa

Please sign in to comment.