Skip to content

Add labeled-data file reading and writing - #17

Draft
C-Achard wants to merge 3 commits into
cy/io-checksfrom
cy/io-labeled-data-file
Draft

C-Achard wants to merge 3 commits into
cy/io-checksfrom
cy/io-labeled-data-file

Conversation

@C-Achard

Copy link
Copy Markdown
Member

The public labeled-data file API: read_labeled_data, write_labeled_data, LabeledDataFile.

Writes

  • A write always produces DeepLabCut's current form: one df_with_missing key, a 3- or 4-level header, the row index split into path parts. Rewriting a legacy file therefore converts it; DeepLabCut 3.0.2 reads both forms. Writing a file back in the form found was rejected: it would make every old form a rule of the writer.
  • The CSV twin is an export, and now treated strictly as a readable copy of the H5. The H5 is authoritative and carries the writer stamp; the CSV carries none. A hand-edited CSV is not read back as a second source of truth, unless conversion is explicitly performed.
  • The .h5 and its .csv twin are written to temporary files beside the target and swapped in only once both are complete.
  • No file locking due to cross-platform complexity and lack of support in current consumers. Accepted limits: the H5 and the CSV are not replaced as one atomic step, and on Windows a replace fails, and raises, while another process holds the file open.
  • A write replaces a file only if it is unchanged since it was read (replaces=), or creates one if none exists.
  • Refused: likelihood in human labels, empty individual name, files holding several keys (which a write would drop).
  • Warnings for the first-frame loss bug: an empty first frame in CSV, written then read back, would be dropped in DLC, and could cause the orphaned paths to be stored as index names.
  • Written H5 files are stamped dlccore.io.labeled_data with the dlccore version.

Import boundaries

Fresh-interpreter tests check that importing dlccore.io loads neither the video nor the H5 module, and that importing a labeled-data package does not load the H5 module.

@C-Achard C-Achard added io: labeled-data CollectedData and machinelabels files consumer: deeplabcut Needed by or affects DeepLabCut consumer: napari Needed by or affects napari-deeplabcut canonical Changes something consumers rely on: finding codes, snapshot format, written files labels Nov 24, 2026
@C-Achard C-Achard self-assigned this Nov 24, 2026
@C-Achard
C-Achard added this pull request to stack #18 November 24, 2026 16:24
@C-Achard
C-Achard marked this pull request as draft November 24, 2026 16:25
@C-Achard
C-Achard force-pushed the cy/io-labeled-data-file branch from 4b0978c to 87ceb46 Compare November 24, 2026 16:32
- Rename the package to dlccore.io and add the dlccore license header
- Stamp written H5 files with the writer name dlccore.io.labeled_data
- Use wide_df_to_long and name DataFrames `df`, never `frame`
- Add import-boundary tests: no format module or the video reader loads
  until imported, and only LabeledDataFile reads its storage
@C-Achard
C-Achard force-pushed the cy/io-labeled-data-file branch from 87ceb46 to 893e621 Compare November 24, 2026 16:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

canonical Changes something consumers rely on: finding codes, snapshot format, written files consumer: deeplabcut Needed by or affects DeepLabCut consumer: napari Needed by or affects napari-deeplabcut io: labeled-data CollectedData and machinelabels files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant