Skip to content

dask.array slice with da.from_array([0]) has incorrect shape #6709

@mgfinch

Description

@mgfinch

What happened:
I found an example of dask.array slice that has has incorrect shape assigned.
Although compute works correctly, the mismatch causes problems.
E.g. when I try to create another array with same chunks without computing the original one.

What you expected to happen:

  • In following example trouble_slice.shape and trouble_slice.compute().shape should be the same.
  • The da.from_array([[4, 4, 4]], chunks=trouble_slice.chunks) should work without raising ValueError

Minimal Complete Verifiable Example:

import dask.array as da

arr = da.from_array([[1, 2, 3], [4, 5, 6]])

# expected behavior
# shape match when I slice with [1]
ok_slice = arr[da.from_array([1])]
print(ok_slice.shape)  # (1, 3)
print(ok_slice.compute().shape)  # (1, 3)
# no problem creating another array of expected shape with same chunks
da.from_array([[4, 4, 4]], chunks=ok_slice.chunks)

print('--------------')

# what went wrong
# shape mismatch when I slice with [0]
trouble_slice = arr[da.from_array([0])]
print(trouble_slice.shape)  # (2, 3)
print(trouble_slice.compute().shape)  # (1, 3)
# probably due to shape mismatch demonstrated above following raises
# ValueError: Chunks do not add up to shape. Got chunks=((2,), (3,)), shape=(1, 3)
da.from_array([[4, 4, 4]], chunks=trouble_slice.chunks)

Anything else we need to know?:

Environment:

  • Dask version: 2.29.0
  • Python version: 3.7.5
  • Operating System: Ubuntu
  • Install method (conda, pip, source): pip

Metadata

Metadata

Assignees

No one assigned

    Labels

    arrayneeds attentionIt's been a while since this was pushed on. Needs attention from the owner or a maintainer.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions