summaryrefslogtreecommitdiff
path: root/numpy/core/src/arrayobject.c
diff options
context:
space:
mode:
authorTravis Oliphant <oliphant@enthought.com>2006-03-01 17:49:45 +0000
committerTravis Oliphant <oliphant@enthought.com>2006-03-01 17:49:45 +0000
commita93cea60ef4816a150f741cca2f55b63f265291b (patch)
tree59cd599c4bf7dc817e53c8553abc94d450c03fff /numpy/core/src/arrayobject.c
parent6fd31c330e6572963a03b71bcd479dbedd153ac8 (diff)
downloadnumpy-a93cea60ef4816a150f741cca2f55b63f265291b.tar.gz
Fix equality and inequality comparison so that non-array objects are not cast to the type of the array object unless that array is of type PyArray_OBJECT.
Diffstat (limited to 'numpy/core/src/arrayobject.c')
-rw-r--r--numpy/core/src/arrayobject.c23
1 files changed, 16 insertions, 7 deletions
diff --git a/numpy/core/src/arrayobject.c b/numpy/core/src/arrayobject.c
index 6b8012f73..b004ca6a4 100644
--- a/numpy/core/src/arrayobject.c
+++ b/numpy/core/src/arrayobject.c
@@ -3255,6 +3255,7 @@ static PyObject *
array_richcompare(PyArrayObject *self, PyObject *other, int cmp_op)
{
PyObject *array_other, *result;
+ int typenum;
switch (cmp_op)
{
@@ -3271,13 +3272,17 @@ array_richcompare(PyArrayObject *self, PyObject *other, int cmp_op)
}
/* Try to convert other to an array */
if (!PyArray_Check(other)) {
- array_other = PyArray_FromObject(other,
- self->descr->type_num, 0, 0);
- /* If not successful, then return the integer
- object 0. This fixes code that used to
+ typenum = self->descr->type_num;
+ if (typenum != PyArray_OBJECT) {
+ typenum = PyArray_NOTYPE;
+ }
+ array_other = PyArray_FromObject \
+ (other, typenum, 0, 0);
+ /* If not successful, then return False
+ This fixes code that used to
allow equality comparisons between arrays
and other objects which would give a result
- of 0
+ of False
*/
if ((array_other == NULL) || \
(array_other == Py_None)) {
@@ -3312,8 +3317,12 @@ array_richcompare(PyArrayObject *self, PyObject *other, int cmp_op)
}
/* Try to convert other to an array */
if (!PyArray_Check(other)) {
- array_other = PyArray_FromObject(other,
- self->descr->type_num, 0, 0);
+ typenum = self->descr->type_num;
+ if (typenum != PyArray_OBJECT) {
+ typenum = PyArray_NOTYPE;
+ }
+ array_other = PyArray_FromObject \
+ (other, typenum, 0, 0);
/* If not successful, then objects cannot be
compared and cannot be equal, therefore,
return True;