Skip to content

ENH: implement descending sorts for StringDType - #32286

Merged
MaanasArora merged 4 commits into
numpy:mainfrom
ngoldbaum:stringdtype-descending
Aug 14, 2026
Merged

ENH: implement descending sorts for StringDType#32286
MaanasArora merged 4 commits into
numpy:mainfrom
ngoldbaum:stringdtype-descending

Conversation

@ngoldbaum

Copy link
Copy Markdown
Member

PR summary

This implements support for descending sorts, following #31431 and #31345

Pretty straightforward! Mostly this is wiring things up.

Ping @MaanasArora I'd appreciate your opinion here.

AI Disclosure

I used an AI to help with the test and review my code.

@MaanasArora MaanasArora left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks @ngoldbaum, looks good! I was half-hoping we could keep reusing the default loops and maybe expand the static_data field to contain two PyArray_CompareFuncs, but I'm not entirely sure how that could be designed (though, an array of two seems reasonable honestly). If you think that's too out of scope or better for follow-up, completely happy to put this in as-is, just let me know and I'll merge!

@ngoldbaum

Copy link
Copy Markdown
Member Author

@MaanasArora thanks for the suggestion! I think this is simpler, let me know what you think.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

it turns out if you add a second release note with the same content as the first, towncrier generates a single entry that references both PRs.

Comment thread numpy/_core/src/common/npy_sort.c Outdated
switch (sort_params->flags) {
if (cmp == NULL) {
npy_gil_error(PyExc_ValueError,
"descending sort not supported for this DType");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can this not be ascending too?

@MaanasArora

Copy link
Copy Markdown
Contributor

Thanks @ngoldbaum, yes this looks great! Just an error handling change inline.

@MaanasArora

Copy link
Copy Markdown
Contributor

Thanks, LGTM now - will merge when CI passes!

@MaanasArora
MaanasArora merged commit 8e56e85 into numpy:main Aug 14, 2026
91 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants