diff options
author | Sebastian Berg <sebastian@sipsolutions.net> | 2013-04-13 09:53:59 +0200 |
---|---|---|
committer | Sebastian Berg <sebastian@sipsolutions.net> | 2013-05-31 19:16:02 +0200 |
commit | a727f424a5b402558a7b7cba978449a1b015a47e (patch) | |
tree | a9a641e5e977883ac86e1fcd101c3e3295f0f167 /numpy | |
parent | 8dfc25d0e1fcaed67b8c688cfd9f5ac0641fc5e7 (diff) | |
download | numpy-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.
Diffstat (limited to 'numpy')
-rw-r--r-- | numpy/core/src/multiarray/number.c | 6 |
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 |