Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

BUG: fixes for StringDType/unicode promoters#27636

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
ngoldbaum merged 4 commits intonumpy:mainfromngoldbaum:fix-stringdtype-promoters
Oct 30, 2024

Conversation

ngoldbaum
Copy link
Member

@ngoldbaumngoldbaum commentedOct 24, 2024
edited
Loading

Fixes#27493.Fixes#27637.

There are a number of missing cases for mixed unicode/string operations that this adds promoters for. Also adds tests for these cases.

Additionally replaces uses ofPy_None as an abstract promoter target withPyArray_IntAbstractDType, which makes the promoters fire less offten in unintended cases and is closer to the intention in the code.

Also fixes issues with the python wrappers for the string ufuncs incorrectly selecting the fixed-width string branches for some signatures by relying onnp.result_type to check forStringDType inputs.

@ngoldbaum
Copy link
MemberAuthor

The latest version of this PR touches a lot of code that@lysnikolaou wrote in the python-level string ufunc wrappers so I'm giving him a ping in case he wants to take a look.

@ngoldbaum
Copy link
MemberAuthor

@jorenham if you're at all curious how NumPy handles ufunc type dispatching on the C side, this fixes an issue you spotted while playing with the type stubs.

jorenham reacted with eyes emoji

Copy link
Contributor

@mhvkmhvk left a comment

Choose a reason for hiding this comment

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

This looks good to me. While looking at the tests and also#27637, I did wonder whether you really want the output to beStringDType in something likereplace when what you started with was aU array. But I think it probably is just good to moving towardsStringDType by default.

@ngoldbaum
Copy link
MemberAuthor

@seberg would you mind taking a look at this? I value your sense of taste for the "right" way to make changes to numpy internals.

Copy link
Member

@sebergseberg left a comment
edited
Loading

Choose a reason for hiding this comment

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

Looks fine to me. I think there might be a whole in the logic forout=, but I am not sure it is worth digging deeper (as opposed to a follow-up, maybe when a bug is reported).

I would love to find a better story for this type of thing... The one story that I could potentially see is to make something like an abstract (doesn't need to be an actual thing could just be a tuple as inisinstance, but conceptually):

class StringOrUnicodeDType:

so that we could just addone promoter, but the promoter would be need to programmatically decide whether the result should be unicode or string.
(Similar to the "this dtype must occur", style of logic. But these ufuncs that include ints show that just a list of dtypes is not super helpful a such)

(Sorry, the changes look good to me, but I am not sure I am in the right state of mind for any inspiration, although I do suspect the tuple idea is about as good as it gets. Together with allowing a promoter to say "do not apply" it would go very far -- if we allow that, a promoter could even register everything, it would just not be friendly)

EDIT: I forgot to say thanks :), this is tricky stuff and looks good, just unfortunately verbose. And verbose isn't fully unintentionally, but it would be good to improve it.

@ngoldbaum
Copy link
MemberAuthor

Thanks! I agree there's definitely room for improvement here to make it less verbose. I also noticed while working on this that the use ofNone in the Unicode promoters makes them fire way too often (e.g. foradd andmultiply for purely numeric operands). We should fix that too.

I opened a followup issue about this:#27671

I'll go ahead and merge this.

seberg reacted with thumbs up emoji

@ngoldbaumngoldbaum merged commit3126b97 intonumpy:mainOct 30, 2024
67 checks passed
@charrischarris removed the 09 - Backport-CandidatePRs tagged should be backported labelOct 30, 2024
@seberg
Copy link
Member

@danish-circuit this PR doesn't have anything to do with typing. Please make a new issue with a full reproducer ideally.

danish-circuit reacted with thumbs up emoji

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

@sebergsebergseberg approved these changes

@mhvkmhvkmhvk approved these changes

Assignees
No one assigned
Labels
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

BUG: Operation spuriously returns a legacy string BUG: index string ufunc promoter issues
4 participants
@ngoldbaum@seberg@mhvk@charris

[8]ページ先頭

©2009-2025 Movatter.jp