Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork11.9k
API: Introducecopy argument fornp.asarray [Array API]#25168
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes from1 commit
906010e94dd1b5ab9c6b88f5d130beb523cFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1477,16 +1477,7 @@ _array_from_array_like(PyObject *op, | ||
| } | ||
| } | ||
| if (tmp == Py_NotImplemented) { | ||
| tmp = PyArray_FromArrayAttr_int(op, requested_dtype, never_copy); | ||
| if (tmp == NULL) { | ||
| return NULL; | ||
| @@ -2418,9 +2409,8 @@ PyArray_FromInterface(PyObject *origin) | ||
| * @param descr The desired `arr.dtype`, passed into the `__array__` call, | ||
| * as information but is not checked/enforced! | ||
| * @param never_copy Specifies that a copy is not allowed. | ||
| * NOTE: For false it passes `op.__array__(copy=None)`, | ||
| * for true: `op.__array__(copy=False)`. | ||
| * @returns NotImplemented if `__array__` is not defined or a NumPy array | ||
| * (or subclass). On error, return NULL. | ||
| */ | ||
| @@ -2438,15 +2428,6 @@ PyArray_FromArrayAttr_int( | ||
| } | ||
| return Py_NotImplemented; | ||
| } | ||
| if (PyType_Check(op) && PyObject_HasAttrString(array_meth, "__get__")) { | ||
| /* | ||
| @@ -2458,12 +2439,33 @@ PyArray_FromArrayAttr_int( | ||
| Py_DECREF(array_meth); | ||
| return Py_NotImplemented; | ||
| } | ||
| PyObject *copy = never_copy ? Py_False : Py_None; | ||
| PyObject *kwargs = PyDict_New(); | ||
| PyDict_SetItemString(kwargs, "copy", copy); | ||
| PyObject *args = descr != NULL ? PyTuple_Pack(1, descr) : PyTuple_New(0); | ||
| new = PyObject_Call(array_meth, args, kwargs); | ||
| if (PyErr_Occurred()) { | ||
| PyObject *type, *value, *traceback; | ||
| PyErr_Fetch(&type, &value, &traceback); | ||
| if (PyUnicode_Check(value) && PyUnicode_CompareWithASCIIString(value, | ||
| "__array__() got an unexpected keyword argument 'copy'") == 0) { | ||
| Py_DECREF(type); | ||
| Py_XDECREF(value); | ||
| Py_XDECREF(traceback); | ||
| if (PyErr_WarnEx(PyExc_UserWarning, | ||
| "__array__ should implement 'dtype' and 'copy' keywords", 1) < 0) { | ||
| return NULL; | ||
ngoldbaum marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| } | ||
| Py_SETREF(new, PyObject_Call(array_meth, args, NULL)); | ||
| } else { | ||
| PyErr_Restore(type, value, traceback); | ||
ngoldbaum marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| return NULL; | ||
| } | ||
| } | ||
| Py_DECREF(array_meth); | ||
| if (new == NULL) { | ||
| return NULL; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -928,7 +928,7 @@ array_getarray(PyArrayObject *self, PyObject *args, PyObject *kwds) | ||
| { | ||
| PyArray_Descr *newtype = NULL; | ||
| NPY_COPYMODE copy = NPY_COPY_IF_NEEDED; | ||
| static char *kwlist[] = {"dtype", "copy", NULL}; | ||
| PyObject *ret; | ||
| if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O&$O&:__array__", kwlist, | ||
| @@ -981,6 +981,7 @@ array_getarray(PyArrayObject *self, PyObject *args, PyObject *kwds) | ||
| } else { // copy == NPY_COPY_NEVER | ||
| PyErr_SetString(PyExc_ValueError, | ||
| "Unable to avoid copy while creating an array from given array."); | ||
ngoldbaum marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| Py_DECREF(self); | ||
| return NULL; | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading.Please reload this page.