Skip to content

Refuse plane_histograms.csv rows whose plane_id, image_file or bit_depth disagree - #19

Merged
guijacquemet merged 1 commit into
mainfrom
claude/csv-plane-columns-check
Oct 30, 2026
Merged

guijacquemet merged 1 commit into
mainfrom
claude/csv-plane-columns-check

Conversation

@guijacquemet

Copy link
Copy Markdown
Contributor

Fixes #18. This is the "CSV columns ignored" item of CellMigrationLab/morphobricks-preprocessing#39. Preprocessing PR CellMigrationLab/morphobricks-preprocessing#44 left it out because the reader lives in this repository.

What changed

  • csv_io._record (used by read_plane_histograms): after it builds the PlaneRecord, it compares the stored plane_id, image_file and bit_depth with the values implied by source_relative_path, z, t and dtype (record.plane_id, record.image_file, bit_depth(dtype)). The comparison is exact text, which is how write_plane_histograms writes them. A mismatch raises CsvFormatError: "<path>, line N: its <column> is '<stored>', but its other columns give '<implied>'. The table was changed after it was written; run the preprocessing brick again on this experiment to rewrite it." Before this change, the stored values were dropped and recomputed, so an edited or merged row with another row key was accepted without any error.
  • The docstring and contract §9.1 now list this error.
  • The file format and schema_version (4) do not change. Every table written by write_plane_histograms passes the check, because the writer derives these columns the same way.

Tests

  • New: tests/test_csv_io.py::test_derived_plane_columns_must_match_the_row (4 cases: plane_id naming another file, plane_id naming another z, image_file, bit_depth).
    • On old code (src reverted, test kept): 4 failed, each with DID NOT RAISE.
    • On new code: 4 passed.
  • Full suite (Python 3.13, pip install -e ".[dev]"): 474 passed, 2 skipped. The 2 skips are tests/test_rgb.py:78, because csbdeep is not installed (CI's separate job covers it).
  • ruff check .: all checks passed. ruff format --check .: 38 files already formatted.
  • Not run: Python 3.11/3.12, Windows, macOS, the csbdeep job.

Release and the preprocessing pin

  • normalization needs a new tag. Preprocessing pins morphobricks-normalization @ git+…@v0.3.1, so it does not get this fix until a new tag exists. I suggest v0.3.2, a patch release: the change only adds a refusal and the format is unchanged. As with earlier releases, that needs a release PR that sets pyproject.toml to 0.3.2 and updates the README/plan release notes, then the owner's tag. This PR does not change the version.
  • preprocessing's dependency needs a bump from @v0.3.1 to @v0.3.2 (the new tag) before it can close [Sad Catapella N3][Validation] Low-level normalization.apply accepts reversed clipping and integer output dtypes silently #39. If preprocessing v0.3.2 is tagged before that, it still ships normalization v0.3.1 without this check. Within preprocessing, the risk is small in the meantime: reused tables are guarded by the manifest's csv_sha256.

Generated by Claude Code

…pth disagree

read_plane_histograms recomputed these three columns from source_relative_path,
z, t and dtype and never compared them with the stored values, so an edited or
merged table with a mismatched row key was accepted silently. The reader now
raises CsvFormatError naming the line, column, stored and implied values. The
table format and schema version are unchanged.

Fixes #18 (from CellMigrationLab/morphobricks-preprocessing#39).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VbytvBRB9CmKQ5AAkhEFcv
@guijacquemet
guijacquemet merged commit b3d44b5 into main Oct 30, 2026
8 checks passed
@guijacquemet
guijacquemet deleted the claude/csv-plane-columns-check branch November 1, 2026 18:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

read_plane_histograms ignores the plane_id, image_file and bit_depth columns

2 participants