diff --git a/anndata/tests/helpers.py b/anndata/tests/helpers.py index a6aabcabf..4fb33c039 100644 --- a/anndata/tests/helpers.py +++ b/anndata/tests/helpers.py @@ -12,7 +12,6 @@ import numpy as np import pandas as pd import pytest -import zarr from pandas.api.types import is_numeric_dtype from scipy import sparse @@ -759,21 +758,30 @@ def shares_memory_sparse(x, y): ), ] +try: + import zarr -class AccessTrackingStore(zarr.DirectoryStore): - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - self._access_count = {} + class AccessTrackingStore(zarr.DirectoryStore): + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self._access_count = {} - def __getitem__(self, key): - for tracked in self._access_count: - if tracked in key: - self._access_count[tracked] += 1 - return super().__getitem__(key) + def __getitem__(self, key): + for tracked in self._access_count: + if tracked in key: + self._access_count[tracked] += 1 + return super().__getitem__(key) - def get_access_count(self, key): - return self._access_count[key] + def get_access_count(self, key): + return self._access_count[key] - def set_key_trackers(self, keys_to_track): - for k in keys_to_track: - self._access_count[k] = 0 + def set_key_trackers(self, keys_to_track): + for k in keys_to_track: + self._access_count[k] = 0 +except ImportError: + + class AccessTrackingStore: + def __init__(self, *_args, **_kwargs) -> None: + raise ImportError( + "zarr must be imported to create an `AccessTrackingStore` instance." + ) diff --git a/docs/release-notes/0.10.6.md b/docs/release-notes/0.10.6.md index abdb08924..4a978f4dd 100644 --- a/docs/release-notes/0.10.6.md +++ b/docs/release-notes/0.10.6.md @@ -3,6 +3,8 @@ ```{rubric} Bugfix ``` +* Defer import of zarr in test helpers, as scanpy CI job relies on them {pr}`1343` {user}`ilan-gold` + ```{rubric} Documentation ```