-
-
Notifications
You must be signed in to change notification settings - Fork 31
WiP: A
10000
dded type annotations for the np.core.fromnumeric
module
#59
Conversation
See https://github.com/numpy/numpy-stubs/issues/54. Added annotations and tests for: * np.warnings * np.ModuleDeprecationWarning * np.VisibleDeprecationWarning * np.ComplexWarning * np.RankWarning * np.TooHardError * np.AxisError
* Removed ``warnings`` (#57 (comment)) * Deleted a now redundant comment (#57 (comment)) * Created and/or moved a number of tests to fail/ and reveal/ (#57 (comment) and #57 (comment)) * Formatted the main __init__.pyi file with black (#57 (review))
This should be fine, but let me open an issue to give people a chance to object. |
No problem, I've just created the pull request at #63. |
* Added new overloads to the ``np.core.fromnumeric`` functions. * Added the ``_ArrayOrScalarCommon.__array__()`` method. * Added the ``_ArrayLikeSeq`` Protocol. * Renamed ``_Scalar`` to ``_ScalarNumeric``. * Wrapped up the reveal tests. * Removed ``typing_extenions`` from the dependencies; see #63
# Can be used as such `Union[Sequence[T], _ArrayLikeSeq]` as ndarray | ||
# is not a proper Sequence | ||
# TODO: Specify the to-be returned array type once ndarray is a Generic | ||
class _ArrayLikeSeq(Protocol): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Union[Sequence[T], _ArrayLikeSeq]
can be used for annotating sequences, as ndarray
is technically not a proper sequence.
In the future (once ndarray is a generic) this can be changed into Union[Sequence[T], _ArrayLikeSeq[T]]
# would be more suited here but they have one significant disadvatange: | ||
# all these methods are also defined available in ndarray, | ||
# which has no guarantee of being scalar-esque (i.e. a 0D array) | ||
_ScalarNumeric = Union[int, float, complex, bool, bool_, number] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not the most ideal solution (due to the lack of duck-typing) but it serves its purpose.
I see that the diff here has become quite large-I would appreciate it if you could split this into several smaller PRs. (At the end of a work day it's easier to motivate myself to review small pieces of code.) |
No problem, I'll create a new (smaller) pull request later today with the first set of changes. |
See https://github.com/numpy/numpy-stubs/issues/54.
Introduced type hints for all (public) functions from the
np.core.fromnumeric
module.Note thatSee #63.typing_extensions
has also been added as a dependency for Python version prior to 3.8.Functions
take
reshape
choose
repeat
put
swapaxes
transpose
partition
argpartition
sort
argsort
argmax
argmin
searchsorted
resize
squeeze
diagonal
trace
ravel
nonzero
shape
compress
clip
sum
all
any
cumsum
ptp
amax
amin
alen
prod
cumprod
ndim
size
around
mean
std
var
round_
,product
,cumproduct
,sometrue
andalltrue
To do