8
8
TYPE_CHECKING ,
9
9
ClassVar ,
10
10
Self ,
11
+ cast ,
11
12
get_args ,
13
+ overload ,
12
14
)
13
15
from uuid import UUID
14
16
28
30
29
31
from numpy .typing import NDArray
30
32
33
+ from pandas ._typing import (
34
+ Dtype ,
35
+ PositionalIndexer ,
36
+ ScalarIndexer ,
37
+ SequenceIndexer ,
38
+ )
39
+
31
40
from pandas .core .arrays .boolean import BooleanArray
32
41
33
42
@@ -89,16 +98,22 @@ def __init__(self, values: Iterable[UuidLike], *, copy: bool = False) -> None:
89
98
@classmethod
90
99
def _from_sequence (
91
100
cls ,
92
- data : Iterable [UuidLike ],
93
- dtype : UuidDtype | None = None ,
101
+ scalars : Iterable [UuidLike ],
102
+ * ,
103
+ dtype : Dtype | None = None ,
94
104
copy : bool = False ,
95
105
) -> Self :
96
106
if dtype is None :
97
107
dtype = UuidDtype ()
98
- return cls (data , copy = copy )
108
+ return cls (scalars , copy = copy )
109
+
110
+ @overload
111
+ def __getitem__ (self , index : ScalarIndexer ) -> UUID : ...
112
+ @overload
113
+ def __getitem__ (self , index : SequenceIndexer ) -> Self : ...
99
114
100
- def __getitem__ (self , index ) -> Self | UUID :
101
- if isinstance (index , int ):
115
+ def __getitem__ (self , index : PositionalIndexer ) -> Self | UUID :
116
+ if isinstance (index , int | np . integer ):
102
117
return UUID (bytes = self ._data [index ].tobytes ())
103
118
index = check_array_indexer (self , index )
104
119
return self ._simple_new (self ._data [index ])
@@ -107,17 +122,18 @@ def __len__(self) -> int:
107
122
return len (self ._data )
108
123
109
124
@unpack_zerodim_and_defer ("__eq__" )
110
- def __eq__ (self , other : object ) -> BooleanArray :
125
+ def __eq__ (self , other : object ) -> BooleanArray : # type: ignore[override]
111
126
return self ._cmp ("eq" , other )
112
127
128
+ @property
113
129
def nbytes (self ) -> int :
114
130
return self ._data .nbytes
115
131
116
132
def isna (self ) -> NDArray [np .bool_ ]:
117
133
return pd .isna (self ._data )
118
134
119
135
def take (
120
- self , indexer , * , allow_fill : bool = False , fill_value : UUID | None = None
136
+ self , indexer , * , allow_fill : bool = False , fill_value : object = None
121
137
) -> Self :
122
138
if allow_fill and fill_value is None :
123
139
fill_value = self .dtype .na_value
@@ -153,8 +169,7 @@ def _cmp(self, op: str, other) -> BooleanArray:
153
169
method = getattr (self ._data , f"__{ op } __" )
154
170
result = method (other )
155
171
156
- rv : BooleanArray = pd .array (result , dtype = "boolean" )
157
- return rv
172
+ return cast ("BooleanArray" , pd .array (result , dtype = "boolean" ))
158
173
159
174
160
175
def test_construct () -> None :
0 commit comments