Skip to content

Commit

Permalink
BUG: Fix nanargmax/nanargmin for 1D integer arguments
Browse files Browse the repository at this point in the history
These functions should return the argument of the *first* max/min value (like
numpy). This was not the case in the current release, since there is special
logic for 1D integer arrays (they are iterated through forwards instead of
backwards like all other array types).
  • Loading branch information
shoyer committed Jan 10, 2014
1 parent d46d268 commit 79a5cba
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 2 deletions.
3 changes: 3 additions & 0 deletions RELEASE.rst
Expand Up @@ -11,6 +11,9 @@ Bottleneck 0.8.0

*Release date: Not yet released, in development*

**Bug fixes**

- nanargmax/nanargmin wrong for redundant max/min values in 1d int arrays

Older versions
==============
Expand Down
2 changes: 1 addition & 1 deletion bottleneck/src/template/func/nanargmax.py
Expand Up @@ -98,7 +98,7 @@ def NAME_NDIMd_DTYPE_axisAXIS(np.ndarray[np.DTYPE_t, ndim=NDIM] a):
amax = MINDTYPE
for iINDEX0 in range(nINDEX0):
ai = a[INDEXALL]
if ai >= amax:
if ai > amax:
amax = ai
idx = iINDEX0
return np.intp(idx)
Expand Down
2 changes: 1 addition & 1 deletion bottleneck/src/template/func/nanargmin.py
Expand Up @@ -98,7 +98,7 @@ def NAME_NDIMd_DTYPE_axisAXIS(np.ndarray[np.DTYPE_t, ndim=NDIM] a):
amin = MAXDTYPE
for iINDEX0 in range(nINDEX0):
ai = a[INDEXALL]
if ai <= amin:
if ai < amin:
amin = ai
idx = iINDEX0
return np.intp(idx)
Expand Down
2 changes: 2 additions & 0 deletions bottleneck/tests/func_test.py
Expand Up @@ -27,6 +27,8 @@ def arrays(dtypes=bn.dtypes, nans=True):
a = a.reshape(shape)
yield a
yield -a
# nanargmax/nanargmin regression tests
yield np.zeros_like(a)
if issubclass(a.dtype.type, np.inexact):
if nans:
for i in range(a.size):
Expand Down

0 comments on commit 79a5cba

Please sign in to comment.