Skip to content

Commit

Permalink
Zarr append
Browse files Browse the repository at this point in the history
  • Loading branch information
mavaylon1 committed Jun 27, 2024
1 parent 7426275 commit 8d469e7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/hdmf/data_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,20 @@
from warnings import warn
from typing import Tuple
from itertools import product, chain
from zarr import Array as ZarrArray

import h5py
import numpy as np

from .utils import docval, getargs, popargs, docval_macro, get_data_shape


def append_data(data, arg):
if isinstance(data, (list, DataIO)):
data.append(arg)
return data
elif isinstance(data, ZarrArray):
data.append([arg], axis=0)
return data
elif type(data).__name__ == 'TermSetWrapper': # circular import
data.append(arg)
return data
Expand Down
14 changes: 14 additions & 0 deletions tests/unit/utils_test/test_data_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from hdmf.data_utils import append_data
from hdmf.testing import TestCase

import numpy as np
from numpy.testing import assert_array_equal
import zarr

class TestAppendData(TestCase):

def test_append_data_zarr(self):
zarr_array = zarr.array([1,2,3])
new = append_data(zarr_array, 4)

assert_array_equal(new[:], np.array([1,2,3,4]))

0 comments on commit 8d469e7

Please sign in to comment.