Skip to content

API/BUG: array.map_blocks raises IndexError for 0-dim array #884

@sinhrks

Description

@sinhrks

I understand map_blocks can work for function which returns scalar as below.

import numpy as np
import dask.array as da

darr = da.from_array(np.array([1, 2, 3, 4]), chunks=2)

def f(x):
    return 1

darr.map_blocks(f).compute()
# array([1, 1])

However, it may raises IndexError in ufuncs, which returns 0-dim array. Should it be handled like scalar, or raise understandable error message?

darr.map_blocks(np.sum).compute()
# IndexError: tuple index out of range

def h(x):
    return np.array(1)

darr.map_blocks(h).compute()
# IndexError: tuple index out of range

# Specifying chunks doesn't solve the problem
darr.map_blocks(h, chunks=(1, )).compute()
# IndexError: tuple index out of range

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions