[Numpy-svn] r3242 - trunk/numpy/core/src

numpy-svn at scipy.org numpy-svn at scipy.org
Mon Oct 2 17:21:26 EDT 2006


Author: oliphant
Date: 2006-10-02 16:21:22 -0500 (Mon, 02 Oct 2006)
New Revision: 3242

Modified:
   trunk/numpy/core/src/arrayobject.c
Log:
Fix #302 by being careful about situations where the index method is defined but the object is a sequence.

Modified: trunk/numpy/core/src/arrayobject.c
===================================================================
--- trunk/numpy/core/src/arrayobject.c	2006-10-02 20:21:11 UTC (rev 3241)
+++ trunk/numpy/core/src/arrayobject.c	2006-10-02 21:21:22 UTC (rev 3242)
@@ -2812,7 +2812,8 @@
         }
 
         if (PyInt_Check(index) || PyArray_IsScalar(index, Integer) ||
-            PyLong_Check(index) || PyIndex_Check(index)) {
+            PyLong_Check(index) || (PyIndex_Check(index) && 
+                                    !PySequence_Check(index))) {
                 intp value;
                 value = PyArray_PyIntAsIntp(index);
                 if (PyErr_Occurred())
@@ -2920,7 +2921,8 @@
         intp vals[MAX_DIMS];
 
         if (PyInt_Check(op) || PyArray_IsScalar(op, Integer) || \
-            PyLong_Check(op) || PyIndex_Check(op)) {
+            PyLong_Check(op) || (PyIndex_Check(op) && 
+                                 !PySequence_Check(op))) {
                 intp value;
                 value = PyArray_PyIntAsIntp(op);
                 if (PyErr_Occurred())
@@ -3844,8 +3846,8 @@
 static PyObject *
 array_index(PyArrayObject *v)
 {
-        if (PyArray_SIZE(v) != 1 || !PyArray_ISINTEGER(v)) {
-                PyErr_SetString(PyExc_TypeError, "only length-1 integer " \
+        if (v->nd != 0 || !PyArray_ISINTEGER(v)) {
+                PyErr_SetString(PyExc_TypeError, "only 0-d integer"     \
                                 "arrays can be converted to an index");
                 return NULL;
         }




More information about the Numpy-svn mailing list