diff options
Diffstat (limited to 'numpy/core')
-rw-r--r-- | numpy/core/multiarray.py | 15 | ||||
-rw-r--r-- | numpy/core/src/multiarray/compiled_base.c | 20 |
2 files changed, 13 insertions, 22 deletions
diff --git a/numpy/core/multiarray.py b/numpy/core/multiarray.py index 2b3633c97..f068717a4 100644 --- a/numpy/core/multiarray.py +++ b/numpy/core/multiarray.py @@ -7,6 +7,7 @@ by importing from the extension module. """ import functools +import warnings from . import overrides from . import _multiarray_umath @@ -994,12 +995,21 @@ def ravel_multi_index(multi_index, dims, mode='raise', order='C'): multi_index, dims, mode=mode, order=order) -def _unravel_index_dispatcher(indices, shape, order=None): +def _deprecate_dims(shape, dims): + if dims is not None: + warnings.warn("'shape' argument should be used instead of 'dims'", + DeprecationWarning, stacklevel=3) + shape = dims + return shape + + +def _unravel_index_dispatcher(indices, shape=None, order=None, dims=None): + shape = _deprecate_dims(shape, dims) return (indices,) @array_function_dispatch(_unravel_index_dispatcher) -def unravel_index(indices, shape, order='C'): +def unravel_index(indices, shape=None, order='C', dims=None): """ Converts a flat index or array of flat indices into a tuple of coordinate arrays. @@ -1043,6 +1053,7 @@ def unravel_index(indices, shape, order='C'): (3, 1, 4, 1) """ + shape = _deprecate_dims(shape, dims) return _multiarray_umath.unravel_index(indices, shape, order=order) diff --git a/numpy/core/src/multiarray/compiled_base.c b/numpy/core/src/multiarray/compiled_base.c index e8380e3bc..17d8baf7b 100644 --- a/numpy/core/src/multiarray/compiled_base.c +++ b/numpy/core/src/multiarray/compiled_base.c @@ -1158,26 +1158,6 @@ arr_unravel_index(PyObject *self, PyObject *args, PyObject *kwds) char *kwlist[] = {"indices", "shape", "order", NULL}; - /* Continue to support the older "dims" argument in place - * of the "shape" argument. Issue an appropriate warning - * if "dims" is detected in keywords, then replace it with - * the new "shape" argument and continue processing as usual */ - - - if (kwds) { - PyObject *dims_item, *shape_item; - dims_item = PyDict_GetItemString(kwds, "dims"); - shape_item = PyDict_GetItemString(kwds, "shape"); - if (dims_item != NULL && shape_item == NULL) { - if (DEPRECATE("'shape' argument should be" - " used instead of 'dims'") < 0) { - return NULL; - } - PyDict_SetItemString(kwds, "shape", dims_item); - PyDict_DelItemString(kwds, "dims"); - } - } - if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO&|O&:unravel_index", kwlist, &indices0, |