arviz_base.convert_to_dataset#
- arviz_base.convert_to_dataset(obj, *, group='posterior', **kwargs)[source]#
Convert a supported object to an xarray.Dataset.
This function is idempotent: if you pass in an xarray.Dataset, it returns it unchanged. If passed another supported object (e.g., dict, DataTree, numpy array), it will be converted to a Dataset via
convert_to_datatree
, and the specified group will be extracted.- Parameters:
- obj
Any
A supported object to convert to InferenceData. See
convert_to_datatree
for full list.- group
str
,default
“posterior” The group name to extract from the converted DataTree.
- **kwargs
Additional arguments passed to
convert_to_datatree
.
- obj
- Returns:
xarray.Dataset
The extracted dataset from the converted object.
- Raises:
ValueError
If the group cannot be extracted from the resulting DataTree.
Examples
>>> convert_to_dataset({"mu": np.random.randn(500)}) <xarray.Dataset> ... # Posterior group with 'mu' variable