From 0e5bf2c65fb3965ab373ab0d26d354ce65aad48e Mon Sep 17 00:00:00 2001 From: Stephan Hoyer Date: Wed, 22 Apr 2015 20:02:45 -0700 Subject: [PATCH] Simplify nanarg{max,min} --- numbagg/funcs.py | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/numbagg/funcs.py b/numbagg/funcs.py index 2e2dbdd..c3ccf0d 100644 --- a/numbagg/funcs.py +++ b/numbagg/funcs.py @@ -106,15 +106,9 @@ def nanargmax(a): # for "not found" (pandas uses the same convention) idx = -1 for i, ai in enumerate(a.flat): - if ai > amax: + if ai > amax or (idx == -1 and not np.isnan(ai)): amax = ai idx = i - if idx == -1: - # take another pass to look for -infty - for i, ai in enumerate(a.flat): - if ai == amax: - idx = i - break return idx @@ -123,15 +117,9 @@ def nanargmin(a): amin = np.infty idx = -1 for i, ai in enumerate(a.flat): - if ai < amin: + if ai < amin or (idx == -1 and not np.isnan(ai)): amin = ai idx = i - if idx == -1: - # take another pass to look for +infty - for i, ai in enumerate(a.flat): - if ai == amin: - idx = i - break return idx