Repository navigation
fix: write() falls back to the path when the WSIData has no store - #89
Merged
Merged
Conversation
WSIData.write() without a file_path raised only when both the store and the path were unset, but then always wrote to the store. A WSIData opened from a SpatialData, with open_wsi(sdata, image_key=...), takes the path of that SpatialData in from_spatialdata() and never gets a store, so write() passed None on to SpatialData.write and failed with "file_path must be a string or a Path object". So did a second write() after open_wsi(..., store=None) and write(file_path). write() now falls back to the path when there is no store, and the store still comes first when both are set. A SpatialData written from memory keeps its elements in memory, and the WSIData is written back to its path. A SpatialData read from disk loads its images, labels and points lazily from that path, which write() refuses to overwrite since #85: it now raises that ValueError instead of the misleading one, and the store is left intact.
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The fallback is correct, preserves existing precedence, and has focused regression coverage.
Review effort: Balanced
Findings: None
What changed in this PR
Fixes WSIData.write() to use its inherited SpatialData path when no WSI store is configured.
Changes:
- Adds path fallback while preserving store precedence.
- Adds regression coverage for writing SpatialData-backed instances.
| File | Description |
|---|---|
wsidata/_model/core.py |
Falls back to self.path when _wsi_store is absent. |
tests/test_wsidata.py |
Verifies writing added tissues to the fallback path. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
WSIData.write()without afile_pathraised only when both the store and the path were unset, but then always wrote to the store. AWSIDataopened from aSpatialData, withopen_wsi(sdata, image_key=...), takes the path of thatSpatialDatainfrom_spatialdata()and never gets a store. Sowrite()passedNoneon toSpatialData.writeand failed withValueError: file_path must be a string or a Path object, type(file_path) = <class 'NoneType'>. So did a secondwrite()afteropen_wsi(..., store=None)andwrite(file_path).write()now falls back to the path when there is no store. The store still comes first when both are set.SpatialDatawritten from memory keeps its elements in memory, and theWSIDatais written back to its path.SpatialDataread from disk loads its images, labels and points lazily from that path. Since fix: refuse to overwrite a store that lazily loaded elements read from #85,write()refuses to overwrite such a path, so here it raises fix: refuse to overwrite a store that lazily loaded elements read from #85'sCannot overwrite …ValueErrorinstead of the misleading one, and the store is left intact. Without fix: refuse to overwrite a store that lazily loaded elements read from #85, the fallback would have deleted the store and then read the deleted files back.Tests
test_write_without_store_goes_to_path: aSpatialDatawritten from memory is opened withopen_wsi(sdata, image_key=...), andwrite()saves the added tissues into its path. Before the fix:ValueError: file_path must be a string or a Path object, type(file_path) = <class 'NoneType'>.Checked by hand, not as tests:
open_wsi(read_zarr(p), image_key=...)thenwrite()raises fix: refuse to overwrite a store that lazily loaded elements read from #85's error, and the image inpis unchanged.open_wsi(slide, store=None),write(x), thenwrite()writes tox.Verification