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

fix handling of default dims #2138

Merged
merged 4 commits into from
Oct 16, 2022
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* Fix bug with the dimension order dependency ([2103](https://github.com/arviz-devs/arviz/pull/2103))
* Add testing module for labeller classes ([2095](https://github.com/arviz-devs/arviz/pull/2095))
* Skip compression for object dtype while creating a netcdf file ([2129](https://github.com/arviz-devs/arviz/pull/2129))
* Fix issue in dim generation when default dims are present in user inputed dims ([2138](https://github.com/arviz-devs/arviz/pull/2138))

### Deprecation
* Removed `fill_last`, `contour` and `plot_kwargs` arguments from `plot_pair` function ([2085](https://github.com/arviz-devs/arviz/pull/2085))
Expand Down
3 changes: 2 additions & 1 deletion arviz/data/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ def generate_dims_coords(
dims = dims[:i]
break

for idx, dim_len in enumerate(shape):
for i, dim_len in enumerate(shape):
idx = i + len([dim for dim in default_dims if dim in dims])
if len(dims) < idx + 1:
dim_name = f"{var_name}_dim_{idx}"
dims.append(dim_name)
Expand Down
11 changes: 7 additions & 4 deletions arviz/tests/base_tests/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,20 +155,23 @@ def test_dims_coords():
assert len(coords["x_dim_2"]) == 5


def test_dims_coords_default_dims():
@pytest.mark.parametrize(
"in_dims", (["dim1", "dim2"], ["draw", "dim1", "dim2"], ["chain", "draw", "dim1", "dim2"])
)
def test_dims_coords_default_dims(in_dims):
shape = 4, 7
var_name = "x"
dims, coords = generate_dims_coords(
shape,
var_name,
dims=["dim1", "dim2"],
dims=in_dims,
coords={"chain": ["a", "b", "c"]},
default_dims=["chain", "draw"],
)
assert "dim1" in dims
assert "dim2" in dims
assert "chain" not in dims
assert "draw" not in dims
assert ("chain" in dims) == ("chain" in in_dims)
assert ("draw" in dims) == ("draw" in in_dims)
assert len(coords["dim1"]) == 4
assert len(coords["dim2"]) == 7
assert len(coords["chain"]) == 3
Expand Down