numpy / numpy/numpy

np.choose does not work for a zero-length sequence

Open
#8,361 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
32.8k
Forks
12.8k
Avg merge
1d 7h
Merged PRs (30d)
197

Description

These all work:

>>> np.choose(np.ones(2, dtype=np.intp), np.zeros((5, 2)))
array([ 0.,  0.])
>>> np.choose(np.ones(1, dtype=np.intp), np.zeros((5, 1)))
array([ 0.])
>>> np.choose(np.ones(0, dtype=np.intp), np.zeros((5, 0)))
array([])

So why does this not? (I would expect the output in both cases to be array([]))

>>> np.choose(np.ones(0, dtype=np.intp), np.zeros((0, 5)))
ValueError: 0-length sequence.
>>> np.choose(np.ones(0, dtype=np.intp), np.zeros((0, 0)))
ValueError: 0-length sequence.

Is there anything semantically wrong in saying "from a set of no sequences, each containing 5 elements, pick the corresponding item from this set of no indices"?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the two failing np.choose examples and locating the np.choose implementation and its existing tests. The work is done when both zero-length cases return array([]) consistently with the working examples, with regression coverage for the behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
numpy, python
Domain
data
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
57/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.