| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
|
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. |
Sorry, something went wrong.
|
@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. |
Sorry, something went wrong.
There was a problem hiding this comment.
This looks good to me. While looking at the tests and also #27637, I did wonder whether you really want the output to be StringDType in something like replace when what you started with was a U array. But I think it probably is just good to moving towards StringDType by default.
Sorry, something went wrong.
|
@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. |
Sorry, something went wrong.
There was a problem hiding this comment.
Looks fine to me. I think there might be a whole in the logic for out=, 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 in isinstance, but conceptually):
class StringOrUnicodeDType:
so that we could just add one 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.
Sorry, something went wrong.
|
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 of None in the Unicode promoters makes them fire way too often (e.g. for add and multiply for purely numeric operands). We should fix that too. I opened a followup issue about this: #27671 I'll go ahead and merge this. |
Sorry, something went wrong.
|
@danish-circuit this PR doesn't have anything to do with typing. Please make a new issue with a full reproducer ideally. |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
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 of Py_None as an abstract promoter target with PyArray_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 on np.result_type to check for StringDType inputs.