Skip to content

Commit 62edbe4

Browse files
authored
Make Zarr optional for testing (#1141)
1 parent 8917eaf commit 62edbe4

File tree

3 files changed

+33
-6
lines changed

3 files changed

+33
-6
lines changed

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ dependencies = [
3636
"pandas>=1.0.5",
3737
"ruamel.yaml>=0.16",
3838
"scipy>=1.4",
39-
"zarr >= 2.12.0",
4039
"importlib-resources; python_version < '3.9'", # TODO: remove when minimum python version is 3.9
4140
]
4241
dynamic = ["version"]

src/hdmf/data_utils.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@
55
from warnings import warn
66
from typing import Tuple
77
from itertools import product, chain
8-
from zarr import Array as ZarrArray
8+
9+
try:
10+
from zarr import Array as ZarrArray
11+
ZARR_INSTALLED = True
12+
except ImportError:
13+
ZARR_INSTALLED = False
914

1015
import h5py
1116
import numpy as np
@@ -16,9 +21,6 @@ def append_data(data, arg):
1621
if isinstance(data, (list, DataIO)):
1722
data.append(arg)
1823
return data
19-
elif isinstance(data, ZarrArray):
20-
data.append([arg], axis=0)
21-
return data
2224
elif type(data).__name__ == 'TermSetWrapper': # circular import
2325
data.append(arg)
2426
return data
@@ -33,6 +35,9 @@ def append_data(data, arg):
3335
data.resize(shape)
3436
data[-1] = arg
3537
return data
38+
elif ZARR_INSTALLED and isinstance(data, ZarrArray):
39+
data.append([arg], axis=0)
40+
return data
3641
else:
3742
msg = "Data cannot append to object of type '%s'" % type(data)
3843
raise ValueError(msg)

tests/unit/utils_test/test_data_utils.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,32 @@
33

44
import numpy as np
55
from numpy.testing import assert_array_equal
6-
import zarr
6+
7+
try:
8+
import zarr
9+
ZARR_INSTALLED = True
10+
except ImportError:
11+
ZARR_INSTALLED = False
12+
13+
14+
class MyIterable:
15+
def __init__(self, data):
16+
self.data = data
17+
718

819
class TestAppendData(TestCase):
20+
def test_append_exception(self):
21+
data = MyIterable([1, 2, 3, 4, 5])
22+
with self.assertRaises(ValueError):
23+
append_data(data, 4)
24+
25+
26+
class TestZarrAppendData(TestCase):
27+
28+
def setUp(self):
29+
if not ZARR_INSTALLED:
30+
self.skipTest("optional Zarr package is not installed")
31+
932

1033
def test_append_data_zarr(self):
1134
zarr_array = zarr.array([1,2,3])

0 commit comments

Comments
 (0)