scverse / scverse/spatialdata

cannot import name 'ConsolidatedMetadataStore' from 'zarr.storage'

Open
#1,058 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

needs: triage priority: low
Dominant language
Python
Stars
394
Forks
95
Avg merge
4d 3h
Merged PRs (30d)
7

Description

Hello,

I don't succeed to export my spatialdata with the function write into a zarr and I've been able to reproduce it with the dataset blob.

from spatialdata.datasets import blobs

test = blobs()
test.write(working_dir + 'test.zarr')

Give the following error:

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
Cell In[5], line 4
      1 from spatialdata.datasets import blobs
      3 test = blobs()
----> 4 test.write(working_dir + 'test.zarr')

File /micromamba/me/envs/sopa/lib/python3.12/site-packages/spatialdata/_utils.py:263, in _deprecation_alias.<locals>.deprecation_decorator.<locals>.wrapper(*args, **kwargs)
    261     raise ValueError("version for deprecation must be specified")
    262 rename_kwargs(f.__name__, kwargs, alias_copy, class_name, library, version)
--> 263 return f(*args, **kwargs)

File /micromamba/me/envs/sopa/lib/python3.12/site-packages/spatialdata/_core/spatialdata.py:1177, in SpatialData.write(self, file_path, overwrite, consolidate_metadata, update_sdata_path, sdata_formats)
   1174 store.close()
   1176 for element_type, element_name, element in self.gen_elements():
-> 1177     self._write_element(
   1178         element=element,
   1179         zarr_container_path=file_path,
   1180         element_type=element_type,
   1181         element_name=element_name,
   1182         overwrite=False,
   1183         parsed_formats=parsed,
   1184     )
   1186 if self.path != file_path and update_sdata_path:
   1187     self.path = file_path

File /micromamba/me/envs/sopa/lib/python3.12/site-packages/spatialdata/_core/spatialdata.py:1254, in SpatialData._write_element(self, element, zarr_container_path, element_type, element_name, overwrite, parsed_formats)
   1248     write_shapes(
   1249         shapes=element,
   1250         group=element_group,
   1251         element_format=parsed_formats["shapes"],
   1252     )
   1253 elif element_type == "tables":
-> 1254     write_table(
   1255         table=element,
   1256         group=element_type_group,
   1257         name=element_name,
   1258         element_format=parsed_formats["tables"],
   1259     )
   1260 else:
   1261     raise ValueError(f"Unknown element type: {element_type}")

File /micromamba/meenvs/sopa/lib/python3.12/site-packages/spatialdata/_io/io_table.py:63, in write_table(table, group, name, group_type, element_format)
     60 else:
     61     region, region_key, instance_key = (None, None, None)
---> 63 write_adata(group, name, table)
     64 tables_group = group[name]
     65 tables_group.attrs["spatialdata-encoding-type"] = group_type

File /micromamba/me/envs/sopa/lib/python3.12/site-packages/anndata/_io/specs/registry.py:518, in write_elem(store, k, elem, dataset_kwargs)
    494 def write_elem(
    495     store: GroupStorageType,
    496     k: str,
   (...)    499     dataset_kwargs: Mapping[str, Any] = MappingProxyType({}),
    500 ) -> None:
    501     """
    502     Write an element to a storage group using anndata encoding.
    503 
   (...)    516         E.g. for zarr this would be `chunks`, `compressor`.
    517     """
--> 518     Writer(_REGISTRY).write_elem(store, k, elem, dataset_kwargs=dataset_kwargs)

File /micromamba/me/envs/sopa/lib/python3.12/site-packages/anndata/_io/utils.py:272, in report_write_key_on_error.<locals>.func_wrapper(*args, **kwargs)
    270     raise ValueError(msg)
    271 try:
--> 272     return func(*args, **kwargs)
    273 except Exception as e:
    274     path = _get_display_path(store)

File /micromamba/me/envs/sopa/lib/python3.12/site-packages/anndata/_io/specs/registry.py:372, in Writer.write_elem(self, store, k, elem, dataset_kwargs, modifiers)
    368 if (is_zarr_group and is_zarr_v2()) or (
    369     isinstance(store, h5py.Group) and not PurePosixPath(k).is_absolute()
    370 ):
    371     k = str(PurePosixPath(store.name) / k)
--> 372 is_consolidated = is_group_consolidated(store) if is_zarr_group else False
    373 if is_consolidated:
    374     msg = "Cannot overwrite/edit a store with consolidated metadata"

File /micromamba/me/envs/sopa/lib/python3.12/site-packages/anndata/_io/zarr.py:167, in is_group_consolidated(group)
    165     raise TypeError(msg)
    166 if is_zarr_v2():
--> 167     from zarr.storage import ConsolidatedMetadataStore
    169     return isinstance(group.store, ConsolidatedMetadataStore)
    170 return group.metadata.consolidated_metadata is not None

ImportError: cannot import name 'ConsolidatedMetadataStore' from 'zarr.storage' (/micromamba/me/envs/sopa/lib/python3.12/site-packages/zarr/storage/__init__.py)
Error raised while writing key 'table' of <class 'zarr.core.group.Group'> to /tables

I work with the conda package of spatialdata version 0.6.1

Desktop (optional):

  • OS: RedHat 8.7

Thanks for the package !
Lea

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at SpatialData.write and the table-writing path shown in the traceback, then inspect anndata's zarr writer and the installed zarr version. Reproduce the failure with spatialdata.datasets.blobs() and test.write(...); done means the dataset writes to a zarr store without the ConsolidatedMetadataStore import error.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
58/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.