From 79a5cbac2d50b046f8dd41e006ebba21549ec9bc Mon Sep 17 00:00:00 2001 From: Stephan Hoyer Date: Thu, 9 Jan 2014 18:12:08 -0800 Subject: [PATCH] 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). --- RELEASE.rst | 3 +++ bottleneck/src/template/func/nanargmax.py | 2 +- bottleneck/src/template/func/nanargmin.py | 2 +- bottleneck/tests/func_test.py | 2 ++ 4 files changed, 7 insertions(+), 2 deletions(-) diff --git a/RELEASE.rst b/RELEASE.rst index 34f86e06e7..62f7ee642f 100644 --- a/RELEASE.rst +++ b/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 ============== diff --git a/bottleneck/src/template/func/nanargmax.py b/bottleneck/src/template/func/nanargmax.py index 1c91d29a10..244101dcaa 100644 --- a/bottleneck/src/template/func/nanargmax.py +++ b/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) diff --git a/bottleneck/src/template/func/nanargmin.py b/bottleneck/src/template/func/nanargmin.py index c2dc2bd5f9..611f8a18fc 100644 --- a/bottleneck/src/template/func/nanargmin.py +++ b/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) diff --git a/bottleneck/tests/func_test.py b/bottleneck/tests/func_test.py index 0eb1f8494a..784f88ebae 100644 --- a/bottleneck/tests/func_test.py +++ b/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):