summaryrefslogtreecommitdiff
path: root/numpy/core/src
diff options
context:
space:
mode:
authorStephan Hoyer <shoyer@google.com>2018-12-01 11:43:16 -0800
committerStephan Hoyer <shoyer@google.com>2018-12-01 11:49:28 -0800
commitbc143e02a20a23ca8c1b426f41201160eca0e376 (patch)
tree7fc7a7506375ba7848bf4f803333da0e23bcb405 /numpy/core/src
parentb3a435305082699c26445630d9c79587d51ba9f1 (diff)
downloadnumpy-bc143e02a20a23ca8c1b426f41201160eca0e376.tar.gz
MAINT: remove wrapper functions from numpy.core.multiarray
The original motivation for the style of these wrapper functions, introduced in gh-12175, was to preserve introspection. But it turns out NumPy's functions defined in C don't support introspection anyways, so the extra wrapper functions are entirely pointless. This version reverts the additional wrapper functions, which put default arguments in two places and introduced slow-down due to the overhead of another function call. I've retained docstrings in multiarray.py, since it's definitely more readable to keep docstrings and dispatchers together rather than leaving docstrings in _add_newdocs.py. One bonus of this approach is that dispatcher functions have the same name as their implementations, so `np.concatenate(unknown=True)` gives an error message mentioning "concatenate" rather than "_concatenate_dispatcher": `TypeError: concatenate() got an unexpected keyword argument 'unknown'`
Diffstat (limited to 'numpy/core/src')
-rw-r--r--numpy/core/src/multiarray/compiled_base.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/numpy/core/src/multiarray/compiled_base.c b/numpy/core/src/multiarray/compiled_base.c
index 17d8baf7b..557a7cfe5 100644
--- a/numpy/core/src/multiarray/compiled_base.c
+++ b/numpy/core/src/multiarray/compiled_base.c
@@ -1158,6 +1158,27 @@ arr_unravel_index(PyObject *self, PyObject *args, PyObject *kwds)
char *kwlist[] = {"indices", "shape", "order", NULL};
+ /* TODO: remove this in favor of warning raised in the dispatcher when
+ * __array_function__ is enabled by default. */
+
+ /* 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,