numpy / numpy/numpy

Transition `PyArray_PythonPyIntFromInt` to modern behavior

Open
#32,590 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

00 - Bug 07 - Deprecation sustain-2026
Dominant language
Python
Stars
32.8k
Forks
12.8k
Avg merge
1d 7h
Merged PRs (30d)
197

Description

PyArray_PythonPyIntFromInt existed to not change behavior of existing code that used the "i" format in Python.
But along the way, Python fixed their things, the conversion now uses __index__ as it should and rejects all non-integers (not just floats explictly).

We missed that and while we used to be ahead of the curve we are now behind here. So what we should do is:

  • Try the __index__ style conversion. (this is a tiny bug fix as well)
  • If that fails, try current code with a warning.

It would be nice to audit if there are remaining "i" uses that matters, because if there aren't we can be clearer about when the warning was introduced (i.e. we won't use it for more functions).

Additionally, it may be nice to do a check whether all integers are used in places where NumPy may just want to directly transition to our integer conversion helpers. These differ in that NumPy sometimes rejects booleans.
(This doesn't matter much either way, the bool rejecting matters mostly in places that are slightly indexing related.)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Locate PyArray_PythonPyIntFromInt and trace its current conversion path and warning behavior. Audit remaining "i" uses and related integer conversion helpers, then verify that __index__ is attempted first, the fallback warns, and relevant conversion behavior is covered by tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.