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
DescriptionReproducing 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)] Activityeric-wieser commented on Aug 7, 2018 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. eric-wieser commented on Aug 7, 2018 seberg commented on Aug 7, 2018 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.... ngoldbaum commented on Oct 12, 2026 I just opened #32991, which I think fixes the hang.
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|