Skip to content

Redesigned __setitem__ implementation - #7393

Merged
jsignell merged 61 commits into
dask:mainfrom
davidhassell:setitem_redesign
Apr 7, 2021
Merged

jsignell merged 61 commits into
dask:mainfrom
davidhassell:setitem_redesign

Conversation

@davidhassell

@davidhassell davidhassell commented Mar 15, 2021 •

Copy link
Copy Markdown
Contributor
  • Closes Redesigned __setitem__ implementation #7392
  • Tests added / passed
  • Passes black dask / flake8 dask
    flake8 gives: dask/array/slicing.py:1532:5: F401 '..core.flatten' imported but unused, but I think that this is from elsewhere ... ?

@davidhassell

Copy link
Copy Markdown
Contributor Author

These figures might help explain the approach. Thanks.

@Illviljan Illviljan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Added a few more comments.

Comment thread dask/array/slicing.py Resolved
Comment thread dask/array/slicing.py
True

"""
if not v.size:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good spot. The examples are out of date, as v is now expected to be numpy array. I have updated docstring.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

No you are right. I think I read too quickly.

Comment thread dask/array/tests/test_array_core.py Outdated
assert_eq(x, dx.compute())


def test_setitem_extended_API_2d_02():

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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?

@davidhassell davidhassell Mar 29, 2021 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agreed. Your suggestion is nice.

Comment thread dask/array/slicing.py Resolved
@mrocklin

Copy link
Copy Markdown
Member

cc @shoyer and @dcherian if you all are interested this could use review from folks like you :)

@mrocklin

Copy link
Copy Markdown
Member

Also @dask/array team, if folks are interested in well documented PRs around sub-array access and setting, this is for you :)

Comment thread dask/array/core.py Outdated
return self._scalarfunc(complex)

def __index__(self):
return self._scalarfunc(int)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I haven't looked at the implementation, but this should probably be:

Suggested change
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__

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

@jakirkham

Copy link
Copy Markdown
Member

Appears there are some merge conflicts

@jsignell

jsignell commented Apr 5, 2021

Copy link
Copy Markdown
Member

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.

@davidhassell

Copy link
Copy Markdown
Contributor Author

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.

@github-actions github-actions Bot added the array label Apr 7, 2021
@jsignell

jsignell commented Apr 7, 2021

Copy link
Copy Markdown
Member

Ok great! I just merged in main and updated one test that was failing since assert_eq does a better job of type checking now :)

@jsignell
jsignell merged commit a199302 into dask:main Apr 7, 2021
@jsignell

jsignell commented Apr 7, 2021

Copy link
Copy Markdown
Member

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!

@davidhassell

Copy link
Copy Markdown
Contributor Author

🚀 Thank you all for the time taken to review and improve my code!

@jakirkham

Copy link
Copy Markdown
Member

cc @rgommers (for vis 🙂)

@rgommers

Copy link
Copy Markdown
Contributor

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Redesigned __setitem__ implementation

8 participants