Skip to content

unique doesn't necessarily return in ascending order #42

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
davidackerman opened this issue May 28, 2025 · 2 comments
Closed

unique doesn't necessarily return in ascending order #42

davidackerman opened this issue May 28, 2025 · 2 comments
Labels
bug Something isn't working

Comments

@davidackerman
Copy link

davidackerman commented May 28, 2025

Thanks for the code, I use it all the time!

I've noticed that generally fastremap.unique returns ids in order, but sometimes this is not the case. See below:

import numpy as np
import fastremap
data = np.array([1704, 1704, 1704, 1704, 1704, 1704, 1704, 1704, 1704, 1704, 1704,
       1704, 1704, 1704, 1704, 1704, 1704,  106,  106,  106,  106,  106,
        106,  106,  106,  106,  106,  106,  106,  106,  106,  106,  106,
        106,  106,  106,  106,  106,  106,  106,  106,  106,  106,  106,
        106,  106,  106,  106,  106,  106,  106,  106,  106,  106,  106,
        106,  106,  106,  106,  106,  106,  106,  106,  106,  106,  106,
        106,  106,  106,  106,  106,  106,  106,  106,  106,  106,  106,
        106,  106,  106,  106,  106,  106,  106,  106,  106,  106,  106,
        106, 1704, 1704, 1704, 1704, 1704, 1704, 1704, 1704, 1704, 1704,
       1704, 1704, 1704, 1704, 1704, 1704, 1704, 1704, 1704, 1704, 1704,
       1704, 1704, 1704, 1704, 1704, 1704, 1704, 1704, 1704, 1704, 1704,
       1704, 1704, 1704, 1704, 1704, 1704, 1704, 1704, 1704, 1704, 1704,
       1704, 1704, 1704, 1704, 1704, 1704, 1704, 1704, 1704, 1704, 1704,
       1704, 1704, 1704, 1704, 1704, 1704, 1704, 1704, 1704, 1704, 1704,
       1704, 1704, 1704, 1704, 1704, 1704, 1704, 1704, 1704, 1704, 1704,
       1704, 1704, 1704, 1704, 1704, 1704, 1704, 1704, 1704, 1704, 1704,
       1704, 1704, 1704, 1704, 1704,  106,  106,  106,  106,  106,  106,
        106,  106,  106,  106,  106,  106,  106,  106,  106,  106,  106,
        106,  106,  106,  106,  106,  106,  106,  106,  106,  106,  106,
        106,  106,  106,  106,  106,  106,  106,  106,  106,  106,  106,
        106,  106,  106,  106,  106,  106,  106,  106,  106,  106,  106,
        106,  106,  106,  106,  106,  106,  106,  106,  106,  106,  106,
        106,  106,  106,  106,  106,  106,  106,  106,  106,  106,  106,
        106, 1704, 1704, 1704, 1704, 1704, 1704, 1704, 1704, 1704, 1704,
       1704, 1704, 1704, 1704, 1704, 1704, 1704, 1704, 1704, 1704, 1704,
       1704, 1704, 1704, 1704, 1704, 1704, 1704, 1704, 1704, 1704, 1704,
       1704, 1704, 1704, 1704, 1704, 1704, 1704, 1704, 1704, 1704, 1704,
       1704, 1704, 1704,  106,  106,  106,  106,  106,  106,  106,  106,
        106,  106,  106,  106,  106,  106,  106,  106,  106,  106,  106,
        106,  106,  106,  106,  106,  106,  106,  106,  106,  106,  106,
        106,  106,  106,  106,  106,  106,  106,  106,  106,  106,  106,
        106,  106,  106,  106,  106,  106,  106,  106,  106,  106,  106,
        106,  106,  106,  106,  106,  106,  106,  106,  106,  106,  106,
        106,  106,  106,  106,  106,  106,  106,  106,  106,  106,  106,
        106,  106,  106,  106,  106,  106,  106,  106,  106,  106,  106,
        106,  106,  106,  106,  106,  106,  106,  106,  106,  106,  106,
        106,  106,  106,  106,  106,  106,  106,  106,  106,  106,  106,
        106,  106,  106,  106,  106,  106,  106,  106,  106,  106,  106,
        106,  106,  106,  106,  106,  106,  106,  106,  106,  106,  106,
        106,  106,  106,  106,  106,  106,  106,  106,  106,  106,  106,
        106,  106,  106,  106,  106,  106,  106,  106,  106,  106,  106,
        106,  106,  106,  106,  106,  106,  106,  106,  106,  106,  106,
        106,  106,  106,  106,  106,  106,  106,  106,  106,  106,  106,
        106,  106,  106,  106,  106,  106,  106,  106,  106,  106,  106,
        106,  106,  106,  106,  106,  106,  106,  106,  106,  106,  106,
        106,  106,  106,  106,  106,  106,  106,  106,  106,  106,  106,
        106,  106,  106,  106,  106,  106,  106,  106,  106,  106,  106,
        106,  106,  106,  106,  106,  106,  106,  106,  106,  106,  106,
        106,  106,  106,  106,  106,  106,  106,  106,  106,  106,  106,
        106,  106,  106,  106,  106,  106,  106,  106,  106,  106,  106,
        106,  106,  106,  106,  106,  106,  106,  106,  106,  106,  106,
        106,  106,  106,  106,  106,  106,  106,  106,  106,  106,  106,
        106,  106,  106,  106,  106,  106,  106,  106,  106,  106,  106,
        106,  106,  106,  106,  106,  106,  106,  106,  106,  106,  106,
        106,  106,  106,  106,  106,  106,  106,  106,  106,  106,  106,
        106,  106,  106,  106,  106,  106,  106,  106,  106,  106,  106,
        106,  106,  106,  106,  106,  106,  106,  106,  106,  106,  106,
        106,  106,  106,  106,  106,  106,  106,  106,  106,  106,  106,
        106,  106,  106,  106,  106,  106,  106,  106,  106,  106,  106,
        106,  106,  106,  106,  106,  106,  106, 1873,  106,  106,  106,
        106,  106,  106,  106,  106,  106,  106,  106,  106,  106,  106,
        106,  106,  106,  106,  106,  106,  106,  106,  106,  106,  106,
        106,  106,  106,  106,  106,  106,  106,  106,  106,  106,  106,
        106,  106,  106,  106, 1873, 1873,  106,  106,  106,  106,  106,
        106,  106,  106,  106,  106,  106,  106,  106,  106,  106,  106,
        106,  106,  106,  106,  106,  106,  106,  106,  106,  106,  106,
        106,  106,  106,  106,  106,  106,  106,  106,  106,  106,  106,
        106, 1873, 1873,  106,  106,  106,  106,  106,  106,  106,  106,
        106,  106,  106,  106,  106,  106,  106])
print(fastremap.unique(data))

returns [1704 106 1873]

@william-silversmith william-silversmith added the bug Something isn't working label May 28, 2025
@william-silversmith
Copy link
Contributor

Hi thanks for the kind words! I think what's happening is that when it takes the "unique by renumbering" path, it is sorted and then gets mapped back to the original labels. I've added a second round of sorting to fix that.

@davidackerman
Copy link
Author

thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy