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 issue when coords for default dims are provided #2001

Merged
merged 2 commits into from
Mar 21, 2022
Merged
Changes from 1 commit
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
6 changes: 5 additions & 1 deletion arviz/data/base.py
Original file line number Diff line number Diff line change
@@ -157,7 +157,11 @@ def generate_dims_coords(
dim_name = dims[idx]
if dim_name not in coords:
coords[dim_name] = np.arange(index_origin, dim_len + index_origin)
coords = {key: coord for key, coord in coords.items() if any(key == dim for dim in dims)}
coords = {
key: coord
for key, coord in coords.items()
if any(key == dim for dim in dims + default_dims)
}
return dims, coords


20 changes: 20 additions & 0 deletions arviz/tests/base_tests/test_data.py
Original file line number Diff line number Diff line change
@@ -150,6 +150,26 @@ def test_dims_coords():
assert len(coords["x_dim_2"]) == 5


def test_dims_coords_default_dims():
shape = 4, 7
var_name = "x"
dims, coords = generate_dims_coords(
shape,
var_name,
dims=["dim1", "dim2"],
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 len(coords["dim1"]) == 4
assert len(coords["dim2"]) == 7
assert len(coords["chain"]) == 3
assert "draw" not in coords


def test_dims_coords_extra_dims():
shape = 4, 20
var_name = "x"