Skip to content

fix: write() falls back to the path when the WSIData has no store - #89

Merged
Mr-Milk merged 1 commit into
mainfrom
fix/write-path-fallback
Oct 1, 2026
Merged

Mr-Milk merged 1 commit into
mainfrom
fix/write-path-fallback

Conversation

@Mr-Milk

@Mr-Milk Mr-Milk commented Oct 1, 2026

Copy link
Copy Markdown
Member

Summary

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 ValueError: file_path must be a string or a Path object, type(file_path) = <class 'NoneType'>. So did a second write() after open_wsi(..., store=None) and write(file_path).

Tests

  • test_write_without_store_goes_to_path: a SpatialData written from memory is opened with open_wsi(sdata, image_key=...), and write() 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:

Verification

  • Python 3.14: 137 passed, 14 skipped (readers and dependencies that are not installed).
  • ruff check and format pass.

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.
Copilot AI balanced review requested due to automatic review settings October 1, 2026 09:03
@Mr-Milk
Mr-Milk enabled auto-merge (squash) October 1, 2026 09:04

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@Mr-Milk
Mr-Milk merged commit f093137 into main Oct 1, 2026
16 checks passed
@Mr-Milk
Mr-Milk deleted the fix/write-path-fallback branch October 1, 2026 09:07
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.

2 participants