GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — `numpy.take` with non-empty `indices` from an empty axis should fail · Issue #11677 · numpy/numpy

numpy.take with non-empty indices from an empty axis should fail #11677

New issue
Copy link
New issue
Copy link
Open
Open
numpy.take with non-empty indices from an empty axis should fail#11677
Copy link
Labels
00 - Bug

Description

@toslunar
toslunar
opened on Aug 6, 2018
Issue body actions

Reproducing code example:

import numpy as np
np.take(np.empty((0, 0)), [1], axis=0, mode='wrap')

does not return (probably causing an infinite-loop).

The message

>>> np.take(np.empty((0, 0)), [1], axis=0)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/tos/GitHub/numpy/numpy/core/fromnumeric.py", line 181, in take
    return _wrapfunc(a, 'take', indices, axis=axis, out=out, mode=mode)
  File "/Users/tos/GitHub/numpy/numpy/core/fromnumeric.py", line 51, in _wrapfunc
    return getattr(obj, method)(*args, **kwds)
IndexError: index 1 is out of bounds for size 0

is different from the message

>>> np.take(np.empty((0,)), [1], axis=0)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/tos/GitHub/numpy/numpy/core/fromnumeric.py", line 181, in take
    return _wrapfunc(a, 'take', indices, axis=axis, out=out, mode=mode)
  File "/Users/tos/GitHub/numpy/numpy/core/fromnumeric.py", line 51, in _wrapfunc
    return getattr(obj, method)(*args, **kwds)
IndexError: cannot do a non-empty take from an empty axes.

To produce the latter message, the size of the output array is checked. Instead the size of the indices could be checked.

Numpy/Python version information:

1.16.0.dev0+9d0225b 3.7.0 (default, Jun 29 2018, 20:13:13)
[Clang 9.1.0 (clang-902.0.39.2)]

Activity

  1. eric-wieser
    added
    00 - Bug
    on Aug 7, 2018
  2. eric-wieser commented on Aug 7, 2018

    @eric-wieser
    eric-wieser
    on Aug 7, 2018
    Member
    More actions

    Relatedly:

    In [2]: np.take(np.empty((0, 0)), [1], axis=0)
    IndexError: index 1 is out of bounds for size 0
    
    In [3]: np.take(np.empty((0, 0)), [1], axis=1)
    Out[3]: array([], shape=(0, 1), dtype=float64)
    

    We need to decide whether the first or second result is correct here.

  3. eric-wieser commented on Aug 7, 2018

    @eric-wieser
    eric-wieser
    on Aug 7, 2018
    Member
    More actions

    @seberg, this looks like a missed case from #3002 (230ee3a)

  4. seberg commented on Aug 7, 2018

    @seberg
    seberg
    on Aug 7, 2018
    Member
    More actions

    Guess so, but don't really recall. My feeling is that the error makes much more sense (also the out of bounds is nicer then the "cannot do empty" but practicality probably beats purity, and wrap/clip modes cannot raise the normal error).
    But, to be safe, could do a DeprecationWarning I guess. Though it seems like one of those less likely things to be abused.

    EDIT: Since NumPy used to be a bit less consistent with these things. It is plausible that I was trying to mimic what was there before and not introduce deprecations....

  5. ngoldbaum commented on Oct 12, 2026

    @ngoldbaum
    ngoldbaum
    on Oct 12, 2026
    Member
    More actions

    I just opened #32991, which I think fixes the hang.

  6. RECHE23
    added a commit that references this issue on Nov 4, 2026

    fix(python): NumPy's answers found by a differential fuzz; native take

    6879bba
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    00 - Bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.