Skip to content

Keep DataArray inputs as is in from_dict and dict_to_dataset - #231

Merged
aloctavodia merged 1 commit into
arviz-devs:mainfrom
raashish1601:fix/146-from-dict-dataarray
Oct 10, 2026
Merged

aloctavodia merged 1 commit into
arviz-devs:mainfrom
raashish1601:fix/146-from-dict-dataarray

Conversation

@raashish1601

Copy link
Copy Markdown
Contributor

Closes #146

from_dict (through dict_to_dataset and ndarray_to_dataarray) treated xarray.DataArray values like plain arrays and relabelled their dims, so a channel dim became alpha_dim_0.

Following the approach discussed in the issue, ndarray_to_dataarray now returns DataArray inputs as they are, so their dims and coords are kept. That covers dicts with only DataArrays and dicts that mix DataArrays and ndarrays. As noted in the issue, dims, coords and sample_dims are not applied to DataArray inputs, and the docstrings of ndarray_to_dataarray, dict_to_dataset and from_dict now say so. ndarray inputs are handled as before.

Tests: added test_ndarray_to_dataarray_keeps_dataarray and test_dict_to_dataset_mixed_dataarray_and_ndarray in tests/test_base.py, and test_from_dict_keeps_dataarray_dims (the example from the issue) in tests/test_io_dict.py. All three fail on main. The full test suite passes locally, and the pre-commit hooks (ruff, mypy, pylint, docstub) pass on the changed files.

@read-the-docs-community

Copy link
Copy Markdown

@raashish1601

Copy link
Copy Markdown
Contributor Author

The failing ExternalTests Python_312_Special_versions job is not from this change. The same 3 cmdstanpy tests fail on main since build 7718 (2026-09-25) with TypeError: CmdStanMCMC.__init__() takes 1 positional argument but 2 were given in external_tests/test_cmdstanpy.py:153, which looks like a cmdstanpy API change in the test fixture.

@aloctavodia
aloctavodia merged commit b87afe3 into arviz-devs:main Oct 10, 2026
5 of 7 checks passed
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.

az.from_dict ignores datarray dims

2 participants