Skip to content

Conversation

@nvaytet
Copy link
Member

@nvaytet nvaytet commented Jun 18, 2025

Fixes #458

@nvaytet nvaytet requested a review from Copilot June 18, 2025 21:00
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes the issue where only one coordinate can be specified for 2D plots by updating test cases and refining coordinate processing in the plotting backend.

  • Updated tests to check proper error throwing when multiple coordinates for the same underlying dimension are provided.
  • Modified the coordinate handling in common.py to drop unused coordinates and manage underlying dimensions.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
tests/plotting/plot_2d_test.py Added parameterized tests to validate single and duplicate coords usage.
src/plopp/plotting/common.py Refactored coordinate validation and assignment logic to support the change.
Comments suppressed due to low confidence (1)

src/plopp/plotting/common.py:99

  • The removal of the explicit duplicate underlying coordinate check in the preprocess function (which formerly raised a ValueError) now relies on implicit behavior that leads to a KeyError in tests. Consider handling duplicate underlying dimensions explicitly to ensure consistent and clear error types throughout the API.
            if underlying in underlying_dims:

Copy link
Member

@jl-wynen jl-wynen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find the logic difficult to follow. But the tests pass, so I guess it's correct.

for c in set(coords) - dims:
if c not in da.coords:
raise ValueError(f"Specified coords do not exist: {c}")
underlying = da.coords[c].dims[-1]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does this only look at the last dim? Is this a general convention in Plopp?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think in Plopp and Scipp?
If you have a 2d coord, the convention is that it is associated with the last dim.

@nvaytet
Copy link
Member Author

nvaytet commented Jun 19, 2025

I find the logic difficult to follow. But the tests pass, so I guess it's correct.

Yes, on the train I thought that we should do it differently.
Maybe something like:

  • If coords is not None, rename dims with all the entries in the coords.
  • After that, drop all coords that are not dimension coords

Would that cover everything?

@nvaytet
Copy link
Member Author

nvaytet commented Jun 19, 2025

I find the logic difficult to follow. But the tests pass, so I guess it's correct.

That was also why I asked copilot for a review, to see if it could follow the logic...

@jl-wynen
Copy link
Member

* If coords is not None, rename dims with all the entries in the coords.

* After that, drop all coords that are not dimension coords

Would that cover everything?

Possibly. You'd need to still be careful around what to rename.

@nvaytet nvaytet merged commit e68a2ef into main Jun 20, 2025
4 checks passed
@nvaytet nvaytet deleted the coords-arg-fix branch June 20, 2025 07:55
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.

Using single name in coords arg for 2d plot raises

3 participants