Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return InferenceData when there are no variables sampled and extend=True #7509

Merged
merged 1 commit into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pymc/sampling/forward.py
Original file line number Diff line number Diff line change
Expand Up @@ -825,7 +825,7 @@ def sample_posterior_predictive(
if return_inferencedata and not extend_inferencedata:
return InferenceData()
elif return_inferencedata and extend_inferencedata:
return trace
return trace if idata is None else idata
return {}

vars_in_trace = get_vars_in_point_list(_trace, model)
Expand Down
5 changes: 5 additions & 0 deletions tests/sampling/test_forward.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,11 @@ def test_normal_scalar(self):
ppc = pm.sample_posterior_predictive(trace, var_names=[], return_inferencedata=False)
assert len(ppc) == 0

# test empty ppc with extend_inferencedata
assert isinstance(trace, InferenceData)
ppc = pm.sample_posterior_predictive(trace, var_names=[], extend_inferencedata=True)
assert ppc is trace

# test keep_size parameter
ppc = pm.sample_posterior_predictive(trace, return_inferencedata=False)
assert ppc["a"].shape == (nchains, ndraws)
Expand Down
Loading