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

Raise error when two coords with same underlying dimension are used #372

Merged
merged 3 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 5 additions & 0 deletions src/plopp/plotting/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,11 @@ def preprocess(
coords = [coords]
for dim in coords:
underlying = out.coords[dim].dims[-1]
if underlying in renamed_dims:
raise ValueError(
"coords: Cannot use more than one coordinate associated with"
nvaytet marked this conversation as resolved.
Show resolved Hide resolved
f"the same underlying dimension ({underlying})."
)
renamed_dims[underlying] = dim
out = out.rename_dims(**renamed_dims)
for n, coord in out.coords.items():
Expand Down
10 changes: 10 additions & 0 deletions tests/plotting/plot_2d_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,16 @@ def test_use_non_dimension_coords():
assert p.canvas.ymax == 3.3 * da.coords['yy'].max().value


def test_use_two_coords_for_same_underlying_dimension_raises():
da = data_array(ndim=2)
da.coords['a'] = da.coords['xx'] * 2
msg = "coords: Cannot use more than one coordinate"
with pytest.raises(ValueError, match=msg):
pp.plot(da, coords=['xx', 'a'])
with pytest.raises(ValueError, match=msg):
pp.plot(da, coords=['a', 'xx'])


@pytest.mark.parametrize('ext', ['jpg', 'png', 'pdf', 'svg'])
def test_save_to_disk_2d(ext):
da = data_array(ndim=2)
Expand Down