Skip to content

ENH: Remove remnants of Python 2 buffer protocol from NumPy internals #30813

Open

Description

@ngoldbaum

I'm noticing this because I'm touching the NumPy headers to fix #30704. That includes touching PyArray_Chunk.

It took me quite a while to understand what PyArray_Chunk and PyArray_BufferConverter are doing, because they're based on the very old "single-segment" buffer protocol. See PEP 3118 for more historical details.

PyArray_Chunk corresponds to PyBufferObject, which was completely removed from the Python C API in the 2->3 transition. See e.g. https://docs.python.org/2.7/c-api/buffer.html?highlight=pybufferobject#c.PyBufferObject.

The docs for PyArray_FromBuffer also talk about a single-segment buffer protocol, but that function has supported the "new" buffer protocol for a very long time.

PyArray_BufferConverter is publicly exposed, it's also used inside array_new, so it is somewhat load-bearing unfortunately.

As far as I can see, PyArray_BufferConverter has zero uses outside NumPy in public code on Github outside of copies of NumPy or wrappers around the entire NumPy C API: https://github.com/search?q=PyArray_BufferConverter&type=code&p=2. Maybe we can just deprecate the public version, along with PyArray_Chunk?

We should also update the docs to no longer talk about the Python 2 buffer protocol.

Possibly related issues:

#23305
#15450

Activity

  1. changed the title [-][ENH] Remove remnants of Python 2 buffer protocol from NumPy internals[/-] [+]ENH: Remove remnants of Python 2 buffer protocol from NumPy internals[/+] on Feb 10, 2026
  2. charris commented on Feb 10, 2026

    @charris
    Member

    That sounds good to me. If there is a problem, now would be when to find it.

  3. seberg commented on Feb 11, 2026

    @seberg
    Member

    This function is used for reinterpreting buffer imports that ignore the original type (frombuffer/new constructor). Talking about the old buffer protocol is wrong of course...

    But I am OK to deprecate it. It is unlikely NumPy users need it and non-NumPy users should use the buffer protocol directly.

  4. sharmavikas18 commented on Mar 7, 2026

    @sharmavikas18

    I would like to work on this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions