Skip to content

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

@callumforrester

Description

@callumforrester
          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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions