10000 MAINT: Remove Python2 newbuffer getbuffer by sethtroisi · Pull Request #15239 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

MAINT: Remove Python2 newbuffer getbuffer #15239

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 2 additions & 55 deletions numpy/core/_add_newdocs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1034,7 +1034,7 @@
A string containing the data.
dtype : data-type, optional
The data type of the array; default: float. For binary input data,
the data must be in exactly this format. Most builtin numeric types are
the data must be in exactly this format. Most builtin numeric types are
supported and extension types may be supported.

.. versionadded:: 1.18.0
Expand Down Expand Up @@ -1484,59 +1484,6 @@

""")

if sys.version_info.major < 3:
add_newdoc('numpy.core.multiarray', 'newbuffer',
"""
newbuffer(size)

Return a new uninitialized buffer object.

Parameters
----------
size : int
Size in bytes of returned buffer object.

Returns
-------
newbuffer : buffer object
Returned, uninitialized buffer object of `size` bytes.

""")

add_newdoc('numpy.core.multiarray', 'getbuffer',
"""
getbuffer(obj [,offset[, size]])

Create a buffer object from the given object referencing a slice of
length size starting at offset.

Default is the entire buffer. A read-write buffer is attempted followed
by a read-only buffer.

Parameters
----------
obj : object

offset : int, optional

size : int, optional

Returns
-------
buffer_obj : buffer

Examples
--------
>>> buf = np.getbuffer(np.ones(5), 1, 3)
>>> len(buf)
3
>>> buf[0]
'\\x00'
>>> buf
<read-write buffer for 0x8af1e70, size 3, offset 1 at 0x8ba4ec0>

""")

add_newdoc('numpy.core.multiarray', 'c_einsum',
"""
c_einsum(subscripts, *operands, out=None, dtype=None, order='K',
Expand Down Expand Up @@ -3951,7 +3898,7 @@

Examples
--------
For a 1D array, ``a.tolist()`` is almost the same as ``list(a)``,
For a 1D array, ``a.tolist()`` is almost the same as ``list(a)``,
except that ``tolist`` changes numpy scalars to Python scalars:

>>> a = np.uint32([1, 2])
Expand Down
2 changes: 0 additions & 2 deletions numpy/core/multiarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@
'set_string_function', 'set_typeDict', 'shares_memory', 'test_interrupt',
'tracemalloc_domain', 'typeinfo', 'unpackbits', 'unravel_index', 'vdot',
'where', 'zeros']
if sys.version_info.major < 3:
__all__ += ['newbuffer', 'getbuffer']

# For backward compatibility, make sure pickle imports these functions from here
_reconstruct.__module__ = 'numpy.core.multiarray'
Expand Down
5 changes: 0 additions & 5 deletions numpy/core/numeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
min_scalar_type, ndarray, nditer, nested_iters, promote_types,
putmask, result_type, set_numeric_ops, shares_memory, vdot, where,
zeros, normalize_axis_index)
if sys.version_info[0] < 3:
from .multiarray import newbuffer, getbuffer

from . import overrides
from . import umath
Expand Down Expand Up @@ -65,9 +63,6 @@
'matmul', 'shares_memory', 'may_share_memory', 'MAY_SHARE_BOUNDS',
'MAY_SHARE_EXACT', 'TooHardError', 'AxisError']

if sys.version_info[0] < 3:
__all__.extend(['getbuffer', 'newbuffer'])


@set_module('numpy')
class ComplexWarning(RuntimeWarning):
Expand Down
44 changes: 0 additions & 44 deletions numpy/core/src/multiarray/multiarraymodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -3293,42 +3293,6 @@ array_datetime_data(PyObject *NPY_UNUSED(dummy), PyObject *args)
return convert_datetime_metadata_to_tuple(meta);
}

#if !defined(NPY_PY3K)
static PyObject *
new_buffer(PyObject *NPY_UNUSED(dummy), PyObject *args)
{
int size;

if (!PyArg_ParseTuple(args, "i:buffer", &size)) {
return NULL;
}
return PyBuffer_New(size);
}

static PyObject *
buffer_buffer(PyObject *NPY_UNUSED(dummy), PyObject *args, PyObject *kwds)
{
PyObject *obj;
Py_ssize_t offset = 0, n;
Py_ssize_t size = Py_END_OF_BUFFER;
void *unused;
static char *kwlist[] = {"object", "offset", "size", NULL};

if (!PyArg_ParseTupleAndKeywords(args, kwds,
"O|" NPY_SSIZE_T_PYFMT NPY_SSIZE_T_PYFMT ":get_buffer", kwlist,
&obj, &offset, &size)) {
return NULL;
}
if (PyObject_AsWriteBuffer(obj, &unused, &n) < 0) {
PyErr_Clear();
return PyBuffer_FromObject(obj, offset, size);
}
else {
return PyBuffer_FromReadWriteObject(obj, offset, size);
}
}
#endif

/*
* Prints floating-point scalars using the Dragon4 algorithm, scientific mode.
* See docstring of `np.format_float_scientific` for description of arguments.
Expand Down Expand Up @@ -4137,14 +4101,6 @@ static struct PyMethodDef array_module_methods[] = {
{"is_busday",
(PyCFunction)array_is_busday,
METH_VARARGS | METH_KEYWORDS, NULL},
#if !defined(NPY_PY3K)
{"newbuffer",
(PyCFunction)new_buffer,
METH_VARARGS, NULL},
{"getbuffer",
(PyCFunction)buffer_buffer,
METH_VARARGS | METH_KEYWORDS, NULL},
#endif
{"format_longfloat",
(PyCFunction)format_longfloat,
METH_VARARGS | METH_KEYWORDS, NULL},
Expand Down
0