Skip to content

Commit acecd26

Browse files
committed
MAINT: remove undocumented __buffer__ attribute lookup
1 parent 06c86bc commit acecd26

File tree

4 files changed

+8
-29
lines changed

4 files changed

+8
-29
lines changed

doc/release/1.17.0-notes.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@ zero::
5252
>>> np.zeros(10)//1
5353
array([0., 0., 0., 0., 0., 0., 0., 0., 0., 0.])
5454

55+
Do not lookup ``__buffer__`` attribute in `numpy.frombuffer`
56+
------------------------------------------------------------
57+
58+
Looking up ``__buffer__`` attribute in `numpy.frombuffer` was undocumented and
59+
non-functional. This code was removed. If needed, use
60+
``frombuffer(memoryview(obj), ...)`` instead.
61+
5562
C API changes
5663
=============
5764

numpy/core/src/multiarray/ctors.c

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3693,32 +3693,12 @@ PyArray_FromBuffer(PyObject *buf, PyArray_Descr *type,
36933693
Py_DECREF(type);
36943694
return NULL;
36953695
}
3696-
if (Py_TYPE(buf)->tp_as_buffer == NULL
3697-
#if defined(NPY_PY3K)
3698-
|| Py_TYPE(buf)->tp_as_buffer->bf_getbuffer == NULL
3699-
#else
3700-
|| (Py_TYPE(buf)->tp_as_buffer->bf_getwritebuffer == NULL
3701-
&& Py_TYPE(buf)->tp_as_buffer->bf_getreadbuffer == NULL)
3702-
#endif
3703-
) {
3704-
PyObject *newbuf;
3705-
newbuf = PyObject_GetAttr(buf, npy_ma_str_buffer);
3706-
if (newbuf == NULL) {
3707-
Py_DECREF(type);
3708-
return NULL;
3709-
}
3710-
buf = newbuf;
3711-
}
3712-
else {
3713-
Py_INCREF(buf);
3714-
}
37153696

37163697
#if defined(NPY_PY3K)
37173698
if (PyObject_GetBuffer(buf, &view, PyBUF_WRITABLE|PyBUF_SIMPLE) < 0) {
37183699
writeable = 0;
37193700
PyErr_Clear();
37203701
if (PyObject_GetBuffer(buf, &view, PyBUF_SIMPLE) < 0) {
3721-
Py_DECREF(buf);
37223702
Py_DECREF(type);
37233703
return NULL;
37243704
}
@@ -3738,7 +3718,6 @@ PyArray_FromBuffer(PyObject *buf, PyArray_Descr *type,
37383718
writeable = 0;
37393719
PyErr_Clear();
37403720
if (PyObject_AsReadBuffer(buf, (void *)&data, &ts) == -1) {
3741-
Py_DECREF(buf);
37423721
Py_DECREF(type);
37433722
return NULL;
37443723
}
@@ -3749,7 +3728,6 @@ PyArray_FromBuffer(PyObject *buf, PyArray_Descr *type,
37493728
PyErr_Format(PyExc_ValueError,
37503729
"offset must be non-negative and no greater than buffer "\
37513730
"length (%" NPY_INTP_FMT ")", (npy_intp)ts);
3752-
Py_DECREF(buf);
37533731
Py_DECREF(type);
37543732
return NULL;
37553733
}
@@ -3763,7 +3741,6 @@ PyArray_FromBuffer(PyObject *buf, PyArray_Descr *type,
37633741
PyErr_SetString(PyExc_ValueError,
37643742
"buffer size must be a multiple"\
37653743
" of element size");
3766-
Py_DECREF(buf);
37673744
Py_DECREF(type);
37683745
return NULL;
37693746
}
@@ -3774,7 +3751,6 @@ PyArray_FromBuffer(PyObject *buf, PyArray_Descr *type,
37743751
PyErr_SetString(PyExc_ValueError,
37753752
"buffer is smaller than requested"\
37763753
" size");
3777-
Py_DECREF(buf);
37783754
Py_DECREF(type);
37793755
return NULL;
37803756
}
@@ -3784,7 +3760,6 @@ PyArray_FromBuffer(PyObject *buf, PyArray_Descr *type,
37843760
&PyArray_Type, type,
37853761
1, &n, NULL, data,
37863762
NPY_ARRAY_DEFAULT, NULL, buf);
3787-
Py_DECREF(buf);
37883763
if (ret == NULL) {
37893764
return NULL;
37903765
}

numpy/core/src/multiarray/multiarraymodule.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4492,7 +4492,6 @@ NPY_VISIBILITY_HIDDEN PyObject * npy_ma_str_array = NULL;
44924492
NPY_VISIBILITY_HIDDEN PyObject * npy_ma_str_array_prepare = NULL;
44934493
NPY_VISIBILITY_HIDDEN PyObject * npy_ma_str_array_wrap = NULL;
44944494
NPY_VISIBILITY_HIDDEN PyObject * npy_ma_str_array_finalize = NULL;
4495-
NPY_VISIBILITY_HIDDEN PyObject * npy_ma_str_buffer = NULL;
44964495
NPY_VISIBILITY_HIDDEN PyObject * npy_ma_str_ufunc = NULL;
44974496
NPY_VISIBILITY_HIDDEN PyObject * npy_ma_str_wrapped = NULL;
44984497
NPY_VISIBILITY_HIDDEN PyObject * npy_ma_str_order = NULL;
@@ -4509,7 +4508,6 @@ intern_strings(void)
45094508
npy_ma_str_array_prepare = PyUString_InternFromString("__array_prepare__");
45104509
npy_ma_str_array_wrap = PyUString_InternFromString("__array_wrap__");
45114510
npy_ma_str_array_finalize = PyUString_InternFromString("__array_finalize__");
4512-
npy_ma_str_buffer = PyUString_InternFromString("__buffer__");
45134511
npy_ma_str_ufunc = PyUString_InternFromString("__array_ufunc__");
45144512
npy_ma_str_wrapped = PyUString_InternFromString("__wrapped__");
45154513
npy_ma_str_order = PyUString_InternFromString("order");
@@ -4521,7 +4519,7 @@ intern_strings(void)
45214519

45224520
return npy_ma_str_array && npy_ma_str_array_prepare &&
45234521
npy_ma_str_array_wrap && npy_ma_str_array_finalize &&
4524-
npy_ma_str_buffer && npy_ma_str_ufunc && npy_ma_str_wrapped &&
4522+
npy_ma_str_ufunc && npy_ma_str_wrapped &&
45254523
npy_ma_str_order && npy_ma_str_copy && npy_ma_str_dtype &&
45264524
npy_ma_str_ndmin && npy_ma_str_axis1 && npy_ma_str_axis2;
45274525
}

numpy/core/src/multiarray/multiarraymodule.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ NPY_VISIBILITY_HIDDEN extern PyObject * npy_ma_str_array;
55
NPY_VISIBILITY_HIDDEN extern PyObject * npy_ma_str_array_prepare;
66
NPY_VISIBILITY_HIDDEN extern PyObject * npy_ma_str_array_wrap;
77
NPY_VISIBILITY_HIDDEN extern PyObject * npy_ma_str_array_finalize;
8-
NPY_VISIBILITY_HIDDEN extern PyObject * npy_ma_str_buffer;
98
NPY_VISIBILITY_HIDDEN extern PyObject * npy_ma_str_ufunc;
109
NPY_VISIBILITY_HIDDEN extern PyObject * npy_ma_str_wrapped;
1110
NPY_VISIBILITY_HIDDEN extern PyObject * npy_ma_str_order;

0 commit comments

Comments
 (0)