Skip to content
This repository was archived by the owner on Jun 10, 2020. It is now read-only.

WiP: Added type annotations for the np.core.fromnumeric module #59

Closed
wants to merge 11 commits into from
Closed

WiP: Added type annotations for the np.core.fromnumeric module #59

wants to merge 11 commits into from

Conversation

BvB93
Copy link
Member

@BvB93 BvB93 commented Apr 19, 2020

See https://github.com/numpy/numpy-stubs/issues/54.

Introduced type hints for all (public) functions from the np.core.fromnumeric module.

Note that typing_extensions has also been added as a dependency for Python version prior to 3.8. See #63.

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 and alltrue

To do

  • Add reveal tests
  • Add pass tests
  • Add fail tests

Bas van Beek added 9 commits April 18, 2020 16:13
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))
@person142
Copy link
Member

Note that typing_extensions has also been added as a dependency for Python version prior to 3.8.

This should be fine, but let me open an issue to give people a chance to object.

@person142
Copy link
Member

@BvB93 actually would you mind making a separate PR just to add typing_extensions? Assuming no objections on #60 (unlikely I think) we can get it in asap-there have been a number of places where it would be useful.

@BvB93
Copy link
Member Author

BvB93 commented Apr 20, 2020

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):
Copy link
Member Author

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]
Copy link
Member Author

@BvB93 BvB93 Apr 20, 2020

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.

@BvB93 BvB93 marked this pull request as ready for review April 20, 2020 17:05
@person142
Copy link
Member

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.)

@BvB93
Copy link
Member Author

BvB93 commented Apr 21, 2020

No problem, I'll create a new (smaller) pull request later today with the first set of changes.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants