-
-
Notifications
You must be signed in to change notification settings - Fork 12.6k
BUG: Fix new DTypes and new string promotion when signature is involved #26744
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
Changes from 1 commit
a4596d7
0b723bc
6347369
817c9e4
1d1c0c0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
Co-authored-by: Nathan Goldbaum <nathan.goldbaum@gmail.com>
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1028,9 +1028,9 @@ all_strings_promoter(PyObject *NPY_UNUSED(ufunc), | |
| PyArray_DTypeMeta *const signature[], | ||
| PyArray_DTypeMeta *new_op_dtypes[]) | ||
| { | ||
| if (op_dtypes[0] != &PyArray_StringDType && | ||
| op_dtypes[1] != &PyArray_StringDType && | ||
| op_dtypes[2] != &PyArray_StringDType) { | ||
| if ((op_dtypes[0] != &PyArray_StringDType && | ||
| op_dtypes[1] != &PyArray_StringDType && | ||
| op_dtypes[2] != &PyArray_StringDType)) { | ||
| /* | ||
| * This promoter was triggered with only unicode arguments, so use | ||
| * unicode. This can happen due to `dtype=` support which sets the | ||
|
|
@@ -1041,9 +1041,9 @@ all_strings_promoter(PyObject *NPY_UNUSED(ufunc), | |
| new_op_dtypes[2] = NPY_DT_NewRef(&PyArray_UnicodeDType); | ||
| return 0; | ||
| } | ||
| if (signature[0] == &PyArray_UnicodeDType && | ||
| signature[1] == &PyArray_UnicodeDType && | ||
| signature[2] == &PyArray_UnicodeDType) { | ||
| if ((signature[0] == &PyArray_UnicodeDType && | ||
| signature[1] == &PyArray_UnicodeDType && | ||
| signature[2] == &PyArray_UnicodeDType)) { | ||
| /* Unicode forced, but didn't override a string input: invalid */ | ||
| return -1; | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This part makes me wonder if I should just check it after the promoter is done and invalidate the result if this is violated. But it is OK here also.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree it would be better to enforce that there, if only because IMO DType authors shouldn't have to worry about that case or add code to account for it to write a correct DType.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indeed, it seems strange one would even get here if the signature is already clear that |
||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems confusing - should
StringDTypereally decide the result for something that does not include itself? Shouldn't that be up toUnicodeDType? What happens if we return -1 here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Things would just fail the operation, I am very sure I added it for a reason. The problem is that you would have to decide that
UU->Uis clearly better thanUU->T. But there is nothing to decide that by, so the machinery prefers the promoter, since the promoter has the ability to resolve which one to actual use (also go toUU->U).The other thing you might not like is that it matches at all, but that would need one of two new features (which is fine):
The other solution for the particular case is that if there wasn't legacy promotion involved, I would like a default promoter that ensures that
ufunc(..., dtype=X)will search forufunc(..., signature=(X, X, X))as well if there is otherwise no match. That would do the right thing here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was probably good to get this in, but it still feels weird to have a promotor for a given dtype return a result that does not involve that type at all - how can it decide for another type what is acceptable? Two of your solutions sound reasonable: returning the equivalent of
NotImplemented(your-1with no error set), or a default promotor. Maybe worth a new issue?