Skip to content

More granular type hints for numpy.ndarray's #383

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

Open
ascillitoe opened this issue Nov 17, 2021 · 1 comment
Open

More granular type hints for numpy.ndarray's #383

ascillitoe opened this issue Nov 17, 2021 · 1 comment

Comments

@ascillitoe
Copy link
Contributor

There are numerous places in alibi-detect where we type hint method arguments with the rather generic np.ndarray, but actually only expect certain dtypes. For example the upcoming FET detectors, and SpectralResidual (see #382). This could be dealt with purely through a little more documentation, but it might also be advantageous to explore more granular type hints.

The above is related to SeldonIO/alibi#513 and SeldonIO/alibi#511, or we could use numpy's inbuilt capability (https://numpy.org/doc/1.21/reference/typing.html#numpy.typing.NDArray for dtypes, and at some point numpy/numpy#16544 for shapes). The latter would however cause issues with old numpy version compatibility.

@jklaise
Copy link
Contributor

jklaise commented Nov 17, 2021

Yea unfortunately we can't just update to numpy>=1.21 and there also doesn't seem to be a backport of these new numpy types. I think it might be a good use case of beartype validators.

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

No branches or pull requests

2 participants