Skip to content

Add to_dict and from_dict methods to Labware#113

Merged
michaelosthege merged 2 commits intomasterfrom
labware-serialization
Mar 31, 2026
Merged

Add to_dict and from_dict methods to Labware#113
michaelosthege merged 2 commits intomasterfrom
labware-serialization

Conversation

@michaelosthege
Copy link
Copy Markdown
Member

Goals

  • Make it easy to serialize labware to dictionaries of only atomic types (no NumPy arrays) and to re-instantiate labware from such dicts.
  • Make Labware.from_dict also work for recreating Trough labware based on the data.

Implementation details

Trough types have different __init__ parameters (rows vs. virtual_rows) just like derived types can have different init parameters or attributes.

I implemented _from_dict_init_kwargs and _from_dict_attributes which can be overriden by derived types to account for customization.

Some (hopefully) clever logic was necessary to support buffers_trough = Labware.from_dict(data) returning Trough objects even if that does not give a definite type hint.

@michaelosthege michaelosthege self-assigned this Mar 31, 2026
@michaelosthege michaelosthege added the enhancement New feature or request label Mar 31, 2026
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 31, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.85%. Comparing base (0391cde) to head (00aa3a7).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #113      +/-   ##
==========================================
+ Coverage   95.74%   95.85%   +0.10%     
==========================================
  Files          19       19              
  Lines        1198     1229      +31     
==========================================
+ Hits         1147     1178      +31     
  Misses         51       51              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@michaelosthege michaelosthege force-pushed the labware-serialization branch from 2878fc3 to 5b1e170 Compare March 31, 2026 14:02
@michaelosthege michaelosthege force-pushed the labware-serialization branch from 5b1e170 to 00aa3a7 Compare March 31, 2026 14:42
@michaelosthege michaelosthege merged commit 539d966 into master Mar 31, 2026
8 checks passed
@michaelosthege michaelosthege deleted the labware-serialization branch March 31, 2026 15:36
@github-actions github-actions bot locked and limited conversation to collaborators Mar 31, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants