summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Berg <sebastian@sipsolutions.net>2013-04-13 09:53:59 +0200
committerSebastian Berg <sebastian@sipsolutions.net>2013-05-31 19:16:02 +0200
commita727f424a5b402558a7b7cba978449a1b015a47e (patch)
treea9a641e5e977883ac86e1fcd101c3e3295f0f167
parent8dfc25d0e1fcaed67b8c688cfd9f5ac0641fc5e7 (diff)
downloadnumpy-a727f424a5b402558a7b7cba978449a1b015a47e.tar.gz
API: Deprecate __index__ for ndim > 0
For example NumPy indexing treats np.ones(()) very differently from np.ones((1,)). It seems a bad idea to allow __index__ for arrays that are not 0-d, as they cannot always be safely interpreted as integers.
-rw-r--r--numpy/core/src/multiarray/number.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/numpy/core/src/multiarray/number.c b/numpy/core/src/multiarray/number.c
index c37a232f4..53218117a 100644
--- a/numpy/core/src/multiarray/number.c
+++ b/numpy/core/src/multiarray/number.c
@@ -840,6 +840,12 @@ array_index(PyArrayObject *v)
"one element can be converted to an index");
return NULL;
}
+ if (PyArray_NDIM(v) != 0) {
+ if (DEPRECATE("converting an array with ndim > 0 to an index"
+ " will result in an error in the future") < 0) {
+ return NULL;
+ }
+ }
return PyArray_DESCR(v)->f->getitem(PyArray_DATA(v), v);
}
#endif