Skip to content

BUG: pass sorted=False in unique_all, unique_counts, and unique_inverse#31323

Open
Jah-yee wants to merge 1 commit intonumpy:mainfrom
Jah-yee:fix/array-api-unique-sorted-false
Open

BUG: pass sorted=False in unique_all, unique_counts, and unique_inverse#31323
Jah-yee wants to merge 1 commit intonumpy:mainfrom
Jah-yee:fix/array-api-unique-sorted-false

Conversation

@Jah-yee
Copy link
Copy Markdown

@Jah-yee Jah-yee commented Apr 24, 2026

Summary

  • Pass sorted=False into np.unique from unique_all, unique_counts, and unique_inverse, matching the documented Array API contract and the existing unique_values implementation (see BUG: unique_all/counts/inverse source omits sorted=False despite docstring claim of equivalence #31241).
  • Add the test coverage that was requested in #31244:
    • test_unique_array_api_functions now uses np.unique(..., sorted=False, ...) as the reference, consistent with the docstrings.
    • test_array_api_unique_forwards_sorted_false patches unique and asserts the four unique_* helpers forward sorted=False, so a missing keyword would fail the test.

Note

Follow-up to #31244, with the tests maintainers asked for there.

A quick bit of context: a comment on a CPython PR is why my account was restricted on that project—I had a clumsy first try at a workflow that didn’t match what they want, and it read the wrong way. I’m not running automation against upstreams; these are one-off, small fixes on my own time, and I’m trying to be easy to review. I kept this change strictly to the sorted plumbing and tests. If anything still feels off, I’m happy to follow whatever process you prefer.

Closes #31241

- Match documented equivalence to np.unique(..., sorted=False) and unique_values
- Add mock-based test that asserts unique() is called with sorted=False
- Align test_unique_array_api_functions expectations with sorted=False

Closes numpy#31241

Made-with: Cursor
@Jah-yee
Copy link
Copy Markdown
Author

Jah-yee commented Apr 24, 2026

@seberg @ngoldbaum — pinging you both since you reviewed the earlier attempt in #31244: this follow-up is only the sorted=False change plus the tests you asked for (mock + aligned np.unique(..., sorted=False) expectations). The short note in the description is the context I wanted you to be able to skim in one pass.

Whenever one of you has a moment, I’d be grateful for a look—no rush. Thanks for maintaining NumPy.

@ngoldbaum
Copy link
Copy Markdown
Member

Note that this is an AI bot that will just reopen this PR if we close it. We should probably ban the github account, see python/cpython#148939

@Jah-yee
Copy link
Copy Markdown
Author

Jah-yee commented Apr 24, 2026

Note that this is an AI bot that will just reopen this PR if we close it. We should probably ban the github account, see python/cpython#148939

No I am not AI bot!
Please see my declaration and the changes I've made in this newly opened PR.
Thx.

@Jah-yee
Copy link
Copy Markdown
Author

Jah-yee commented Apr 24, 2026

Note that this is an AI bot that will just reopen this PR if we close it. We should probably ban the github account, see python/cpython#148939

No I am not AI bot! Please see my declaration and the changes I've made in this newly opened PR. Thx.

I would love to follow up on any potential changes I'll make to finish this PR ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: unique_all/counts/inverse source omits sorted=False despite docstring claim of equivalence

2 participants