Repository navigation
Commit 6ee1013
Reduce time cost of tests (#1116)
* perf: session-scope blobs fixtures to cut setup time by ~10s
Cache `blobs(256, 300, 3)` and `BlobsDataset()._labels_blobs()` once
per session via private session-scoped fixtures, then deepcopy into
each function-scoped fixture. Cuts fixture setup from 44.8s to 35.0s
(-9.8s) and total suite from 186s to 180s. All 1332 tests still pass.
Benchmark CSVs committed for reference (pytest_*.csv).
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
* perf: use blobs(length=128) in test_vectorize to cut to_circles cost
to_circles() on labels scales linearly with pixel count.
Dropping from 512×512 to 128×128 cuts test_labels_2d_to_circles
from ~3.9s to ~1.0s per parametrized variant (−4.7s across the file).
Updated hardcoded coordinate/radius assertions to match the new size.
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
* chore: remove benchmark CSVs from repo
* chore: remove benchmark stats csv
* perf: eliminate double-validation in __setitem__ and use fast fixture deepcopy
Two orthogonal wins:
1. _elements.py: `get_model()` already calls `schema.validate()` internally;
the explicit second validate() + get_axes_names() call in every __setitem__
was redundant. Removing it halves the DataTree (_to_dataset_view) overhead
per element insertion — directly speeds up fixture setup.
2. conftest.py: introduce `_fast_deepcopy_sdata` (copy.deepcopy + manual attrs
restoration for DaskDataFrame/#503 and GeoDataFrame/#286) that is ~13x faster
than sd_deepcopy (7ms vs 93ms for full_sdata). Session-scope full_sdata,
images, labels and the 'full' sdata parametrized fixture; each test gets
a fresh 7ms copy instead of an 87ms full reconstruction. Also switch
sdata_blobs from sd_deepcopy to fast_deepcopy_sdata (2ms vs 25ms).
Full suite: 186s → 163s (~12% reduction, ~23s saved).
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
* perf: add validate=False option to get_model, clarify setitem validation comment
- get_model() now accepts validate=False to skip schema.validate() when the
caller only needs to infer the element type without re-running validation
- add comment to Elements.__setitem__ noting that subclass overrides call
get_model() which performs the validation
- drop Python 3.13 CI matrix entries (superseded by 3.14)
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
* perf: skip re-validation when building SpatialData from already-valid elements
Add skip_element_validation() context manager (backed by a ContextVar) that
makes __setitem__ call get_model(validate=False) — type inference only, no
schema.validate(). Use it in every code path that constructs a SpatialData
from elements that originated from an existing SpatialData and were never
externally mutated: bounding_box_query, polygon_query, query_by_coordinate_system,
transform_to_coordinate_system, subset, and init_from_elements.
test_query_spatial_data: 0.77s → 0.64s (the remaining time is the query work
itself — filtering, shapely ops, raster cropping).
Also inline a minimal 2-image SpatialData in
test_transformations_between_coordinate_systems instead of relying on the
full 8-element images fixture; the test only ever uses image2d and
image2d_multiscale, so writing the other 6 to disk was pure waste.
test_transformations_between_coordinate_systems: 0.61s → 0.44s.
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
* Revert "perf: skip re-validation when building SpatialData from already-valid elements"
This reverts commit acb25b1.
* perf: vectorize label centroid computation, 30x speedup
Replace per-slice O(H+W) approach (512 dask compute() calls for a 256×256
array) with a single array materialization + np.bincount O(n_pixels) pass.
This speeds up get_centroids() on labels from ~1.5s to ~50ms, cutting
to_circles(labels) from ~1.6s to ~53ms. Affects test_validation dataloader
variants (~2.5s → ~0.2s each, saving ~9s), test_labels_2d_to_circles, and
any production call to get_centroids or to_circles on label arrays.
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
* perf: session-scope blobs fixtures in concatenate and get_attrs tests
Add blobs_factory fixture that returns fast deepcopies of the session-scoped
blobs dataset, and update test_concatenate_* and test_no_shared_transformations
to use it instead of calling blobs() per test. Also update test_get_attrs.py
sdata_attrs fixture and test_empty_attrs to use sdata_blobs.
The concatenate parametrized tests (6 variants) drop from ~0.55s to ~0.02s
each (~3s total savings); test_get_attrs drops from ~0.28s to ~0.02s per test.
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
* perf: reduce categories and partitions in test_categories_on_partitioned_dataframe
Drop from 200 to 20 for both N_PARTITIONS and the number of gene categories.
The test's assertions (round-trip values, category-order mismatch between pandas
and dask, dtype) are all preserved at the smaller scale; the 200-partition
stress test was over-specified for what's actually being verified.
~1.56s → ~0.95s (39% faster) for that test.
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
* perf: shrink test_categories_on_partitioned_dataframe to N=10, local seed
Drop from 20 to 10 for both N_PARTITIONS and the number of gene categories,
and replace the module-level RNG with a local default_rng(seed=0) so the
test is independent of other tests' RNG consumption.
With seed=0 and N=10, partition 0 is deterministically missing gene_4,
which is sufficient to trigger the dask category-order mismatch being tested.
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
* ci: parallelize test suite with pytest-xdist worksteal
Add pytest-xdist to test dependencies and pass -n auto --dist worksteal
to pytest in CI. worksteal distributes tests dynamically across workers
so slow IO tests don't block fast unit tests on a single worker.
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
* refactor: clean up _get_centroids_for_labels docstring and clarify indexing
- Remove reference to the old per-slice implementation from the docstring
- Add inline comment explaining why indexing="ij" is correct for any
number of spatial dimensions (2D and 3D labels)
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
* refactor: minor code swap for improved clarity
* perf: speed up test suite — subset sdata, disable numba JIT, promote fixtures to session scope
- test_delete_element_from_disk: subset full_sdata to [element_name, points_0_1]
before writing, cutting the initial write from 19 elements to 2 (2–13× speedup
per parametrize case)
- conftest: set NUMBA_DISABLE_JIT=1 to avoid ~1.4s JIT overhead per worker on
first datashader/rasterize call
- test_partial_read: promote all module-scoped fixtures to session scope so the
corrupted zarr stores are built once per session instead of once per module
- test_transform: use small_translation=True to avoid out-of-bounds raster
operations that trigger large dask computations
- test_spatialdata_operations: reduce target_width 1000→100 in
test_transform_to_data_extent to shrink the output raster
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
* fix+perf: faster test suite — subset fixtures, disable numba JIT, fix napari plugin
Napari registers a pytest11 entry point that loads (and breaks) numba before
conftest.py runs. Fix: block it in pyproject.toml addopts with -p no:napari.
datashader's @jit(cache=True) raises "no locator available" on Python 3.13 +
numba. With napari blocked, conftest.py now runs before any plugin imports
numba, so NUMBA_DISABLE_JIT=1 consistently disables all @jit decorators
(datashader, xrspatial) and avoids the mixed JIT/non-JIT crash.
Promote all module-scoped fixtures in test_partial_read to session scope so
corrupted zarr stores are built once per session.
For tests that write a full SpatialData object but only need a single element
(or a small subset) to trigger the condition under test, subset the fixture
before writing. The initial full write dominates test time (19 elements
including 3-D multiscale rasters), so even subsetting to 1-6 elements gives
2-13× speedups per parametrize case:
- test_delete_element_from_disk: subset to [element_name, points_0_1]
- test_incremental_io_on_disk: subset to the 7 elements the loop accesses
- test_overwrite_fails_when_zarr_store_present: use empty SpatialData()
- test_element_already_on_disk_different_type: subset to [element_name]
- test_self_contained: subset to [image2d, labels2d, points_0, circles]
- test_change_path_of_subset: subset to the 5 elements + points_0_1 (needed
so only_on_disk > 0 assertion passes)
- test_validate_can_write_metadata_on_element: subset to [element_name]
- test_save_transformations_incremental: subset to [element_name, image2d]
(image2d anchors the non-self-contained assertion for the circles case)
- test_consolidated_metadata: subset to one element per type
- test_channel_names_raster_images_v1_to_v2_to_v3: subset to
[image2d, image2d_multiscale]
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
* refactor: update comments and refine test_consolidated_metadata subset
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
---------
Co-authored-by: Claude Sonnet 4.6 <[email protected]>1 parent d0582ec commit 6ee1013
17 files changed
Lines changed: 215 additions & 147 deletions
File tree
- .github/workflows
- src/spatialdata
- _core
- models
- tests
- core
- operations
- dataloader
- io
- models
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | | - | |
24 | 23 | | |
25 | 24 | | |
26 | | - | |
27 | 25 | | |
28 | 26 | | |
29 | | - | |
30 | 27 | | |
31 | 28 | | |
32 | 29 | | |
| |||
62 | 59 | | |
63 | 60 | | |
64 | 61 | | |
65 | | - | |
| 62 | + | |
66 | 63 | | |
67 | 64 | | |
68 | 65 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
69 | 69 | | |
70 | 70 | | |
71 | 71 | | |
| 72 | + | |
72 | 73 | | |
73 | 74 | | |
74 | 75 | | |
| |||
102 | 103 | | |
103 | 104 | | |
104 | 105 | | |
| 106 | + | |
105 | 107 | | |
106 | 108 | | |
107 | 109 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | | - | |
25 | 24 | | |
26 | 25 | | |
27 | 26 | | |
| |||
50 | 49 | | |
51 | 50 | | |
52 | 51 | | |
| 52 | + | |
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
| |||
72 | 72 | | |
73 | 73 | | |
74 | 74 | | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
| 75 | + | |
84 | 76 | | |
85 | 77 | | |
86 | 78 | | |
| |||
89 | 81 | | |
90 | 82 | | |
91 | 83 | | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
| 84 | + | |
101 | 85 | | |
102 | 86 | | |
103 | 87 | | |
| |||
106 | 90 | | |
107 | 91 | | |
108 | 92 | | |
109 | | - | |
110 | 93 | | |
111 | 94 | | |
112 | 95 | | |
| |||
116 | 99 | | |
117 | 100 | | |
118 | 101 | | |
119 | | - | |
120 | 102 | | |
121 | 103 | | |
122 | 104 | | |
| |||
126 | 108 | | |
127 | 109 | | |
128 | 110 | | |
129 | | - | |
130 | 111 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
4 | 3 | | |
5 | 4 | | |
6 | | - | |
| 5 | + | |
7 | 6 | | |
8 | 7 | | |
9 | 8 | | |
| |||
56 | 55 | | |
57 | 56 | | |
58 | 57 | | |
59 | | - | |
| 58 | + | |
60 | 59 | | |
61 | | - | |
| 60 | + | |
62 | 61 | | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
| 62 | + | |
75 | 63 | | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
93 | 81 | | |
94 | 82 | | |
95 | 83 | | |
| |||
109 | 97 | | |
110 | 98 | | |
111 | 99 | | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | | - | |
| 100 | + | |
116 | 101 | | |
117 | 102 | | |
118 | 103 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1250 | 1250 | | |
1251 | 1251 | | |
1252 | 1252 | | |
| 1253 | + | |
1253 | 1254 | | |
1254 | 1255 | | |
1255 | | - | |
| 1256 | + | |
1256 | 1257 | | |
1257 | 1258 | | |
1258 | 1259 | | |
1259 | 1260 | | |
1260 | 1261 | | |
| 1262 | + | |
| 1263 | + | |
1261 | 1264 | | |
1262 | 1265 | | |
1263 | 1266 | | |
| |||
1268 | 1271 | | |
1269 | 1272 | | |
1270 | 1273 | | |
1271 | | - | |
| 1274 | + | |
| 1275 | + | |
1272 | 1276 | | |
1273 | 1277 | | |
1274 | 1278 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
4 | 11 | | |
5 | 12 | | |
6 | 13 | | |
| |||
33 | 40 | | |
34 | 41 | | |
35 | 42 | | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
36 | 62 | | |
37 | 63 | | |
38 | 64 | | |
| |||
41 | 67 | | |
42 | 68 | | |
43 | 69 | | |
44 | | - | |
45 | | - | |
| 70 | + | |
| 71 | + | |
46 | 72 | | |
47 | 73 | | |
48 | 74 | | |
49 | 75 | | |
50 | | - | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
51 | 82 | | |
52 | 83 | | |
53 | 84 | | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
54 | 90 | | |
55 | 91 | | |
56 | 92 | | |
| |||
87 | 123 | | |
88 | 124 | | |
89 | 125 | | |
90 | | - | |
91 | | - | |
| 126 | + | |
| 127 | + | |
92 | 128 | | |
93 | 129 | | |
94 | 130 | | |
| |||
98 | 134 | | |
99 | 135 | | |
100 | 136 | | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
101 | 153 | | |
102 | 154 | | |
103 | 155 | | |
| |||
110 | 162 | | |
111 | 163 | | |
112 | 164 | | |
113 | | - | |
| 165 | + | |
114 | 166 | | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
| 167 | + | |
122 | 168 | | |
123 | 169 | | |
124 | 170 | | |
| |||
304 | 350 | | |
305 | 351 | | |
306 | 352 | | |
307 | | - | |
308 | | - | |
309 | | - | |
| 353 | + | |
| 354 | + | |
310 | 355 | | |
311 | 356 | | |
312 | 357 | | |
313 | 358 | | |
314 | | - | |
| 359 | + | |
315 | 360 | | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
316 | 366 | | |
317 | 367 | | |
318 | | - | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
319 | 385 | | |
320 | 386 | | |
321 | 387 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
0 commit comments