* Given a dtype or DType object, find the correct descriptor to cast the * array to. In some places, this function is used with dtype=NULL which * means that legacy behavior is used: The dtype instances "S0", "U0", and * "V0" are converted to mean the DType classes instead. * When dtype != NULL, this path is ignored, and the function does nothing * unless descr == NULL. If both descr and dty
| 892 | * @return A concrete dtype instance or NULL |
| 893 | */ |
| 894 | NPY_NO_EXPORT PyArray_Descr * |
| 895 | PyArray_AdaptDescriptorToArray( |
| 896 | PyArrayObject *arr, PyArray_DTypeMeta *dtype, PyArray_Descr *descr) |
| 897 | { |
| 898 | /* If the requested dtype is flexible, adapt it */ |
| 899 | PyArray_Descr *new_descr; |
| 900 | int res; |
| 901 | |
| 902 | if (dtype != NULL && descr != NULL) { |
| 903 | /* descr was given and no special logic, return (call not necessary) */ |
| 904 | Py_INCREF(descr); |
| 905 | return descr; |
| 906 | } |
| 907 | if (dtype == NULL) { |
| 908 | res = PyArray_ExtractDTypeAndDescriptor(descr, &new_descr, &dtype); |
| 909 | if (res < 0) { |
| 910 | return NULL; |
| 911 | } |
| 912 | if (new_descr != NULL) { |
| 913 | Py_DECREF(dtype); |
| 914 | return new_descr; |
| 915 | } |
| 916 | } |
| 917 | else { |
| 918 | assert(descr == NULL); /* gueranteed above */ |
| 919 | Py_INCREF(dtype); |
| 920 | } |
| 921 | |
| 922 | res = find_descriptor_from_array(arr, dtype, &new_descr); |
| 923 | if (res < 0) { |
| 924 | Py_DECREF(dtype); |
| 925 | return NULL; |
| 926 | } |
| 927 | if (new_descr == NULL) { |
| 928 | /* This is an object array but contained no elements, use default */ |
| 929 | new_descr = NPY_DT_CALL_default_descr(dtype); |
| 930 | } |
| 931 | Py_XDECREF(dtype); |
| 932 | return new_descr; |
| 933 | } |
| 934 | |
| 935 | |
| 936 | /** |
no test coverage detected