Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOC: document the typing conventions for generic ndarray #22506

Open
kwsp opened this issue Oct 31, 2022 · 1 comment
Open

DOC: document the typing conventions for generic ndarray #22506

kwsp opened this issue Oct 31, 2022 · 1 comment

Comments

@kwsp
Copy link

kwsp commented Oct 31, 2022

Issue with current documentation:

Currently it isn't obvious how one should type ndarray: should one type them like ndarray[shape, dtype] or ndarray[dtype, shape]?

In the few places in the docs where I think this is relevant, no information is given as to how one should type ndarray:

Both pages link to numpy.typing.NDArray, it appears that one should follow the convention of ndarray[shape, dtype]

numpy.typing.NDArray = numpy.ndarray[typing.Any, numpy.dtype[+ScalarType]]

Idea or request for content:

If that is the case, should we make this explicit in the two doc pages linked above?

I came across this issue recently when I was writing some custom serialization/deserialization functions that take into account the shape and type of ndarrays from the type annotations, and found the typing convention isn't clearly documented. Having a convention for annotation ndarray could help make the type annotations more interoperable.

@kwsp
Copy link
Author

kwsp commented Mar 16, 2023

Relevant discussions on how to type shapes: #16544

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

No branches or pull requests

2 participants