labthings / labthings/labthings-fastapi
Accept `np.ndarray` as a typehint for actions/properties
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 9
- Forks
- 4
- PR merge metrics
- No merged PRs in 30d
Description
We use numpy a lot, so it would be great to be able to type hint numpy properly.
Currently we have to use: from labthings_fastapi.types.numpy import NDArray which works for sending things over HTTP but means the type hints are wrong when using the action from within the server.
Proposal
- Allow
np.ndarray - On seeing
np.ndarrayLabThings should convert it to a pydantic model this model can have the necessary data to reconstruct the array including dimensions and types
class NDArrayModel(BaseModel):
shape = list[int]
d_type = Literal["bool"], Literal["int"], Literal["float"], Literal["uint8"], Literal["uint16"]
data = list[int]|list[bool]|list[float]
This way we can serialise the data as a 1D list along with the information for how to contruct the correct array. In a ThingClient the array should be able to be reconstructed. In Javascript or any other language there is enough information to process the result.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the existing labthings_fastapi.types.numpy.NDArray type and the ThingClient path that reconstructs returned values. Trace how action and property type hints are converted for HTTP, then define what metadata is needed for shape, dtype, and flattened data. Done means np.ndarray is accepted and arrays can be serialized and reconstructed across the server and client.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- numpy, python
- Domain
- api, backend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 40/100