Repository navigation
Conversation
…ersion
Add tests/data/reference_stores/ with a generator for committed
reference stores: each storage format version (0.1-0.4) written by the
first and the last spatialdata release that wrote it by default
(0.1.0/0.2.1, 0.2.2/0.3.0, 0.4.0/0.5.0, 0.6.0/0.9.0). The reader on
main can then be tested against bytes it did not write; the round-trip
tests in test_format.py use the same code to write and read.
- generate.py (standard library only) resolves each writer's
environment into requirements.txt with `uv pip compile --universal`
and --exclude-newer (PyPI upload date + 3 days), installs it with the
writer's Python version, writes the store, checks the recorded
container, element, Zarr and NGFF versions against the specification,
and zips the store reproducibly.
- write.py runs inside the writer's environment.
- build.py defines the object every store holds. It is frozen and uses
only public APIs available from spatialdata 0.1.0 to main.
Each writer runs on the Python of its release date: 3.12 if the
release's CI tested it, otherwise the newest minor version it tested, at
the last patch release published on or before the release (3.10.14 for
0.1.0; 3.12.4 to 3.12.16 for the others). Old dependencies break on
later Python releases: dask <= 2024.2.1 (pinned by 0.1.0) fails to
import on Python >= 3.12.3, and pygeos 0.14 has no Python 3.12 wheels.
Writers on Python < 3.12 also lock setuptools, which virtual
environments of those Pythons included and which xarray-schema needs
(pkg_resources) without declaring it. `uv pip sync` also gets
--exclude-newer, so source builds use build tools of the release date.
build.py holds elements in the form every storage format keeps them:
the image's Scale over all of its axes (writers store a ("y", "x")
Scale over ("c", "y", "x")), the circles with geometry first, and the
polygons of one geometry type (format 0.1 stores shapes as single-type
ragged arrays without column order).
Each store lives in storage-format-<version>_spatialdata-<release>/,
with its requirements.txt and zip. The stores themselves are added in a
separate commit, generated with this script.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011ecEfSxdLEEKahggNs3nqz
Read every reference store in tests/data/reference_stores with the current code and compare it with the object it was written from (build.py). Also check that sdata.path points to the store and that `selection` reads only the selected element types; neither was covered by any test so far, and the planned restructuring of read_zarr changes both. Accepted differences between a store and build.py go into ACCEPTED_DIFFERENCES, each with a reason; it starts empty. A missing store fails the tests rather than skipping them, so these tests fail until the generated stores are committed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011ecEfSxdLEEKahggNs3nqz
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1346 +/- ##
==========================================
+ Coverage 91.77% 91.79% +0.02%
==========================================
Files 53 53
Lines 8398 8398
==========================================
+ Hits 7707 7709 +2
+ Misses 691 689 -2 🚀 New features to boost your workflow:
|
jan-glx
left a comment
There was a problem hiding this comment.
Thanks @ajkswamy, this looks really useful! A safety net built from bytes the current code didn't write is exactly what the read_zarr refactor needs. I was worried about committing the stores at first, but at ~260 KiB for the whole folder (~190 KiB of zips) that's totally fine.
CI hadn't run on this PR (the pull_request event seems to have been dropped), so I closed and reopened it to re-trigger it.
Three questions/suggestions:
I. Keep the generator files out of linting and dependency scanning. Right now generate.py and write.py go through ruff-check/ruff-format (hence the # fmt: skips). The eight requirements.txt files go through the pre-commit text hooks. GitHub's dependency graph is enabled for this repo and reads requirements.txt manifests anywhere, so the old 2024/2025 pins would show up as dependencies of spatialdata, and in security alerts once those are on. (mypy and coverage are already fine: files = ["src"] and run.source = ["spatialdata"].) Could we exclude them explicitly? For example, a top-level exclude: ^tests/data/reference_stores/ in .pre-commit-config.yaml plus extend-exclude = ["tests/data/reference_stores"] under [tool.ruff]. For the scanners, either put generate.py, write.py and the requirements.txt files into a zip too, or give them names nothing picks up (e.g. requirements.lock, generate.py.dont_run). build.py can stay as is, since the tests import it.
II. Would it make sense to also add these stores to the spatialdata-sandbox datasets on the scverse S3? Those are at https://exampledata.scverse.org/spatialdata/spatialdata-sandbox/ (uploaded by spatialdata-integration-testing, listed on the datasets page of the docs). All versions there were written by spatialdata 0.7.1–0.9.0, i.e. storage format 0.4. These eight stores would add formats 0.1–0.3, and other readers (napari-spatialdata, R/JS readers, …) could test against them without cloning this repo.
III. Could the README show what the reference object looks like? Right now it only says "the same small object, one element of each type, defined in build.py" (it's actually two shapes elements). A short overview would save maintainers from reading build.py when a test fails, e.g. a small table or the printed SpatialData repr. It could cover:
image_multiscale: 3×16×16 uint8, channels r/g/b, 2 scaleslabels_single_scale: 16×16, labels 1 and 2points: 5 points withgene/cell_idcircles: 2 circles with radiuspolygons: 2 MultiPolygons, one with a holetable: 2×3, annotatingcircles- coordinate systems
globalandaligned(Scale on the image, Translation on the circles)
|
Thanks @jan-glx for the review, great ideas! I will implement your third suggestion as it is. @jan-glx @LucaMarconato How about I move We could also:
With this setup, we would need to modify the config of formats + sdata versions in |
AI use transparency
generator and test code, the commit messages and this description.
and committed the stores myself.
What this adds
Small example datasets ("reference stores") written by older spatialdata releases, and tests
that check the current code still reads them correctly.
Part of #1345. No library code changes; this only adds tests and test data.
Why
Our existing format tests write a dataset and read it back with the same code. If writing and
reading change together, those tests still pass, even when files written by older versions no
longer read correctly. Before restructuring the reading code (#), we need a safety net
that uses files the current code did not write.
What's in it
8 stores, about 300 KiB in total: for each of the four storage format versions (0.1 to 0.4),
one store written by the first release that used it and one by the last.
Every store holds the same small object (one image, labels, points, two shapes elements and a
table), defined in
tests/data/reference_stores/build.py.A generator script (
generate.py) that installs each old release in a temporary environment,writes its store, checks the recorded format versions against the specification, and zips the
store. Each folder keeps the exact package list used (
requirements.txt), so the stores can bereproduced. The README explains how and when to regenerate them (normally never).
Tests (
tests/io/test_reference_stores.py) that read each store and compare it with theobject from
build.py. They also checksdata.pathand theselectionargument, which no testcovered so far.
How the old releases are installed
Old releases have to run in the environment of their time:
otherwise the newest version it tested). spatialdata 0.1.0 therefore runs on Python 3.10.14, and
the others on Python 3.12.4 to 3.12.16. Newer Python versions break some old dependencies, for
example dask 2024.2.1, which 0.1.0 requires.
What we learned about the formats
Writing one object with every release showed a few things the formats don't keep.
build.pybuildsthe object in the form every format stores it, so all stores can be compared with one object:
(y, x)on a(c, y, x)image comes back as a scale over(c, y, x).element (a mix of polygons and multipolygons comes back as multipolygons only).
Mixing geometry types in one shapes element is therefore not covered. The README lists this and
other variants no store covers.
For reviewers
spatialdata.testing, which compares strictly and has become stricterover time (for example Add tests for sdata.attrs across formats #1015). A future change there can make these tests fail even though no
store changed.
Scaletransformations over different axes raises anerror instead of returning
False. Fixing this would need a separate PR.