2
2
3
3
__all__ = ["array" ]
4
4
5
+ from typing import SupportsIndex
5
6
from ._types import (
6
7
array ,
7
8
dtype as Dtype ,
@@ -604,11 +605,11 @@ def __ge__(self: array, other: Union[int, float, array], /) -> array:
604
605
def __getitem__ (
605
606
self : array ,
606
607
key : Union [
607
- int ,
608
+ SupportsIndex ,
608
609
slice ,
609
610
ellipsis ,
610
611
None ,
611
- Tuple [Union [int , slice , ellipsis , None ], ...],
612
+ Tuple [Union [SupportsIndex , slice , ellipsis , None ], ...],
612
613
array ,
613
614
],
614
615
/ ,
@@ -620,9 +621,13 @@ def __getitem__(
620
621
----------
621
622
self: array
622
623
array instance.
623
- key: Union[int , slice, ellipsis, None, Tuple[Union[int , slice, ellipsis, None], ...], array]
624
+ key: Union[SupportsIndex , slice, ellipsis, None, Tuple[Union[SupportsIndex , slice, ellipsis, None], ...], array]
624
625
index key.
625
626
627
+
628
+ .. note::
629
+ ``key`` can only be an array if it is valid for boolean array indexing, or supports ``__index__()``.
630
+
626
631
Returns
627
632
-------
628
633
out: array
@@ -1077,7 +1082,7 @@ def __rshift__(self: array, other: Union[int, array], /) -> array:
1077
1082
def __setitem__ (
1078
1083
self : array ,
1079
1084
key : Union [
1080
- int , slice , ellipsis , Tuple [Union [int , slice , ellipsis ], ...], array
1085
+ SupportsIndex , slice , ellipsis , Tuple [Union [SupportsIndex , slice , ellipsis ], ...], array
1081
1086
],
1082
1087
value : Union [int , float , bool , array ],
1083
1088
/ ,
@@ -1089,11 +1094,13 @@ def __setitem__(
1089
1094
----------
1090
1095
self: array
1091
1096
array instance.
1092
- key: Union[int , slice, ellipsis, Tuple[Union[int , slice, ellipsis], ...], array]
1097
+ key: Union[SupportsIndex , slice, ellipsis, Tuple[Union[SupportsIndex , slice, ellipsis], ...], array]
1093
1098
index key.
1094
1099
value: Union[int, float, bool, array]
1095
1100
value(s) to set. Must be compatible with ``self[key]`` (see :ref:`broadcasting`).
1096
1101
1102
+ .. note::
1103
+ ``key`` can only be an array if it is valid for boolean array indexing, or supports ``__index__()``.
1097
1104
1098
1105
.. note::
1099
1106
0 commit comments