8000 WIP: handling of nan in unique, fixes #2111 by jaimefrio · Pull Request #5487 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

WIP: handling of nan in unique, fixes #2111 #5487

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

jaimefrio
Copy link
Member

Works for floats, but not for complex or structured dtypes

Works for floats, but not for complex or structured dtypes
@homu
Copy link
Contributor
homu commented Nov 14, 2016

☔ The latest upstream changes (presumably #7742) made this pull request unmergeable. Please resolve the merge conflicts.

# gh-2111: NaNs never compare equal, so they need special handling,
# but they always sort to the end
if issubclass(ar.dtype.type, np.inexact) and np.isnan(aux[-1]):
nanidx = np.searchsorted(aux, np.nan)
Copy link
Member
@mattip mattip Sep 23, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if you replace this with nanidx = np.nonzero(np.isnan(aux))[0] ?

Edit: ... and the next line with flag[nanindex[:-1] + 1] = False

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, that creates an intermediate array of the same size as aux, so it's O(n) in both space and time. The solution above is O(log n) in time and O(1) in space, so it will almost certainly have better performance. It could be argued that your proposed code may be more understandable to a beginner, but I don't think np.searchsorted should be considered advanced or obscure, and should be perfectly fine to use, especially in numpy's source code.

So I guess I like my code better... ;-)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mattip's solution has the benefit of working for all types. So maybe we want both?

@anirudh2290
Copy link
Member

@jaimefrio this is marked WIP and has been open for a while. Do you plan on returning to this ?

@charris
Copy link
Member
charris commented Dec 28, 2020

I'm going to close this, it is stalled and needs rebase. @jaimefrio Please make a new PR if you want to pursue this.

@charris charris closed this Dec 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants
0