@@ -283,7 +283,16 @@ class _ArrayOrScalarCommon(
283
283
284
284
_BufferType = Union [ndarray , bytes , bytearray , memoryview ]
285
285
286
- class ndarray (_ArrayOrScalarCommon , Iterable , Sized , Container ):
286
+ _ArbitraryDtype = TypeVar ('_ArbitraryDtype' , bound = generic )
287
+ _ArrayDtype = TypeVar ('_ArrayDtype' , bound = generic )
288
+
289
+ class ndarray (
290
+ Generic [_ArrayDtype ],
291
+ _ArrayOrScalarCommon ,
292
+ Iterable ,
293
+ Sized ,
294
+ Container ,
295
+ ):
287
296
real : ndarray
288
297
imag : ndarray
289
298
def __new__ (
@@ -296,7 +305,7 @@ class ndarray(_ArrayOrScalarCommon, Iterable, Sized, Container):
296
305
order : Optional [str ] = ...,
297
306
) -> ndarray : ...
298
307
@property
299
- def dtype (self ) -> _Dtype : ...
308
+ def dtype (self ) -> Type [ _ArrayDtype ] : ...
300
309
@property
301
310
def ctypes (self ) -> _ctypes : ...
302
311
@property
@@ -326,6 +335,16 @@ class ndarray(_ArrayOrScalarCommon, Iterable, Sized, Container):
326
335
) -> None : ...
327
336
def dump (self , file : str ) -> None : ...
328
337
def dumps (self ) -> bytes : ...
338
+ @overload
339
+ def astype (
340
+ self ,
341
+ dtype : _ArbitraryDtype ,
342
+ order : str = ...,
343
+ casting : str = ...,
344
+ subok : bool = ...,
345
+ copy : bool = ...,
346
+ ) -> ndarray [_ArbitraryDtype ]: ...
347
+ @overload
329
348
def astype (
330
349
self ,
331
350
dtype : _DtypeLike ,
@@ -334,40 +353,74 @@ class ndarray(_ArrayOrScalarCommon, Iterable, Sized, Container):
334
353
subok : bool = ...,
335
354
copy : bool = ...,
336
355
) -> ndarray : ...
337
- def byteswap (self , inplace : bool = ...) -> ndarray : ...
338
- def copy (self , order : str = ...) -> ndarray : ...
356
+ def byteswap (self , inplace : bool = ...) -> ndarray [_ArrayDtype ]: ...
357
+ @overload
358
+ def copy (self ) -> ndarray [_ArrayDtype ]: ...
359
+ @overload
360
+ def copy (self , order : str = ...) -> ndarray [_ArrayDtype ]: ...
361
+ @overload
362
+ def view (self ) -> ndarray [_ArrayDtype ]: ...
339
363
@overload
340
364
def view (self , dtype : Type [_NdArraySubClass ]) -> _NdArraySubClass : ...
341
365
@overload
366
+ def view (self , dtype : Type [_ArbitraryDtype ]) -> ndarray [_ArbitraryDtype ]: ...
367
+ @overload
342
368
def view (self , dtype : _DtypeLike = ...) -> ndarray : ...
343
369
@overload
344
370
def view (
345
- self , dtype : _DtypeLike , type : Type [_NdArraySubClass ]
371
+ self ,
372
+ dtype : _ArbitraryDtype ,
373
+ type : Type [_NdarraySubClass ],
374
+ ) -> _NdArraySubClass [_ArbitraryDtype ]: ...
375
+ @overload
376
+ def view (
377
+ self ,
378
+ dtype : _DtypeLike ,
379
+ type : Type [_NdArraySubClass ],
346
380
) -> _NdArraySubClass : ...
347
381
@overload
348
382
def view (self , * , type : Type [_NdArraySubClass ]) -> _NdArraySubClass : ...
383
+ @overload
384
+ def getfield (
385
+ self ,
386
+ dtype : Type [_ArbitraryDtype ],
387
+ offset : int = ...,
388
+ ) -> ndarray [_ArbitraryDtype ]: ...
389
+ @overload
349
390
def getfield (self , dtype : Union [_DtypeLike , str ], offset : int = ...) -> ndarray : ...
350
391
def setflags (
351
392
self , write : bool = ..., align : bool = ..., uic : bool = ...
352
393
) -> None : ...
353
394
def fill (self , value : Any ) -> None : ...
354
395
# Shape manipulation
355
396
@overload
356
- def reshape (self , shape : Sequence [int ], * , order : str = ...) -> ndarray : ...
397
+ def reshape (
398
+ self ,
399
+ shape : Sequence [int ],
400
+ * ,
401
+ order : str = ...,
402
+ ) -> ndarray [_ArrayDtype ]: ...
357
403
@overload
358
- def reshape (self , * shape : int , order : str = ...) -> ndarray : ...
404
+ def reshape (
405
+ self ,
406
+ * shape : int ,
407
+ order : str = ...,
408
+ ) -> ndarray [_ArrayDtype ]: ...
359
409
@overload
360
410
def resize (self , new_shape : Sequence [int ], * , refcheck : bool = ...) -> None : ...
361
411
@overload
362
412
def resize (self , * new_shape : int , refcheck : bool = ...) -> None : ...
363
413
@overload
364
- def transpose (self , axes : Sequence [int ]) -> ndarray : ...
414
+ def transpose (self , axes : Sequence [int ]) -> ndarray [ _ArrayDtype ] : ...
365
415
@overload
366
- def transpose (self , * axes : int ) -> ndarray : ...
367
- def swapaxes (self , axis1 : int , axis2 : int ) -> ndarray : ...
368
- def flatten (self , order : str = ...) -> ndarray : ...
369
- def ravel (self , order : str = ...) -> ndarray : ...
370
- def squeeze (self , axis : Union [int , Tuple [int , ...]] = ...) -> ndarray : ...
416
+ def transpose (self , * axes : int ) -> ndarray [_ArrayDtype ]: ...
417
+ def swapaxes (self , axis1 : int , axis2 : int ) -> ndarray [_ArrayDtype ]: ...
418
+ def flatten (self , order : str = ...) -> ndarray [_ArrayDtype ]: ...
419
+ def ravel (self , order : str = ...) -> ndarray [_ArrayDtype ]: ...
420
+ def squeeze (
421
+ self ,
422
+ axis : Union [int , Tuple [int , ...]] = ...,
423
+ ) -> ndarray [_ArrayDtype ]: ...
371
424
# Many of these special methods are irrelevant currently, since protocols
372
425
# aren't supported yet. That said, I'm adding them for completeness.
373
426
# https://docs.python.org/3/reference/datamodel.html
@@ -472,6 +525,15 @@ class str_(character): ...
472
525
# float128, complex256
473
526
# float96
474
527
528
+ @overload
529
+ def array (
530
+ object : object ,
531
+ dtype : Type [_ArbitraryDtype ] = ...,
532
+ copy : bool = ...,
533
+ subok : bool = ...,
534
+ ndmin : int = ...,
535
+ ) -> ndarray [_ArbitraryDtype ]: ...
536
+ @overload
475
537
def array (
476
538
object : object ,
477
539
dtype : _DtypeLike = ...,
0 commit comments