* Do the promotion step and possible casting. This function should * never be called if a descriptor was requested. In that case the output * dtype is not of importance, so we must not risk promotion errors. * * @param out_descr The current descriptor. * @param descr The newly found descriptor to promote with * @param fixed_DType The user provided (fixed) DType or NULL * @param flags dtype
| 683 | * @return -1 on error, 0 on success. |
| 684 | */ |
| 685 | static inline int |
| 686 | handle_promotion(PyArray_Descr **out_descr, PyArray_Descr *descr, |
| 687 | PyArray_DTypeMeta *fixed_DType, enum _dtype_discovery_flags *flags) |
| 688 | { |
| 689 | assert(!(*flags & DESCRIPTOR_WAS_SET)); |
| 690 | |
| 691 | if (*out_descr == NULL) { |
| 692 | Py_INCREF(descr); |
| 693 | *out_descr = descr; |
| 694 | return 0; |
| 695 | } |
| 696 | PyArray_Descr *new_descr = PyArray_PromoteTypes(descr, *out_descr); |
| 697 | if (NPY_UNLIKELY(new_descr == NULL)) { |
| 698 | if (fixed_DType != NULL || PyErr_ExceptionMatches(PyExc_FutureWarning)) { |
| 699 | /* |
| 700 | * If a DType is fixed, promotion must not fail. Do not catch |
| 701 | * FutureWarning (raised for string+numeric promotions). We could |
| 702 | * only catch TypeError here or even always raise the error. |
| 703 | */ |
| 704 | return -1; |
| 705 | } |
| 706 | PyErr_Clear(); |
| 707 | *flags |= PROMOTION_FAILED; |
| 708 | /* Continue with object, since we may need the dimensionality */ |
| 709 | new_descr = PyArray_DescrFromType(NPY_OBJECT); |
| 710 | } |
| 711 | Py_SETREF(*out_descr, new_descr); |
| 712 | return 0; |
| 713 | } |
| 714 | |
| 715 | |
| 716 | /** |
no test coverage detected