Repository: numpy/numpy
File: numpy/_core/src/multiarray/getset.c (C)

Code before:
        goto exit;
    }

    while(selfit->index < selfit->size) {
        copyswap(selfit->dataptr, arrit->dataptr, swap, self);
        PyArray_ITER_NEXT(selfit);
        PyArray_ITER_NEXT(arrit);
        if (arrit->index == arrit->size) {
            PyArray_ITER_RESET(arrit);
        }
    }
    retval = 0;

 exit:
    Py_XDECREF(selfit);
    Py_XDECREF(arrit);
    Py_XDECREF(arr);
    return retval;
}

static PyObject *
array_transpose_get(PyArrayObject *self, void *NPY_UNUSED(ignored))
{
    int ndim = PyArray_NDIM(self);
    if (ndim != 2) {
        if (PyErr_WarnFormat(PyExc_UserWarning, 1,
                "In the future `.T` property will be supported for "
                "2-dim arrays only. Received %d-dim array. Either "
                "`np.permute_dims(arr, range(arr.ndim)[::-1])` "
                "(compatible with the Array API) or `arr.transpose()` "
                "should be used instead.",
                ndim) < 0) {
            return NULL;
        }
    }
    return PyArray_Transpose(self, NULL);
}

static PyObject *
array_matrix_transpose_get(PyArrayObject *self, void *NPY_UNUSED(ignored))
{
    return PyArray_MatrixTranspose(self);
}

static PyObject *
array_ptp(PyArrayObject *self, void *NPY_UNUSED(ignored))
{
    PyErr_SetString(PyExc_AttributeError,
                    "`ptp` was removed from the ndarray class in NumPy 2.0. "
                    "Use np.ptp(arr, ...) instead.");
    return NULL;

Review comment (bug):
Why a `UserWarning`?  Please use a `DeprecationWarning`, or actually, use the `DEPRECATE` macro.

We could use a visible deprecation warning if we want to inform new users who accidentally get it wrong. But only if we take the trouble to check that very few libraries use this (i.e. there are few places in existing code where `DeprecationWarning` would be hidden, but `VisibleDeprecationWarning` wouldn't be).

Code after:
        goto exit;
    }

    while(selfit->index < selfit->size) {
        copyswap(selfit->dataptr, arrit->dataptr, swap, self);
        PyArray_ITER_NEXT(selfit);
        PyArray_ITER_NEXT(arrit);
        if (arrit->index == arrit->size) {
            PyArray_ITER_RESET(arrit);
        }
    }
    retval = 0;

 exit:
    Py_XDECREF(selfit);
    Py_XDECREF(arrit);
    Py_XDECREF(arr);
    return retval;
}

static PyObject *
array_transpose_get(PyArrayObject *self, void *NPY_UNUSED(ignored))
{
    int ndim = PyArray_NDIM(self);
    if (ndim != 2) {
        /* Deprecated 2025-04-19, NumPy 2.3 */
        if (PyErr_WarnFormat(PyExc_DeprecationWarning, 1,
                "In the future, the `.T` property will be supported for "
                "2-dimensional arrays only. Received %d-dimensional "
                "array. Either `arr.transpose()` or `.mT` (which swaps "
                "the last two axes only) should be used instead."
                "(Deprecated NumPy 2.3)", ndim) < 0) {
            return NULL;
        }
    }
    return PyArray_Transpose(self, NULL);
}

static PyObject *
array_matrix_transpose_get(PyArrayObject *self, void *NPY_UNUSED(ignored))
{
    return PyArray_MatrixTranspose(self);
}

static PyObject *
array_ptp(PyArrayObject *self, void *NPY_UNUSED(ignored))
{
    PyErr_SetString(PyExc_AttributeError,
                    "`ptp` was removed from the ndarray class in NumPy 2.0. "
                    "Use np.ptp(arr, ...) instead.");
    return NULL;