@@ -1028,6 +1028,25 @@ all_strings_promoter(PyObject *NPY_UNUSED(ufunc),
1028
1028
PyArray_DTypeMeta *const signature[],
1029
1029
PyArray_DTypeMeta *new_op_dtypes[])
1030
1030
{
1031
+ if (op_dtypes[0 ] != &PyArray_StringDType &&
1032
+ op_dtypes[1 ] != &PyArray_StringDType &&
1033
+ op_dtypes[2 ] != &PyArray_StringDType) {
1034
+ /*
1035
+ * This promoter was triggered with only unicode arguments, so use
1036
+ * unicode. This can happen due to `dtype=` support which sets the
1037
+ * output DType/signature.
1038
+ */
1039
+ new_op_dtypes[0 ] = NPY_DT_NewRef (&PyArray_UnicodeDType);
1040
+ new_op_dtypes[1 ] = NPY_DT_NewRef (&PyArray_UnicodeDType);
1041
+ new_op_dtypes[2 ] = NPY_DT_NewRef (&PyArray_UnicodeDType);
1042
+ return 0 ;
1043
+ }
1044
+ if (signature[0 ] == &PyArray_UnicodeDType &&
1045
+ signature[1 ] == &PyArray_UnicodeDType &&
1046
+ signature[2 ] == &PyArray_UnicodeDType) {
1047
+ /* Unicode forced, but didn't override a string input: invalid */
1048
+ return -1 ;
1049
+ }
1031
1050
new_op_dtypes[0 ] = NPY_DT_NewRef (&PyArray_StringDType);
1032
1051
new_op_dtypes[1 ] = NPY_DT_NewRef (&PyArray_StringDType);
1033
1052
new_op_dtypes[2 ] = NPY_DT_NewRef (&PyArray_StringDType);
@@ -2532,6 +2551,17 @@ init_stringdtype_ufuncs(PyObject *umath)
2532
2551
return -1 ;
2533
2552
}
2534
2553
2554
+ PyArray_DTypeMeta *out_strings_promoter_dtypes[] = {
2555
+ &PyArray_UnicodeDType,
2556
+ &PyArray_UnicodeDType,
2557
+ &PyArray_StringDType,
2558
+ };
2559
+
2560
+ if (add_promoter (umath, " add" , out_strings_promoter_dtypes, 3 ,
2561
+ all_strings_promoter) < 0 ) {
2562
+ return -1 ;
2563
+ }
2564
+
2535
2565
INIT_MULTIPLY (Int64, int64);
2536
2566
INIT_MULTIPLY (UInt64, uint64);
2537
2567
0 commit comments