-
-
Notifications
You must be signed in to change notification settings - Fork 1.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
Enable __setitem__ for dask versions that support it. #5174
Conversation
Hello @tammasloughran! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found: There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻 Comment last updated at 2021-05-01 11:11:23 UTC |
Looks good! Not sure whether there's a reasonable way of testing this... Are there any current tests for the error that break on the new version (i.e. because it doesn't raise an error)? |
I don't quite understand understand what you mean. Like this? |
Forgive me not being clear. The current test with the version check is great. And I hadn't realized there was a released dask version — even better that the test is already running on both versions of the code. |
Thanks @tammasloughran This is a great PR! |
Well... I see now there is also a duplicate test here, which fails when using the newer dask version. I don't understand why xarray goes to all the trouble of directly unit testing an external library. Makes more sense to me to only test the xarray wrapper for the dask functionality. I could add another version check there, or remove that test. What do you think? |
Co-authored-by: Maximilian Roos <5635139+max-sixty@users.noreply.github.com>
That's testing the |
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.
@tammasloughran, I left a few inline suggestions
After those two suggestions, let's merge? |
Co-authored-by: Anderson Banihirwe <axbanihirwe@ualr.edu>
Co-authored-by: Anderson Banihirwe <axbanihirwe@ualr.edu>
… version to '0' if dask is not installed.
@tammasloughran would be great to get this in by #5232 if you have any time, it's great work. I think it's fairly close to the tests passing. |
The errors seems unrelated? Seems to rather be a mismatch in the CI? A dask method
But those seems to have been removed in dask/distributed#4677. Further reading in dask/dask-yarn#147 (comment) |
Co-authored-by: Illviljan <14371165+Illviljan@users.noreply.github.com>
that seems to have been a conda issue (but it's gone now), and the remaining failure is a known flaky test, so CI looks good |
xarray/tests/test_dask.py
Outdated
if LooseVersion(dask.__version__) >= LooseVersion("2021.04.0+17"): | ||
arr = Variable(("x"), da.array([1, 2, 3, 4])) | ||
expected = Variable(("x"), da.array([99, 2, 3, 4])) | ||
arr[0] = 99 # Indexing by integers | ||
assert_identical(arr, expected) | ||
arr = Variable(("x"), da.array([1, 2, 3, 4])) | ||
expected = Variable(("x"), da.array([99, 99, 99, 4])) | ||
arr[2::-1] = 99 # Indexing by slices | ||
assert_identical(arr, expected) | ||
arr = Variable(("x"), da.array([1, 2, 3, 4])) | ||
expected = Variable(("x"), da.array([99, 99, 3, 99])) | ||
arr[[0, -1, 1]] = 99 # Indexing by a list of integers | ||
assert_identical(arr, expected) | ||
arr = Variable(("x"), da.array([1, 2, 3, 4])) | ||
expected = Variable(("x"), da.array([99, 99, 99, 4])) | ||
arr[np.arange(3)] = 99 # Indexing by a 1-d numpy array of integers | ||
assert_identical(arr, expected) | ||
arr = Variable(("x"), da.array([1, 2, 3, 4])) | ||
expected = Variable(("x"), da.array([1, 99, 99, 99])) | ||
arr[[False, True, True, True]] = 99 # Indexing by a list of booleans | ||
assert_identical(arr, expected) | ||
arr = Variable(("x"), da.array([1, 2, 3, 4])) | ||
expected = Variable(("x"), da.array([1, 99, 99, 99])) | ||
arr[np.arange(4) > 0] = 99 # Indexing by a 1-d numpy array of booleans | ||
assert_identical(arr, expected) | ||
arr = Variable(("x"), da.array([1, 2, 3, 4])) | ||
expected = Variable(("x"), da.array([99, 99, 99, 99])) | ||
arr[arr > 0] = 99 # Indexing by one broadcastable Array of booleans | ||
assert_identical(arr, expected) | ||
else: | ||
with pytest.raises(TypeError, match=r"stored in a dask array"): | ||
v[:1] = 0 |
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.
Nitpick: I was wondering if we could use @pytest.mark.parametrize
here to parametrize this test so as to avoid code duplication?
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.
I definitely agree, but I think I'd prioritize merging quickly. For a first PR, it's great code overall. We could add a TODO
to the current code so it doesn't look like best practice to the next person.
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.
I concur...
@tammasloughran this just needs a whatsnew now! |
Excellent — thank you @tammasloughran ! |
The basics seem to work for me with just these changes. But I haven't tested much to see if it plays nicely with the rest of xarray. Looks like dask's item assignment is still mostly limited to 1D arrays and slices of multi dimensional arrays—no fancy stuff.