summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
Diffstat (limited to 'numpy')
-rw-r--r--numpy/core/src/multiarray/ctors.c37
-rw-r--r--numpy/core/src/multiarray/datetime_busday.c10
-rw-r--r--numpy/core/src/multiarray/datetime_busdaycal.c2
-rw-r--r--numpy/core/src/umath/ufunc_object.c29
-rw-r--r--numpy/core/tests/test_umath.py26
5 files changed, 29 insertions, 75 deletions
diff --git a/numpy/core/src/multiarray/ctors.c b/numpy/core/src/multiarray/ctors.c
index 41dcaf3bb..bf90142e1 100644
--- a/numpy/core/src/multiarray/ctors.c
+++ b/numpy/core/src/multiarray/ctors.c
@@ -1623,6 +1623,8 @@ fail:
* validate and possibly copy arr itself ...
* }
* ... use arr ...
+ * context is passed to PyArray_FromArrayAttr, which ignores it. Since this is
+ * a NUMPY_API function, we cannot remove it.
*/
NPY_NO_EXPORT int
PyArray_GetArrayParamsFromObject(PyObject *op,
@@ -1875,6 +1877,10 @@ PyArray_GetArrayParamsFromObject(PyObject *op,
/*NUMPY_API
* Does not check for NPY_ARRAY_ENSURECOPY and NPY_ARRAY_NOTSWAPPED in flags
* Steals a reference to newtype --- which can be NULL
+ *
+ * context is passed to PyArray_GetArrayParamsFromObject, which passes it to
+ * PyArray_FromArrayAttr, which raises if it is not NULL. Since this is a
+ * NUMPY_API function, we cannot remove it.
*/
NPY_NO_EXPORT PyObject *
PyArray_FromAny(PyObject *op, PyArray_Descr *newtype, int min_depth,
@@ -2648,13 +2654,18 @@ PyArray_FromInterface(PyObject *origin)
return NULL;
}
-/*NUMPY_API*/
+/*NUMPY_API
+ */
NPY_NO_EXPORT PyObject *
PyArray_FromArrayAttr(PyObject *op, PyArray_Descr *typecode, PyObject *context)
{
PyObject *new;
PyObject *array_meth;
+ if (context != NULL) {
+ PyErr_SetString(PyExc_RuntimeError, "'context' must be NULL");
+ return NULL;
+ }
array_meth = PyArray_LookupSpecial_OnInstance(op, "__array__");
if (array_meth == NULL) {
if (PyErr_Occurred()) {
@@ -2662,29 +2673,11 @@ PyArray_FromArrayAttr(PyObject *op, PyArray_Descr *typecode, PyObject *context)
}
return Py_NotImplemented;
}
- if (context == NULL) {
- if (typecode == NULL) {
- new = PyObject_CallFunction(array_meth, NULL);
- }
- else {
- new = PyObject_CallFunction(array_meth, "O", typecode);
- }
+ if (typecode == NULL) {
+ new = PyObject_CallFunction(array_meth, NULL);
}
else {
- if (typecode == NULL) {
- new = PyObject_CallFunction(array_meth, "OO", Py_None, context);
- if (new == NULL && PyErr_ExceptionMatches(PyExc_TypeError)) {
- PyErr_Clear();
- new = PyObject_CallFunction(array_meth, "");
- }
- }
- else {
- new = PyObject_CallFunction(array_meth, "OO", typecode, context);
- if (new == NULL && PyErr_ExceptionMatches(PyExc_TypeError)) {
- PyErr_Clear();
- new = PyObject_CallFunction(array_meth, "O", typecode);
- }
- }
+ new = PyObject_CallFunction(array_meth, "O", typecode);
}
Py_DECREF(array_meth);
if (new == NULL) {
diff --git a/numpy/core/src/multiarray/datetime_busday.c b/numpy/core/src/multiarray/datetime_busday.c
index cdeb65d0e..d3cce8a37 100644
--- a/numpy/core/src/multiarray/datetime_busday.c
+++ b/numpy/core/src/multiarray/datetime_busday.c
@@ -1012,7 +1012,7 @@ array_busday_offset(PyObject *NPY_UNUSED(self),
/* This steals the datetime_dtype reference */
dates = (PyArrayObject *)PyArray_FromAny(dates_in, datetime_dtype,
- 0, 0, 0, dates_in);
+ 0, 0, 0, NULL);
if (dates == NULL) {
goto fail;
}
@@ -1021,7 +1021,7 @@ array_busday_offset(PyObject *NPY_UNUSED(self),
/* Make 'offsets' into an array */
offsets = (PyArrayObject *)PyArray_FromAny(offsets_in,
PyArray_DescrFromType(NPY_INT64),
- 0, 0, 0, offsets_in);
+ 0, 0, 0, NULL);
if (offsets == NULL) {
goto fail;
}
@@ -1142,7 +1142,7 @@ array_busday_count(PyObject *NPY_UNUSED(self),
/* This steals the datetime_dtype reference */
dates_begin = (PyArrayObject *)PyArray_FromAny(dates_begin_in,
datetime_dtype,
- 0, 0, 0, dates_begin_in);
+ 0, 0, 0, NULL);
if (dates_begin == NULL) {
goto fail;
}
@@ -1165,7 +1165,7 @@ array_busday_count(PyObject *NPY_UNUSED(self),
/* This steals the datetime_dtype reference */
dates_end = (PyArrayObject *)PyArray_FromAny(dates_end_in,
datetime_dtype,
- 0, 0, 0, dates_end_in);
+ 0, 0, 0, NULL);
if (dates_end == NULL) {
goto fail;
}
@@ -1286,7 +1286,7 @@ array_is_busday(PyObject *NPY_UNUSED(self),
/* This steals the datetime_dtype reference */
dates = (PyArrayObject *)PyArray_FromAny(dates_in,
datetime_dtype,
- 0, 0, 0, dates_in);
+ 0, 0, 0, NULL);
if (dates == NULL) {
goto fail;
}
diff --git a/numpy/core/src/multiarray/datetime_busdaycal.c b/numpy/core/src/multiarray/datetime_busdaycal.c
index eb6ef04be..1aa5f6ab1 100644
--- a/numpy/core/src/multiarray/datetime_busdaycal.c
+++ b/numpy/core/src/multiarray/datetime_busdaycal.c
@@ -293,7 +293,7 @@ PyArray_HolidaysConverter(PyObject *dates_in, npy_holidayslist *holidays)
/* This steals the datetime_dtype reference */
dates = (PyArrayObject *)PyArray_FromAny(dates_in, datetime_dtype,
- 0, 0, 0, dates_in);
+ 0, 0, 0, NULL);
if (dates == NULL) {
goto fail;
}
diff --git a/numpy/core/src/umath/ufunc_object.c b/numpy/core/src/umath/ufunc_object.c
index db2842542..66d52cf92 100644
--- a/numpy/core/src/umath/ufunc_object.c
+++ b/numpy/core/src/umath/ufunc_object.c
@@ -1034,7 +1034,7 @@ get_ufunc_arguments(PyUFuncObject *ufunc,
int nin = ufunc->nin;
int nout = ufunc->nout;
int nop = ufunc->nargs;
- PyObject *obj, *context;
+ PyObject *obj;
PyArray_Descr *dtype = NULL;
/*
* Initialize output objects so caller knows when outputs and optional
@@ -1071,22 +1071,8 @@ get_ufunc_arguments(PyUFuncObject *ufunc,
out_op[i] = (PyArrayObject *)PyArray_FromArray(obj_a, NULL, 0);
}
else {
- if (!PyArray_IsScalar(obj, Generic)) {
- /*
- * TODO: There should be a comment here explaining what
- * context does.
- */
- context = Py_BuildValue("OOi", ufunc, args, i);
- if (context == NULL) {
- goto fail;
- }
- }
- else {
- context = NULL;
- }
out_op[i] = (PyArrayObject *)PyArray_FromAny(obj,
- NULL, 0, 0, 0, context);
- Py_XDECREF(context);
+ NULL, 0, 0, 0, NULL);
}
if (out_op[i] == NULL) {
@@ -4401,7 +4387,7 @@ PyUFunc_GenericReduction(PyUFuncObject *ufunc, PyObject *args,
PyObject *axes_in = NULL;
PyArrayObject *mp = NULL, *wheremask = NULL, *ret = NULL;
PyObject *op;
- PyObject *obj_ind, *context;
+ PyObject *obj_ind;
PyArrayObject *indices = NULL;
PyArray_Descr *otype = NULL;
PyArrayObject *out = NULL;
@@ -4495,14 +4481,7 @@ PyUFunc_GenericReduction(PyUFuncObject *ufunc, PyObject *args,
}
}
/* Ensure input is an array */
- if (!PyArray_Check(op) && !PyArray_IsScalar(op, Generic)) {
- context = Py_BuildValue("O(O)i", ufunc, op, 0);
- }
- else {
- context = NULL;
- }
- mp = (PyArrayObject *)PyArray_FromAny(op, NULL, 0, 0, 0, context);
- Py_XDECREF(context);
+ mp = (PyArrayObject *)PyArray_FromAny(op, NULL, 0, 0, 0, NULL);
if (mp == NULL) {
goto fail;
}
diff --git a/numpy/core/tests/test_umath.py b/numpy/core/tests/test_umath.py
index 0ab029988..b7baa16e1 100644
--- a/numpy/core/tests/test_umath.py
+++ b/numpy/core/tests/test_umath.py
@@ -1848,32 +1848,14 @@ class TestSpecialMethods:
a = A()
assert_raises(RuntimeError, ncu.maximum, a, a)
- def test_array_with_context(self):
+ def test_array_too_many_args(self):
- class A:
- def __array__(self, dtype=None, context=None):
- func, args, i = context
- self.func = func
- self.args = args
- self.i = i
- return np.zeros(1)
-
- class B:
- def __array__(self, dtype=None):
- return np.zeros(1, dtype)
-
- class C:
- def __array__(self):
+ class A(object):
+ def __array__(self, dtype, context):
return np.zeros(1)
a = A()
- ncu.maximum(np.zeros(1), a)
- assert_(a.func is ncu.maximum)
- assert_equal(a.args[0], 0)
- assert_(a.args[1] is a)
- assert_(a.i == 1)
- assert_equal(ncu.maximum(a, B()), 0)
- assert_equal(ncu.maximum(a, C()), 0)
+ assert_raises_regex(TypeError, '2 required positional', np.sum, a)
def test_ufunc_override(self):
# check override works even with instance with high priority.