Skip to content

Fix typing of numpy arrays#144

Merged
alihamdan merged 1 commit intodevelopfrom
ndarray
Nov 2, 2023
Merged

Fix typing of numpy arrays#144
alihamdan merged 1 commit intodevelopfrom
ndarray

Conversation

@alihamdan
Copy link
Member

This PR fixes all annotations of numpy array and makes it explicit what type of array a function expects/returns.

We were using invalid numpy array annotations in some places and didn't precise the type of the array in other places. To properly type numpy array one needs to write this notation np.ndarray[Any, np.dtype[np.complex_]] where the first type is the shape of the array and the second is its type. This is not practical and is why numpy introduced numpy.typing.NDArray which can be simply used like NDArray[np.complex_]. Because we use this type a lot, I added a type alias.

This PR fixes all annotations of numpy array and makes it explicit
what type of array a function expects/returns.

We were using invalid numpy array annotations in some places and didn't precise
the type of the array in other places. To properly type numpy array one needs
to write this notation `np.ndarray[Any, np.dtype[np.complex_]]` where the first
type is the shape of the array and the second is its type. This is not practical
and is why numpy introduced `numpy.typing.NDArray` which can be simply used like
`NDArray[np.complex_]`. Because we use this type a lot, I added a type alias.
@alihamdan alihamdan added the enhancement New feature or request label Nov 2, 2023
@alihamdan alihamdan requested a review from benoit9126 November 2, 2023 17:19
@alihamdan alihamdan self-assigned this Nov 2, 2023
@alihamdan alihamdan merged commit 790deac into develop Nov 2, 2023
@alihamdan alihamdan deleted the ndarray branch November 2, 2023 19:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants