Skip to content

Transition PyArray_PythonPyIntFromInt to modern behavior #32590

Description

@seberg

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.)

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions