8000 cleanup · numpy/numpy@df42838 · GitHub
[go: up one dir, main page]

Skip to content

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit df42838

Browse files
committed
cleanup
1 parent 290373b commit df42838

File tree

2 files changed

+16
-24
lines changed

2 files changed

+16
-24
lines changed

numpy/_core/src/multiarray/convert.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#include "array_assign.h"
2323

2424
#include "convert.h"
25-
#include "getset.h"
2625
#include "array_coercion.h"
2726
#include "refcount.h"
2827

numpy/_core/src/multiarray/getset.c

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -376,8 +376,23 @@ array_nbytes_get(PyArrayObject *self, void *NPY_UNUSED(ignored))
376376
* will be adjusted in that case as well.
377377
*/
378378
static int
379-
array_descr_set_lock_held(PyArrayObject *self, PyObject *arg)
379+
array_descr_set(PyArrayObject *self, PyObject *arg)
380380
{
381+
// to be replaced with PyUnstable_Object_IsUniquelyReferenced https://github.com/python/cpython/pull/133144
382+
int unique_reference = (Py_REFCNT(self) == 1);
383+
384+
if (!unique_reference) {
385+
// this will not emit deprecation warnings for all cases, but for most it will
386+
/* DEPRECATED 2025-05-04, NumPy 2.3 */
387+
int ret = PyErr_WarnEx(PyExc_DeprecationWarning,
388+
"Setting the dtype on a Numpy array has been deprecated in Numpy 2.3.\n"
389+
"Instead of changing the dtype on an array x, create a new array with x.view(new_dtype)",
390+
1);
391+
if (ret) {
392+
return -1;
393+
}
394+
}
395+
381396
PyArray_Descr *newtype = NULL;
382397

383398
if (arg == NULL) {
@@ -522,28 +537,6 @@ array_descr_set_lock_held(PyArrayObject *self, PyObject *arg)
522537
return -1;
523538
}
524539

525-
static int
526-
array_descr_set(PyArrayObject *self, PyObject *arg, void *NPY_UNUSED(ignored))
527-
{
528-
// to be replaced with PyUnstable_Object_IsUniquelyReferenced https://github.com/python/cpython/pull/133144
529-
int unique_reference = (Py_REFCNT(self) == 1);
530-
531-
if (!unique_reference) {
532-
// this will not emit deprecation warnings for all cases we want, but it gets is in the right direction
533-
/* DEPRECATED 2025-05-04, NumPy 2.3 */
534-
int ret = PyErr_WarnEx(PyExc_DeprecationWarning,
535-
"Setting the dtype on a Numpy array has been deprecated in Numpy 2.3.\n"
536-
"Instead of changing the dtype on an array x, create a new array with x.view(new_dtype)",
537-
1);
538-
//printf("array_descr_set: %p %p: %ld, bail\n", self, arg, Py_REFCNT(self));
539-
if (ret) {
540-
return -1;
541-
}
542-
}
543-
//printf("array_descr_set: %p %p: %ld\n", self, arg, Py_REFCNT(self));
544-
return array_descr_set_lock_held(self, arg);
545-
}
546-
547540
static PyObject *
548541
array_struct_get(PyArrayObject *self, void *NPY_UNUSED(ignored))
549542
{

0 commit comments

Comments
 (0)
0