-
Notifications
You must be signed in to change notification settings - Fork 54
__index__ method #231
Copy link
Copy link
Closed
Labels
API extensionAdds new functions or objects to the API.Adds new functions or objects to the API.topic: IndexingArray indexing.Array indexing.
Metadata
Metadata
Assignees
Labels
API extensionAdds new functions or objects to the API.Adds new functions or objects to the API.topic: IndexingArray indexing.Array indexing.
Type
Fields
Give feedbackNo fields configured for issues without a type.
I just noticed that the
__index__method is missing from the array object specification. See https://www.python.org/dev/peps/pep-0357/.__index__should returnint(self)if the input is a 0-D array with integer dtype, and raise TypeError otherwise (similar to__int__except it doesn't work on floating-point arrays). This will allow 0-D integer arrays to be used as indices. While this is not strictly necessary for an array type to support itself as an index, it does mean that things like indexing Python lists with 0-D arrays will work correctly, and it's generally a good Python practice to do this for integer-like types.