Skip to content

dask.array.choose() fails when the choice is trivial #11980

@rossjjennings

Description

@rossjjennings

Describe the issue:
If dask.array.choose() is used in the trivial case where there is only one choice, it returns NotImplemented. This behavior differs from Numpy's version, which keeps working just fine in this case (see example below).

Minimal Complete Verifiable Example:

import numpy as np
import dask.array as da

indices = np.array([0, 0, 0, 0])
choices = (np.array([10., 20., 30., 40.]),)
print(np.choose(indices, choices))

indices = da.array([0, 0, 0, 0])
choices = (da.array([10., 20., 30., 40.]),)
print(da.choose(indices, choices))

The Numpy portion prints the correct result ([10., 20., 30., 40.]), but the Dask portion prints NotImplemented.

Anything else we need to know?:
This example may seem useless, but this originally came up in a context where the number of choices is dynamic, and it is important to retain the correct behavior when there is only one choice.

Environment:

  • Dask version: 2025.5.1
  • Python version: Python 3.12
  • Operating System: Ubuntu 24.04
  • Install method (conda, pip, source): conda

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs triageNeeds a response from a contributor

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions