Skip to content

Commit

Permalink
Simplify nanarg{max,min}
Browse files Browse the repository at this point in the history
  • Loading branch information
shoyer committed Apr 23, 2015
1 parent 470ca5c commit 0e5bf2c
Showing 1 changed file with 2 additions and 14 deletions.
16 changes: 2 additions & 14 deletions numbagg/funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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


Expand Down

0 comments on commit 0e5bf2c

Please sign in to comment.