Skip to content

Commit

Permalink
Backport PR #1343: (fix): move zarr import inside try-catch in test h…
Browse files Browse the repository at this point in the history
…elpers (#1347)

Co-authored-by: Ilan Gold <ilanbassgold@gmail.com>
  • Loading branch information
meeseeksmachine and ilan-gold authored Jan 26, 2024
1 parent 9777e76 commit 08e7b94
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 15 deletions.
38 changes: 23 additions & 15 deletions anndata/tests/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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."
)
2 changes: 2 additions & 0 deletions docs/release-notes/0.10.6.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

Expand Down

0 comments on commit 08e7b94

Please sign in to comment.