Skip to content

Commit b5239b4

Browse files
support zarrv3 (#985)
* changed pyproject to zarr>=3 * adjust dependencies * wip * more fixes * update ome-zarr dep * Add zarr v3 formats * refactoring formats * wip replace parse_url() with _open_zarr_store() * update way of writing transforms, update typehints * attempt fix consolidated metadata, fix channel names write * fix partial read tests * fix path * access name in group directly * fix read in consolidated metadata * initial ugly fix groups and consolidated metadata when deleting * fix reading back table * open group without using consolidated metadata when writing * revert adding labels * fix read / write issues with consolidated metadata * use_consolidated False when writing transforms * add ome_format arg * check valid element formats in container format * uncomment code arrayNotFoundError * remove future annotations import * update workflow mac version * drop python 3.10 version is not supported by zarr v3.0.8 * change target python version and readthedocs python version * minor updates * update Self import * fix ome errors * add windows workflow * prevent consolidation labels group when deleting element * add shapes test * fix shape conversion * update dask dependency because of zarr v3 * fix multipoly * fix invalid read name test * use UPath * fix paths * resolve paths * refactor overwrite transformations * refactor * further refactor, add docstrings * refactor io_raster * several refactors io * war on warnings * checks backward compatibility * correct test * further reduce warnings * remove log with no useful info * remove log as it is stated in doc string * move log to info in docstring * remove deprecated warning * get rid of categorical and str casting warnings * below 1000 warnings * further reduction of warnings * remove deprecated code * correct location for storing transforms * consistent naming * update according to ome-zarr-py * correct docstring * update docstring * remove todo * remove unassigned function call * refactor new _open_zarr_store to _resolve_zarr_store * silence zarr parquet warnings * change overwriting warning, silence in tests * silence overwriting warnings * silence chunk warning * remove argument from docstring, update typehint * update typehint * small fixes * fail if not root does not exist * write out function name * small fixes * initial replacement parse_url * alter docstring * adjust argument docstring * remove overwrite warnings * fix test * replace parse_url * change version * remove type hints from docstrings * refactor to one function * change typehint * remove typehints from docstring * remove type hint return in docstring * remove comment * ensure comment added back * fix channel metadata * get rid of TableValidateMixin * code fixes * fix * remove format without effect * remove unnecessary catch warnings * add todo * fixes * remove unnecessary .get('ome') * add clarifying comment * wip tests readwrite across formats * return None instead of AnnData * remove TODO * remove invalid characters from test * remove unused fixture and commented code * almost completed extending readwrite tests to all container versions * add OSError * partial fix writing empty spatialdata * fix type * fix overwrite when no zarr store * fix write element to empty directory location * correct no zarr store write test * remove unnecessary code * fix write_element * delete group isntead of .zattrs * remove parse_url * removed logger.ingo() and most of remaining warnings from tests * addressing review comments * addressed consolidate metadata comment * make full coverage of _validate_can_safely_write_to_path() easier to understand * restore partial read/write tests * minor changes in test_partial_read(); code review finished * support ome-zarr-py master * fix docs * ensure multiscales written correctly * refactor read_zarr (#982) * refactor read_zarr * remove unneccesary checks * Refactor zarrv3 (#986) * refactor read_zarr * remove unneccesary checks * emit warning with old spatialdata storage version detected * simplify code for writing (code review changes) * finished addressing review --------- Co-authored-by: Luca Marconato <[email protected]>
1 parent 18eb623 commit b5239b4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+2351
-1498
lines changed

.github/workflows/test.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,17 @@ jobs:
1818
strategy:
1919
fail-fast: false
2020
matrix:
21-
python: ["3.10", "3.12"]
21+
python: ["3.11", "3.13"]
2222
os: [ubuntu-latest]
2323
include:
2424
- os: macos-latest
25-
python: "3.10"
25+
python: "3.11"
2626
- os: macos-latest
2727
python: "3.12"
2828
pip-flags: "--pre"
2929
name: "Python 3.12 (pre-release)"
30+
- os: windows-latest
31+
python: "3.11"
3032

3133
env:
3234
OS: ${{ matrix.os }}

.mypy.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[mypy]
2-
python_version = 3.10
2+
python_version = 3.11
33

44
ignore_errors = False
55
warn_redundant_casts = True

.readthedocs.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ version: 2
33
build:
44
os: ubuntu-20.04
55
tools:
6-
python: "3.10"
6+
python: "3.11"
77
sphinx:
88
configuration: docs/conf.py
99
fail_on_warning: true

docs/api/data_formats.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Data formats (advanced)
22

3-
The SpatialData format is defined as a set of versioned subclasses of `spatialdata._io.format.SpatialDataFormat`, one per type of element.
4-
These classes are useful to ensure backward compatibility whenever a major version change is introduced. We also provide pointers to the latest format.
3+
The SpatialData format is defined as a set of versioned subclasses of `ome_zarr.format.Format`, one per type of element. The `spatialdata.SpatialDataFormatType` is a union type encompassing the possible valid formats.
4+
These format subclasses are useful to ensure backward compatibility whenever a major version change is introduced. We also provide pointers to the latest format.
55

66
```{eval-rst}
77
.. currentmodule:: spatialdata._io.format

docs/api/io.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,5 @@ use any of the [spatialdata-io readers](https://spatialdata.scverse.org/projects
77
.. currentmodule:: spatialdata
88
99
.. autofunction:: read_zarr
10-
.. autofunction:: save_transformations
1110
.. autofunction:: get_dask_backing_files
1211
```

pyproject.toml

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ maintainers = [
1515
urls.Documentation = "https://spatialdata.scverse.org/en/latest"
1616
urls.Source = "https://github.com/scverse/spatialdata.git"
1717
urls.Home-page = "https://github.com/scverse/spatialdata.git"
18-
requires-python = ">=3.10"
18+
requires-python = ">=3.11"
1919
dynamic= [
2020
"version" # allow version to be set by git tags
2121
]
@@ -25,15 +25,15 @@ dependencies = [
2525
"anndata>=0.9.1",
2626
"click",
2727
"dask-image",
28-
"dask>=2024.4.1,<=2024.11.2",
28+
"dask>=2024.10.0,<=2024.11.2",
2929
"datashader",
30-
"fsspec",
30+
"fsspec[s3,http]",
3131
"geopandas>=0.14",
3232
"multiscale_spatial_image>=2.0.3",
3333
"networkx",
3434
"numba>=0.55.0",
3535
"numpy",
36-
"ome_zarr>=0.8.4",
36+
"ome_zarr>=0.12.2",
3737
"pandas",
3838
"pooch",
3939
"pyarrow",
@@ -44,15 +44,17 @@ dependencies = [
4444
"scikit-image",
4545
"scipy",
4646
"typing_extensions>=4.8.0",
47+
"universal_pathlib>=0.2.6",
4748
"xarray>=2024.10.0",
4849
"xarray-schema",
4950
"xarray-spatial>=0.3.5",
50-
"zarr<3",
51+
"zarr>=3.0.0",
5152
]
5253

5354
[project.optional-dependencies]
5455
dev = [
5556
"bump2version",
57+
"sentry-prevent-cli",
5658
]
5759
test = [
5860
"pytest",
@@ -97,7 +99,13 @@ xfail_strict = true
9799
addopts = [
98100
# "-Werror", # if 3rd party libs raise DeprecationWarnings, just use filterwarnings below
99101
"--import-mode=importlib", # allow using test files with same name
100-
"-s" # print output from tests
102+
"-s", # print output from tests
103+
]
104+
# These are all markers coming from xarray, dask or anndata. Added here to silence warnings.
105+
markers = [
106+
"slow: marks tests as slow (deselect with '-m \"not slow\"')",
107+
"gpu: run test on GPU using CuPY.",
108+
"skip_with_pyarrow_strings: skipwhen pyarrow string conversion is turned on",
101109
]
102110
# info on how to use this https://stackoverflow.com/questions/57925071/how-do-i-avoid-getting-deprecationwarning-from-inside-dependencies-with-pytest
103111
filterwarnings = [
@@ -131,7 +139,7 @@ exclude = [
131139

132140
]
133141
line-length = 120
134-
target-version = "py310"
142+
target-version = "py311"
135143

136144
[tool.ruff.lint]
137145
ignore = [

src/spatialdata/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@
4242
"SpatialData",
4343
"get_extent",
4444
"get_centroids",
45+
"SpatialDataFormatType",
4546
"read_zarr",
4647
"unpad_raster",
4748
"get_pyramid_levels",
48-
"save_transformations",
4949
"get_dask_backing_files",
5050
"are_extents_equal",
5151
"relabel_sequential",
@@ -79,7 +79,7 @@
7979
)
8080
from spatialdata._core.query.spatial_query import bounding_box_query, polygon_query
8181
from spatialdata._core.spatialdata import SpatialData
82-
from spatialdata._io._utils import get_dask_backing_files, save_transformations
83-
from spatialdata._io.format import SpatialDataFormat
82+
from spatialdata._io._utils import get_dask_backing_files
83+
from spatialdata._io.format import SpatialDataFormatType
8484
from spatialdata._io.io_zarr import read_zarr
8585
from spatialdata._utils import get_pyramid_levels, unpad_raster

src/spatialdata/_core/_deepcopy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def _(sdata: SpatialData) -> SpatialData:
4646
for _, element_name, element in sdata.gen_elements():
4747
elements_dict[element_name] = deepcopy(element)
4848
deepcopied_attrs = _deepcopy(sdata.attrs)
49-
return SpatialData.from_elements_dict(elements_dict, attrs=deepcopied_attrs)
49+
return SpatialData.init_from_elements(elements_dict, attrs=deepcopied_attrs)
5050

5151

5252
@deepcopy.register(DataArray)

src/spatialdata/_core/_elements.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from collections import UserDict
44
from collections.abc import Iterable, KeysView, ValuesView
55
from typing import TypeVar
6-
from warnings import warn
76

87
from anndata import AnnData
98
from dask.dataframe import DataFrame as DaskDataFrame
@@ -41,9 +40,7 @@ def _remove_shared_key(self, key: str) -> None:
4140
@staticmethod
4241
def _check_key(key: str, element_keys: Iterable[str], shared_keys: set[str | None]) -> None:
4342
check_valid_name(key)
44-
if key in element_keys:
45-
warn(f"Key `{key}` already exists. Overwriting it in-memory.", UserWarning, stacklevel=2)
46-
else:
43+
if key not in element_keys:
4744
try:
4845
check_key_is_case_insensitively_unique(key, shared_keys)
4946
except ValueError as e:

src/spatialdata/_core/concatenate.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@ def _concatenate_tables(
6868
TableModel.INSTANCE_KEY: instance_key,
6969
}
7070
merged_table.uns[TableModel.ATTRS_KEY] = attrs
71-
72-
return TableModel().validate(merged_table)
71+
return TableModel().parse(merged_table)
7372

7473

7574
def concatenate(
@@ -252,6 +251,8 @@ def _fix_ensure_unique_element_names(
252251
tables_by_sdata.append(tables)
253252
sdatas_fixed = []
254253
for elements, tables in zip(elements_by_sdata, tables_by_sdata, strict=True):
255-
sdata = SpatialData.init_from_elements(elements, tables=tables)
254+
if tables is not None:
255+
elements.update(tables)
256+
sdata = SpatialData.init_from_elements(elements)
256257
sdatas_fixed.append(sdata)
257258
return sdatas_fixed

0 commit comments

Comments
 (0)