Skip to content

Cpaniaguam/fix predictive idata to dataframe datatree#974

Closed
cpaniaguam wants to merge 8 commits into
970-compatibility-with-pymc6from
cpaniaguam/fix-predictive_idata_to_dataframe-Datatree
Closed

Cpaniaguam/fix predictive idata to dataframe datatree#974
cpaniaguam wants to merge 8 commits into
970-compatibility-with-pymc6from
cpaniaguam/fix-predictive_idata_to_dataframe-Datatree

Conversation

@cpaniaguam

@cpaniaguam cpaniaguam commented Jun 3, 2026

Copy link
Copy Markdown
Collaborator

Add handling of inference data containers (az.InferenceData and xr.DataTree) in the codebase, increasing compatibility with different versions of ArviZ and supporting both data structures throughout the workflow. The changes include new utility methods for accessing and modifying inference data groups, refactoring of predictive sampling functions to use these utilities, and updates to utility functions and tests for consistency.

Inference Data Handling Improvements:

  • Added utility methods _get_idata_groups, _get_idata_group_dataset, and _set_idata_group_dataset to abstract group access and modification for both az.InferenceData and xr.DataTree, ensuring compatibility across ArviZ versions.
  • Refactored _drop_parent_str_from_idata to use the new group access utilities, and updated its type hints to support both az.InferenceData and xr.DataTree.

Predictive Sampling Refactor:

  • Updated sample_prior_predictive and sample_do methods to use the new group access utilities when renaming dimensions and variables, improving code clarity and compatibility. [1] [2]
  • Modified sample_posterior_predictive to use the new _get_idata_groups utility for checking group existence.

Utility Function Updates:

  • Updated predictive_idata_to_dataframe to accept both az.InferenceData and xr.DataTree, and handle group data extraction accordingly. [1] [2] [3]

Testing:

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR extends HSSM’s inference-data handling to support both arviz.InferenceData and xarray.DataTree, aiming to keep predictive sampling and downstream utilities working across ArviZ container variants/versions.

Changes:

  • Added helper methods in HSSM to abstract inference-data group enumeration, dataset access, and dataset replacement.
  • Refactored predictive sampling paths (sample_prior_predictive, sample_do, and a posterior_predictive group check) to use the new helpers.
  • Updated predictive_idata_to_dataframe to accept az.InferenceData | xr.DataTree, and marked an RL likelihood-builder test as xfail due to upstream PyTensor changes.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
src/hssm/base.py Adds group-access helpers and refactors predictive code paths to use them for InferenceData/DataTree compatibility.
src/hssm/utils.py Extends predictive_idata_to_dataframe to handle predictive groups stored as xr.DataTree nodes.
tests/rl/test_rl_likelihood_builder.py Marks test_make_rl_logp_op as xfail due to upstream API breakage.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/hssm/base.py
Comment thread src/hssm/base.py Outdated
Comment thread src/hssm/base.py Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

Comment on lines +749 to +751
@pytest.mark.xfail(
reason="make_rl_logp_op is currently broken due to changes in PyTensor API and needs to be updated."
)
Comment thread src/hssm/base.py
self, idata: az.InferenceData | None
) -> az.InferenceData:
"""Drop the parent_str variable from an InferenceData object.
def _get_idata_groups(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand that you are trying to be backward-compatible here. However, there is no need. Arviz is no longer backward-compatible, so we are moving forward from InferenceData altogether. az.InferenceData doesn't really exist any more. I am surprised that we didn't get an error. Let's drop this layer of backward compatibility. This new version of HSSM should not support InferenceData

@cpaniaguam cpaniaguam closed this Jun 5, 2026
@cpaniaguam cpaniaguam deleted the cpaniaguam/fix-predictive_idata_to_dataframe-Datatree branch June 5, 2026 17:10
@digicosmos86

Copy link
Copy Markdown
Collaborator

@cpaniaguam no need for this to be closed. We still need to make these functions compatible with DataTree. Maybe you'll do this in another PR?

I actually don't really like these functions because they break wrappers and tend to break when breaking changes are introduced. Let's also think of ways to remove these functions. We might lose some functionalities but gain maintainability

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants