diff options
| author | Charles Harris <charlesr.harris@gmail.com> | 2021-06-11 12:44:25 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-06-11 12:44:25 -0600 |
| commit | 1581032a16ba8150f0deca6451f142eeba249dfd (patch) | |
| tree | 8876fdabdbbe2608d7447232796a8ae619b0c6e9 /numpy | |
| parent | 8cb12732effc36690690cc71f4909cb1dd8369fd (diff) | |
| parent | 5ad2ca2f44ce9b197632a52e7da8f33269fc11ed (diff) | |
| download | numpy-1581032a16ba8150f0deca6451f142eeba249dfd.tar.gz | |
Merge pull request #19224 from seberg/string-compare-dead-code
MAINT: Remove python 2 specific string comparison code
Diffstat (limited to 'numpy')
| -rw-r--r-- | numpy/core/src/multiarray/arrayobject.c | 48 |
1 files changed, 8 insertions, 40 deletions
diff --git a/numpy/core/src/multiarray/arrayobject.c b/numpy/core/src/multiarray/arrayobject.c index e7fbb88cd..78f547de2 100644 --- a/numpy/core/src/multiarray/arrayobject.c +++ b/numpy/core/src/multiarray/arrayobject.c @@ -971,8 +971,7 @@ _strings_richcompare(PyArrayObject *self, PyArrayObject *other, int cmp_op, PyArrayMultiIterObject *mit; int val; - /* Cast arrays to a common type */ - if (PyArray_TYPE(self) != PyArray_DESCR(other)->type_num) { + if (PyArray_TYPE(self) != PyArray_TYPE(other)) { /* * Comparison between Bytes and Unicode is not defined in Py3K; * we follow. @@ -981,53 +980,22 @@ _strings_richcompare(PyArrayObject *self, PyArrayObject *other, int cmp_op, return Py_NotImplemented; } if (PyArray_ISNOTSWAPPED(self) != PyArray_ISNOTSWAPPED(other)) { - PyObject *new; - if (PyArray_TYPE(self) == NPY_STRING && - PyArray_DESCR(other)->type_num == NPY_UNICODE) { - PyArray_Descr* unicode = PyArray_DescrNew(PyArray_DESCR(other)); - unicode->elsize = PyArray_DESCR(self)->elsize << 2; - new = PyArray_FromAny((PyObject *)self, unicode, - 0, 0, 0, NULL); - if (new == NULL) { - return NULL; - } - Py_INCREF(other); - self = (PyArrayObject *)new; - } - else if ((PyArray_TYPE(self) == NPY_UNICODE) && - ((PyArray_DESCR(other)->type_num == NPY_STRING) || - (PyArray_ISNOTSWAPPED(self) != PyArray_ISNOTSWAPPED(other)))) { - PyArray_Descr* unicode = PyArray_DescrNew(PyArray_DESCR(self)); - - if (PyArray_DESCR(other)->type_num == NPY_STRING) { - unicode->elsize = PyArray_DESCR(other)->elsize << 2; - } - else { - unicode->elsize = PyArray_DESCR(other)->elsize; - } - new = PyArray_FromAny((PyObject *)other, unicode, - 0, 0, 0, NULL); - if (new == NULL) { - return NULL; - } - Py_INCREF(self); - other = (PyArrayObject *)new; - } - else { - PyErr_SetString(PyExc_TypeError, - "invalid string data-types " - "in comparison"); + /* Cast `other` to the same byte order as `self` (both unicode here) */ + PyArray_Descr* unicode = PyArray_DescrNew(PyArray_DESCR(self)); + unicode->elsize = PyArray_DESCR(other)->elsize; + PyObject *new = PyArray_FromAny((PyObject *)other, + unicode, 0, 0, 0, NULL); + if (new == NULL) { return NULL; } + other = (PyArrayObject *)new; } else { - Py_INCREF(self); Py_INCREF(other); } /* Broad-cast the arrays to a common shape */ mit = (PyArrayMultiIterObject *)PyArray_MultiIterNew(2, self, other); - Py_DECREF(self); Py_DECREF(other); if (mit == NULL) { return NULL; |
