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 exception when using diff with a non-existent dimension #8962

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

nathanredmond
Copy link

Copy link

welcome bot commented Apr 22, 2024

Thank you for opening this pull request! It may take us a few days to respond here, so thank you for being patient.
If you have questions, some answers may be found in our contributing guidelines.

Copy link
Collaborator

@max-sixty max-sixty left a comment

Choose a reason for hiding this comment

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

Looks good @nathanredmond ! Thanks for your first PR!

@@ -3861,6 +3861,12 @@ def test_dataarray_diff_n1(self) -> None:
expected = DataArray(np.diff(da.values, axis=1), dims=["x", "y"])
assert_equal(expected, actual)

def test_dataarray_diff_dim_nonexist(self) -> None:
# uncomment this code for test corresponding to pushed changes
# with pytest.raises(KeyError, match=r"dim provided not present"):
Copy link
Collaborator

Choose a reason for hiding this comment

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

This can use pytest.warns

@@ -7726,6 +7726,7 @@ def diff(
n: int = 1,
*,
label: Literal["upper", "lower"] = "upper",
dims_found=False,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we need this? I think it can be defined inside the function

Comment on lines +39 to +41
- Fix for :py:meth:`DataSet.diff` and consequently :py:meth:`DataArray.diff` to
raise a KeyError when `diff` is parameterized with a dimension that does not
exist in callee's DataSet/DataArray. (:issue:`7748`)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is fine, though we can also simplify the language a bit — cut words like consequently / parameterized with!

@dcherian dcherian changed the title Addresses GH7748 Raise exception when using diff with a non-existent dimension Apr 22, 2024
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.

diff('non existing dimension') does not raise exception
3 participants