MCPcopy Create free account
hub / github.com/numpy/numpy / _is_user_defined_string_array

Function _is_user_defined_string_array

numpy/core/src/multiarray/multiarraymodule.c:3927–3949  ·  view source on GitHub ↗

* returns 1 if array is a user-defined string dtype, sets an error and * returns 0 otherwise */

Source from the content-addressed store, hash-verified

3925 * returns 0 otherwise
3926 */
3927static int _is_user_defined_string_array(PyArrayObject* array)
3928{
3929 if (NPY_DT_is_user_defined(PyArray_DESCR(array))) {
3930 PyTypeObject* scalar_type = NPY_DTYPE(PyArray_DESCR(array))->scalar_type;
3931 if (PyType_IsSubtype(scalar_type, &PyBytes_Type) ||
3932 PyType_IsSubtype(scalar_type, &PyUnicode_Type)) {
3933 return 1;
3934 }
3935 else {
3936 PyErr_SetString(
3937 PyExc_TypeError,
3938 "string comparisons are only allowed for dtypes with a "
3939 "scalar type that is a subtype of str or bytes.");
3940 return 0;
3941 }
3942 }
3943 else {
3944 PyErr_SetString(
3945 PyExc_TypeError,
3946 "string operation on non-string array");
3947 return 0;
3948 }
3949}
3950
3951
3952/*

Callers 1

_vec_stringFunction · 0.85

Calls 1

PyArray_DESCRFunction · 0.85

Tested by

no test coverage detected