Repository navigation
Redesigned __setitem__ implementation - #7393
Conversation
|
These figures might help explain the approach. Thanks. |
Illviljan
left a comment
There was a problem hiding this comment.
Added a few more comments.
| True | ||
|
|
||
| """ | ||
| if not v.size: |
There was a problem hiding this comment.
The v.size seems to be breaking the doctests, because v=-99.
Is there supposed to be a v = np.asarray(v) before the check or are the doctests outdated and this function should only handle numpy arrays?
There was a problem hiding this comment.
Good spot. The examples are out of date, as v is now expected to be numpy array. I have updated docstring.
There was a problem hiding this comment.
It'd be good to include an asarray here or look for the attr size so that you can raise a sensible exception if v does not have size
There was a problem hiding this comment.
Hi @jsignell, I'm fine with putting in a v = np.asanyarray(v) into the first line of setitem, but as v is coming from the resolution of a dask key, is it not already guaranteed to a numpy array?
In the following:
('setitem-d7e36a', 0, 1): (setitem, ('array-836255', 0, 1), ('getitem-5ad1e3', 0, 0), [slice(2, 4, 1), slice(0, 4, 1)])('getitem-5ad1e3', 0, 0) "is" v.
Apologies if I've misunderstood!
There was a problem hiding this comment.
No you are right. I think I read too quickly.
| assert_eq(x, dx.compute()) | ||
|
|
||
|
|
||
| def test_setitem_extended_API_2d_02(): |
There was a problem hiding this comment.
Not a fan of the numbered function tests, but I can't figure out a much better alternative either. How about test_setitem_extended_API_2d_rhs_func_of_lhs?
There was a problem hiding this comment.
Agreed. Your suggestion is nice.
Co-authored-by: Illviljan <[email protected]>
|
Also @dask/array team, if folks are interested in well documented PRs around sub-array access and setting, this is for you :) |
Co-authored-by: Illviljan <[email protected]>
| return self._scalarfunc(complex) | ||
|
|
||
| def __index__(self): | ||
| return self._scalarfunc(int) |
There was a problem hiding this comment.
I haven't looked at the implementation, but this should probably be:
| return self._scalarfunc(int) | |
| return self._scalarfunc(operator.index) |
Unlike __int__, __index__ is not supposed to coerce non-integer values: https://docs.python.org/3/reference/datamodel.html#object.__index__
There was a problem hiding this comment.
Thanks, @shoyer - good call: "Presence of this method indicates that the numeric object is an integer type.", so I'll make the change you suggest.
|
Appears there are some merge conflicts |
|
Looks like they have to do with the new strict import order. @davidhassell please let me know if you'd like me to handle the conflicts. |
Hi @jsignell - Happy for you to look at this :) I had a naive had look, but just resolving the marked conflicts was not enough, and I wasn't sure it warranted updating my fork's branch with the latest master ...Certainly happy to take it further, though, if you like. |
|
Ok great! I just merged in main and updated one test that was failing since |
|
Ok thanks for the work here @davidhassell! I just merged this, so it'll be in main for a week or two and then go into the next release! |
|
🚀 Thank you all for the time taken to review and improve my code! |
|
cc @rgommers (for vis 🙂) |
|
This is an amazing PR, not only the added functionality but also the explanations of how things work under the hood and the figures in gh-7392. Thanks @davidhassell! |
black dask/flake8 daskflake8 gives:
dask/array/slicing.py:1532:5: F401 '..core.flatten' imported but unused, but I think that this is from elsewhere ... ?