Permalink
Browse files

BUG: Fix nanargmax/nanargmin for 1D integer arguments

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...
1 parent d46d268 commit 79a5cbac2d50b046f8dd41e006ebba21549ec9bc @shoyer shoyer committed Jan 10, 2014
View
3 RELEASE.rst
@@ -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
==============
View
2 bottleneck/src/template/func/nanargmax.py
@@ -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)
View
2 bottleneck/src/template/func/nanargmin.py
@@ -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)
View
2 bottleneck/tests/func_test.py
@@ -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):

0 comments on commit 79a5cba

Please sign in to comment.