Skip to content

ENH: Removed remnants of Python 2 buffer protocol from NumPy internals#31176

Open
Anushreebasics wants to merge 2 commits intonumpy:mainfrom
Anushreebasics:internals
Open

ENH: Removed remnants of Python 2 buffer protocol from NumPy internals#31176
Anushreebasics wants to merge 2 commits intonumpy:mainfrom
Anushreebasics:internals

Conversation

@Anushreebasics
Copy link
Copy Markdown

fixes #30813

First time committer introduction

Hi NumPy team, I’m a first-time contributor. I use NumPy regularly for array-heavy Python work, mainly for data processing and numerical experimentation. While working with NumPy internals/C-API docs, I noticed issue #30813 around legacy Python 2 buffer-protocol language and wanted to help modernize and clarify that path. This contribution is my attempt to reduce confusion for future contributors and keep the API/docs aligned with current behavior.

AI Disclosure

no AI tools were used

@Anushreebasics
Copy link
Copy Markdown
Author

Summary

It makes three main changes:

  • Adds a [DeprecationWarning] when [PyArray_BufferConverter] is used.

  • Moves internal ndarray construction to a private [_PyArray_Chunk] typedef so internal code no longer depends on the public alias.

  • Updates the C-API reference docs for [PyArray_BufferConverter] and [PyArray_Chunk] to describe the modern buffer-protocol behavior instead of the old single-segment/Python 2 framing.

@ngoldbaum @jorenham please review

Copy link
Copy Markdown
Member

@ngoldbaum ngoldbaum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some comments. FWIW it's OK if you used AI for PRs like this, you just need to disclose it.

npy_intp len;
int flags;
} _PyArray_Chunk;
#else
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why add this indirection if you're not going to deprecate using the struct or change it? I'd just keep it around and use the public version internally.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could also figure out a way to signal to users that this struct is deprecated. In that case it makes sense to add the indirection.

Comment thread numpy/_core/src/multiarray/conversion_utils.c
@Anushreebasics
Copy link
Copy Markdown
Author

@ngoldbaum please review the changes

Copy link
Copy Markdown
Member

@ngoldbaum ngoldbaum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! I marked it for the 2.5 release. Before this can be merged it needs a release note though. See doc/release/upcoming_changes/README.rst for instructions.

@Anushreebasics
Copy link
Copy Markdown
Author

@ngoldbaum I have added the release notes, please review the changes

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants