NUMPY_API * Convert an object to NPY_RAISE / NPY_CLIP / NPY_WRAP */
| 745 | * Convert an object to NPY_RAISE / NPY_CLIP / NPY_WRAP |
| 746 | */ |
| 747 | NPY_NO_EXPORT int |
| 748 | PyArray_ClipmodeConverter(PyObject *object, NPY_CLIPMODE *val) |
| 749 | { |
| 750 | if (object == NULL || object == Py_None) { |
| 751 | *val = NPY_RAISE; |
| 752 | } |
| 753 | |
| 754 | else if (PyBytes_Check(object) || PyUnicode_Check(object)) { |
| 755 | return string_converter_helper( |
| 756 | object, (void *)val, clipmode_parser, "clipmode", |
| 757 | "must be one of 'clip', 'raise', or 'wrap'"); |
| 758 | } |
| 759 | else { |
| 760 | /* For users passing `np.RAISE`, `np.WRAP`, `np.CLIP` */ |
| 761 | int number = PyArray_PyIntAsInt(object); |
| 762 | if (error_converting(number)) { |
| 763 | goto fail; |
| 764 | } |
| 765 | if (number <= (int) NPY_RAISE |
| 766 | && number >= (int) NPY_CLIP) { |
| 767 | *val = (NPY_CLIPMODE) number; |
| 768 | } |
| 769 | else { |
| 770 | PyErr_Format(PyExc_ValueError, |
| 771 | "integer clipmode must be np.RAISE, np.WRAP, or np.CLIP"); |
| 772 | } |
| 773 | } |
| 774 | return NPY_SUCCEED; |
| 775 | |
| 776 | fail: |
| 777 | PyErr_SetString(PyExc_TypeError, |
| 778 | "clipmode not understood"); |
| 779 | return NPY_FAIL; |
| 780 | } |
| 781 | |
| 782 | /*NUMPY_API |
| 783 | * Convert an object to an array of n NPY_CLIPMODE values. |
no test coverage detected