Accept `np.ndarray` as a typehint for actions/properties
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 40/100
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.
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.
- Dominant language
- Python
- Stars
- 9
- Forks
- 4
- PR merge metrics
- No merged PRs in 30d
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.
More from labthings/labthings-fastapi
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
labthings/labthings-fastapi#405 ·
-
drop-python-version
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
labthings/labthings-fastapi#354 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
labthings/labthings-fastapi#312 · 1 comment ·
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
labthings/labthings-fastapi#404 · 2 comments ·
-
Difficulty 3/5 1-2 days Newbie friendliness 63/100
labthings/labthings-fastapi#403 · 1 comment ·
All issues in labthings/labthings-fastapi
Similar issues
-
area: harness bug status: needs-triage
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Human-Agent-Society/reef#625 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
-
Difficulty 1/5 Under an hour Newbie friendliness 80/100
learningequality/kolibri#15351 · 2 comments ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
Name consistency Open
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
eellak/triplestore#65 · 1 comment ·