-
-
Notifications
You must be signed in to change notification settings - Fork 31
MAINT: Introduced a couple of fixes for the np.core.fromnumeric functions #74
Changes from 4 commits
22a8632
4e2e6bf
fcd4e46
062947b
443b301
e519d92
911eed0
cda1e70
45158c1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -93,6 +93,7 @@ _DtypeLike = Union[ | |
_NdArraySubClass = TypeVar("_NdArraySubClass", bound=ndarray) | ||
|
||
_ArrayLike = TypeVar("_ArrayLike") | ||
_ArrayLikeNested = Any # TODO: wait for support for recursive types | ||
|
||
class dtype: | ||
names: Optional[Tuple[str, ...]] | ||
|
@@ -803,6 +804,7 @@ _Mode = Literal["raise", "wrap", "clip"] | |
_Order = Literal["C", "F", "A"] | ||
_PartitionKind = Literal["introselect"] | ||
_SortKind = Literal["quicksort", "mergesort", "heapsort", "stable"] | ||
_Side = Literal["left", "right"] | ||
|
||
# Various annotations for scalars | ||
|
||
|
@@ -813,14 +815,27 @@ _ScalarNumpy = Union[generic, dt.datetime, dt.timedelta] | |
_ScalarBuiltin = Union[str, bytes, dt.date, dt.timedelta, bool, int, float, complex] | ||
_Scalar = Union[_ScalarBuiltin, _ScalarNumpy] | ||
|
||
_ScalarGeneric = TypeVar( | ||
"_ScalarGeneric", bound=Union[dt.datetime, dt.timedelta, generic] | ||
# Integers and booleans can generally be used interchangeably | ||
_ScalarInt = TypeVar("_ScalarInt", bound=Union[integer, bool_]) | ||
|
||
_ScalarGeneric = TypeVar("_ScalarGeneric", bound=generic) | ||
_ScalarGenericPlus = TypeVar( | ||
|
||
"_ScalarGenericPlus", bound=Union[dt.datetime, dt.timedelta, generic] | ||
) | ||
|
||
# An array-like object consisting of integers | ||
_Int = Union[int, integer] | ||
_Int = Union[int, integer, bool, bool_] | ||
|
||
_Bool = Union[bool, bool_] | ||
_ArrayLikeIntNested = Any # TODO: wait for support for recursive types | ||
_ArrayLikeInt = Union[_Int, ndarray, Sequence[_Int], Sequence[_ArrayLikeIntNested]] | ||
_ArrayLikeBoolNested = Any # TODO: wait for support for recursive types | ||
|
||
# Integers and booleans can generally be used interchangeably | ||
_ArrayLikeInt = Union[ | ||
|
||
_Int, | ||
ndarray, | ||
Sequence[_Int], | ||
Sequence[_ArrayLikeIntNested], | ||
Sequence[_ArrayLikeBoolNested], | ||
] | ||
|
||
# The signature of take() follows a common theme with its overloads: | ||
# 1. A generic comes in; the same generic comes out | ||
|
@@ -829,12 +844,12 @@ _ArrayLikeInt = Union[_Int, ndarray, Sequence[_Int], Sequence[_ArrayLikeIntNeste | |
# 4. An array-like object comes in; an ndarray or generic comes out | ||
@overload | ||
def take( | ||
a: _ScalarGeneric, | ||
a: _ScalarGenericPlus, | ||
indices: int, | ||
axis: Optional[int] = ..., | ||
out: Optional[ndarray] = ..., | ||
mode: _Mode = ..., | ||
) -> _ScalarGeneric: ... | ||
) -> _ScalarGenericPlus: ... | ||
@overload | ||
def take( | ||
a: _Scalar, | ||
|
@@ -862,21 +877,21 @@ def take( | |
def reshape(a: _ArrayLike, newshape: _ShapeLike, order: _Order = ...) -> ndarray: ... | ||
@overload | ||
def choose( | ||
a: _ScalarGeneric, | ||
a: _ScalarInt, | ||
choices: Union[Sequence[_ArrayLike], ndarray], | ||
out: Optional[ndarray] = ..., | ||
mode: _Mode = ..., | ||
) -> _ScalarGeneric: ... | ||
) -> _ScalarInt: ... | ||
@overload | ||
def choose( | ||
a: _Scalar, | ||
a: _Int, | ||
choices: Union[Sequence[_ArrayLike], ndarray], | ||
out: Optional[ndarray] = ..., | ||
mode: _Mode = ..., | ||
) -> _ScalarNumpy: ... | ||
) -> Union[integer, bool_]: ... | ||
@overload | ||
def choose( | ||
a: _ArrayLike, | ||
a: _ArrayLikeInt, | ||
|
||
choices: Union[Sequence[_ArrayLike], ndarray], | ||
out: Optional[ndarray] = ..., | ||
mode: _Mode = ..., | ||
|
@@ -886,7 +901,7 @@ def repeat( | |
) -> ndarray: ... | ||
def put(a: ndarray, ind: _ArrayLikeInt, v: _ArrayLike, mode: _Mode = ...) -> None: ... | ||
def swapaxes( | ||
a: Union[Sequence[_ArrayLike], ndarray], axis1: int, axis2: int | ||
a: Union[Sequence[_ArrayLikeNested], ndarray], axis1: int, axis2: int | ||
) -> ndarray: ... | ||
def transpose( | ||
a: _ArrayLike, axes: Union[None, Sequence[int], ndarray] = ... | ||
|
@@ -898,6 +913,23 @@ def partition( | |
kind: _PartitionKind = ..., | ||
order: Union[None, str, Sequence[str]] = ..., | ||
) -> ndarray: ... | ||
@overload | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The behaviour of However, if a builtin scalar is passed it also returns a >>> import numpy as np
>>> type(np.argpartition(0, 0))
numpy.ndarray
>>> type(np.argpartition(np.int64(0), 0))
numpy.int64 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ouch. Sounds like it could potentially be worthy of opening an issue against NumPy. |
||
def argpartition( | ||
a: generic, | ||
kth: _ArrayLikeInt, | ||
axis: Optional[int] = ..., | ||
kind: _PartitionKind = ..., | ||
order: Union[None, str, Sequence[str]] = ..., | ||
) -> integer: ... | ||
@overload | ||
def argpartition( | ||
a: _ScalarBuiltin, | ||
kth: _ArrayLikeInt, | ||
axis: Optional[int] = ..., | ||
kind: _PartitionKind = ..., | ||
order: Union[None, str, Sequence[str]] = ..., | ||
) -> ndarray: ... | ||
@overload | ||
def argpartition( | ||
a: _ArrayLike, | ||
kth: _ArrayLikeInt, | ||
|
@@ -906,13 +938,13 @@ def argpartition( | |
order: Union[None, str, Sequence[str]] = ..., | ||
) -> ndarray: ... | ||
def sort( | ||
a: Union[Sequence[_ArrayLike], ndarray], | ||
a: Union[Sequence[_ArrayLikeNested], ndarray], | ||
axis: Optional[int] = ..., | ||
kind: Optional[_SortKind] = ..., | ||
order: Union[None, str, Sequence[str]] = ..., | ||
) -> ndarray: ... | ||
def argsort( | ||
a: Union[Sequence[_ArrayLike], ndarray], | ||
a: Union[Sequence[_ArrayLikeNested], ndarray], | ||
axis: Optional[int] = ..., | ||
kind: Optional[_SortKind] = ..., | ||
order: Union[None, str, Sequence[str]] = ..., | ||
|
Uh oh!
There was an error while loading. Please reload this page.