Skip to content

Expected behavior of dask.array.full() for non-scalar fill values? #6107

@Huite

Description

@Huite

What is the expected behavior for dask.array.full() for a non-scalar fill_value?

The numpy.full() signature in the documentation mentions "scalar" for fill_value.
https://docs.scipy.org/doc/numpy/reference/generated/numpy.full.html

However, it'll broadcast non-scalar values if it can:

a = np.full((3, 2), [1, 2])

Since dask.array.full() wraps this function, it works similarly:

import dask.array

a1 = dask.array.full((2, 3), [[1, 2, 3], [4, 5, 6]])
a1.compute()

The issue is that when the chunk sizes change, it won't work anymore, as it starts broadcasting per chunk:

a2 = dask.array.full((2, 3), [[1, 2, 3], [4, 5, 6]], chunks=(1, 3))
a2.compute()  # ValueError: could not broadcast input array from shape (2,3) into shape (1,3)
a3 = dask.array.full((2, 3), [1, 2, 3], chunks=(1, 3))
a3.compute()

My feeling is that choosing different chunk sizes shouldn't lead to different behavior here. I think I'd prefer a ValueError for a non-scalar fill_value.

Metadata

Metadata

Assignees

No one assigned

    Labels

    arraygood first issueClearly described and easy to accomplish. Good for beginners to the project.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions