-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
base: main
Are you sure you want to change the base?
Conversation
Thank you for opening this pull request! It may take us a few days to respond here, so thank you for being patient. |
There was a problem hiding this 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"): |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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
- 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`) |
There was a problem hiding this comment.
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
!
diff
with a non-existent dimension
whats-new.rst