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

Bound numpy array dimensions at type-checking time where appropriate #145

Open
callumforrester opened this issue Sep 16, 2024 · 0 comments

Comments

@callumforrester
Copy link
Contributor

          BTW I recently discovered you can specify shape too, although most of numpy returns `shape=Any` so it's of limited use at the mo:
ScalarType_co = TypeVar("ScalarType_co", bound=np.generic, covariant=True)
OneDArray = np.ndarray[tuple[int], np.dtype[ScalarType_co]]
TwoDArray = np.ndarray[tuple[int, int], np.dtype[ScalarType_co]]

NPMask = OneDArray[np.bool]

Originally posted by @coretl in #143 (comment)

We can specify dimensional constraints in numpy.typing, so npt.NDArray[tuple[int, int], np.floating[Any]] for example.

There are probably specific places in scanspec where this would be useful, this issue is go through and find them.

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

1 participant