nanargmin broken when using axis kwarg #3030

dopplershift opened this Issue Feb 28, 2013 · 2 comments


None yet

2 participants


The following snippet was broken by commit 8362e08:

import numpy as np
np.nanargmin(np.array([['nan', 'nan'], [1, 2]], dtype=np.float), axis=1)

Before the change this would yield

[-9223372036854775808                    0]

Now this raises a ValueError:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/foo/.local/lib/python2.7/site-packages/numpy/lib/", line 1564, in nanargmin
    return _nanop(np.argmin, np.inf, a, axis)
  File "/home/foo/.local/lib/python2.7/site-packages/numpy/lib/", line 1400, in _nanop
    res[mask_all_along_axis] = np.nan
ValueError: cannot convert float NaN to integer

This is very likely a re-incarnation of bug #643 in some form, but I'm opening separately since this was working up until a month ago.

charris commented Feb 28, 2013

The problem is that the functions return nan for an all nan row (or column or ...) and argmin etc return integers, and nans can't be cast to integers. What should we do in this case? Using nan as an integer type didn't make sense in the first place (what were they thinking?), but if you raise this issue on the list perhaps folks can agree on a solution.

charris commented Feb 15, 2014

This now raises ValueError: All-NaN slice encountered. Folks didn't like the idea of returning the minimum possible (negative) index value as an error, which was the other possibility. Returning something like -1 was not acceptable as -1 is a valid index in most cases.

@charris charris closed this Feb 15, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment