20
20
from pandas .core .construction import extract_array
21
21
from pandas .core .indexers import check_array_indexer
22
22
23
- _T = TypeVar ("_T" , bound = "NDArrayBackedExtensionArray" )
23
+ NDArrayBackedExtensionArrayT = TypeVar (
24
+ "NDArrayBackedExtensionArrayT" , bound = "NDArrayBackedExtensionArray"
25
+ )
24
26
25
27
26
28
class NDArrayBackedExtensionArray (ExtensionArray ):
@@ -30,7 +32,9 @@ class NDArrayBackedExtensionArray(ExtensionArray):
30
32
31
33
_ndarray : np .ndarray
32
34
33
- def _from_backing_data (self : _T , arr : np .ndarray ) -> _T :
35
+ def _from_backing_data (
36
+ self : NDArrayBackedExtensionArrayT , arr : np .ndarray
37
+ ) -> NDArrayBackedExtensionArrayT :
34
38
"""
35
39
Construct a new ExtensionArray `new_array` with `arr` as its _ndarray.
36
40
@@ -52,13 +56,13 @@ def _validate_scalar(self, value):
52
56
# ------------------------------------------------------------------------
53
57
54
58
def take (
55
- self : _T ,
59
+ self : NDArrayBackedExtensionArrayT ,
56
60
indices : Sequence [int ],
57
61
* ,
58
62
allow_fill : bool = False ,
59
63
fill_value : Any = None ,
60
64
axis : int = 0 ,
61
- ) -> _T :
65
+ ) -> NDArrayBackedExtensionArrayT :
62
66
if allow_fill :
63
67
fill_value = self ._validate_fill_value (fill_value )
64
68
@@ -113,16 +117,20 @@ def size(self) -> int:
113
117
def nbytes (self ) -> int :
114
118
return self ._ndarray .nbytes
115
119
116
- def reshape (self : _T , * args , ** kwargs ) -> _T :
120
+ def reshape (
121
+ self : NDArrayBackedExtensionArrayT , * args , ** kwargs
122
+ ) -> NDArrayBackedExtensionArrayT :
117
123
new_data = self ._ndarray .reshape (* args , ** kwargs )
118
124
return self ._from_backing_data (new_data )
119
125
120
- def ravel (self : _T , * args , ** kwargs ) -> _T :
126
+ def ravel (
127
+ self : NDArrayBackedExtensionArrayT , * args , ** kwargs
128
+ ) -> NDArrayBackedExtensionArrayT :
121
129
new_data = self ._ndarray .ravel (* args , ** kwargs )
122
130
return self ._from_backing_data (new_data )
123
131
124
132
@property
125
- def T (self : _T ) -> _T :
133
+ def T (self : NDArrayBackedExtensionArrayT ) -> NDArrayBackedExtensionArrayT :
126
134
new_data = self ._ndarray .T
127
135
return self ._from_backing_data (new_data )
128
136
@@ -138,11 +146,13 @@ def equals(self, other) -> bool:
138
146
def _values_for_argsort (self ):
139
147
return self ._ndarray
140
148
141
- def copy (self : _T ) -> _T :
149
+ def copy (self : NDArrayBackedExtensionArrayT ) -> NDArrayBackedExtensionArrayT :
142
150
new_data = self ._ndarray .copy ()
143
151
return self ._from_backing_data (new_data )
144
152
145
- def repeat (self : _T , repeats , axis = None ) -> _T :
153
+ def repeat (
154
+ self : NDArrayBackedExtensionArrayT , repeats , axis = None
155
+ ) -> NDArrayBackedExtensionArrayT :
146
156
"""
147
157
Repeat elements of an array.
148
158
@@ -154,7 +164,7 @@ def repeat(self: _T, repeats, axis=None) -> _T:
154
164
new_data = self ._ndarray .repeat (repeats , axis = axis )
155
165
return self ._from_backing_data (new_data )
156
166
157
- def unique (self : _T ) -> _T :
167
+ def unique (self : NDArrayBackedExtensionArrayT ) -> NDArrayBackedExtensionArrayT :
158
168
new_data = unique (self ._ndarray )
159
169
return self ._from_backing_data (new_data )
160
170
@@ -216,7 +226,9 @@ def __getitem__(self, key):
216
226
return result
217
227
218
228
@doc (ExtensionArray .fillna )
219
- def fillna (self : _T , value = None , method = None , limit = None ) -> _T :
229
+ def fillna (
230
+ self : NDArrayBackedExtensionArrayT , value = None , method = None , limit = None
231
+ ) -> NDArrayBackedExtensionArrayT :
220
232
value , method = validate_fillna_kwargs (value , method )
221
233
222
234
mask = self .isna ()
0 commit comments