Skip to content

BUG: do not raise IndexError for identity slice in array.vindex - #3559

Merged
mrocklin merged 4 commits into
dask:masterfrom
stsievert:vindex-slicing
Jun 10, 2018
Merged

mrocklin merged 4 commits into
dask:masterfrom
stsievert:vindex-slicing

Conversation

@stsievert

Copy link
Copy Markdown
Member

This closes #3211. This PR ensures that x is x.vindex[:] for a Dask array x. This works for any identity indexing slice, not only 1D (e.g., x[:, :] or x[:, :, :]).

  • Tests added: test_vindex_identity.
    • This performs makes several assertions for two dimensions. I deliberately left this expanded for readability.
    • I test the edge cases: off by one (x[:n - 1] or x[1:]) and slices with a stride of 2 (x[0:n:2]).
  • Passes flake8 dask (well, warns on a bunch but not on this diff).

Comment thread dask/array/core.py
identity_slices = ((0, num_in_dim, 1) # i.e, x[:]
for num_in_dim in self.shape)
if all(slice_ == identity for slice_, identity in zip(slices, identity_slices)):
return self

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.

Perhaps inline identity_slices here?

if all(slc == slice(0, d) for slc, d in zip(slices, self.shape)):
   ...

This might reduce cognitive load from future readers a bit, rather than have to cross check against the variable definition above.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Nice. That helps makes the code simpler.

a, b = 10, 20

x = rng.random(a, chunks=a // 2)
assert x is x.vindex[:]

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.

Can we also test x.vindex[:10] here for completeness?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Good catch.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Good catch.

@mrocklin

mrocklin commented Jun 7, 2018

Copy link
Copy Markdown
Member

A couple tiny style comments, but otherwise this looks good to me. Thanks @stsievert !

@mrocklin

mrocklin commented Jun 8, 2018

Copy link
Copy Markdown
Member

ping

@stsievert

Copy link
Copy Markdown
Member Author

Updated. Thanks for the review.

@mrocklin

Copy link
Copy Markdown
Member

Fixes #3211

@mrocklin
mrocklin merged commit 946832f into dask:master Jun 10, 2018
@mrocklin

Copy link
Copy Markdown
Member

This is in. Thanks @stsievert !

@stsievert
stsievert deleted the vindex-slicing branch June 10, 2018 14:45
convexset added a commit to convexset/dask that referenced this pull request Jun 12, 2018
* master:
  [array.linalg.qr] added sfqr (short-and-fat) as a counterpart to tsqr… (dask#3575)
  Drop Dask Array's `learn` module (dask#3580)
  Adds `isneginf` and `isposinf` (dask#3581)
  Update sizeof definitions (dask#3582)
  BUG: do not raise IndexError for identity slice in array.vindex (dask#3559)
  Correct internal dimension of Dask's SVD (dask#3517)
  Fix check in configuration with env=None (dask#3562)
  Dataframe sample method docstring fix (dask#3566)
  Include "region" in key names for da.store (dask#3540)

# Conflicts:
#	dask/array/linalg.py
#	dask/array/tests/test_linalg.py
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.

Dask Array vindex doesn't allow identity

2 participants