Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Append References #203

Merged
merged 41 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
8be834f
Append References
mavaylon1 Jul 3, 2024
c54504b
Merge branch 'dev' into append_ref
mavaylon1 Jul 3, 2024
cfd2eba
ruff updates
mavaylon1 Jul 3, 2024
dad5e7d
Merge branch 'append_ref' of https://github.com/hdmf-dev/hdmf-zarr in…
mavaylon1 Jul 3, 2024
c17445a
ruff updates
mavaylon1 Jul 3, 2024
cafc657
ruff updates
mavaylon1 Jul 3, 2024
1fa504b
test
mavaylon1 Jul 3, 2024
d29251f
test
mavaylon1 Jul 3, 2024
dfde2f0
test
mavaylon1 Jul 3, 2024
d5c77a3
test
mavaylon1 Jul 8, 2024
73371b9
test
mavaylon1 Jul 8, 2024
6111b63
Update pyproject.toml
mavaylon1 Jul 8, 2024
7b15f6a
Update requirements-min.txt
mavaylon1 Jul 8, 2024
543225a
Update CHANGELOG.md
mavaylon1 Jul 8, 2024
fe70acf
ruff check
mavaylon1 Jul 8, 2024
732a323
Merge branch 'append_ref' of https://github.com/hdmf-dev/hdmf-zarr in…
mavaylon1 Jul 8, 2024
63e83e3
ruff check
mavaylon1 Jul 8, 2024
d5af631
clean up
mavaylon1 Jul 10, 2024
cc783fa
clear
mavaylon1 Jul 13, 2024
6868473
clear
mavaylon1 Jul 13, 2024
f5e6d7f
clear
mavaylon1 Jul 13, 2024
5373c7c
clear
mavaylon1 Jul 13, 2024
13caa37
Rename ZarrIO.__get_ref to ZarrIO._create_ref
rly Jul 13, 2024
ff6e435
fixed tests
mavaylon1 Jul 22, 2024
5e6a617
Merge branch 'dev' into append_ref
mavaylon1 Jul 22, 2024
c646c6d
clean up
mavaylon1 Jul 22, 2024
a6b5ac7
Merge branch 'dev' into append_ref
rly Jul 25, 2024
19470af
Add failing check to test
rly Jul 25, 2024
e8190ae
Fix
mavaylon1 Jul 26, 2024
2bcc4f6
Update CHANGELOG.md
rly Jul 26, 2024
10f0d06
Update src/hdmf_zarr/backend.py
rly Jul 26, 2024
4b2d32c
Update src/hdmf_zarr/backend.py
rly Jul 26, 2024
f716916
Update src/hdmf_zarr/backend.py
rly Jul 26, 2024
af72b53
Update src/hdmf_zarr/backend.py
rly Jul 26, 2024
7f7bda9
Update src/hdmf_zarr/backend.py
rly Jul 26, 2024
0909867
Update src/hdmf_zarr/backend.py
rly Jul 26, 2024
1d073a3
root
mavaylon1 Jul 28, 2024
8fc669f
Merge branch 'append_ref' of https://github.com/hdmf-dev/hdmf-zarr in…
mavaylon1 Jul 28, 2024
f32632c
notes
mavaylon1 Jul 28, 2024
798917f
loop
mavaylon1 Jul 28, 2024
7c5c0af
Update zarr_utils.py
mavaylon1 Jul 29, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# HDMF-ZARR Changelog

## 0.9.0 (Upcoming)
### Enhancements
* Added support for appending a dataset of references. @mavaylon1 [#203]([https://github.com/hdmf-dev/hdmf-zarr/pull/172](https://github.com/hdmf-dev/hdmf-zarr/pull/203))
rly marked this conversation as resolved.
Show resolved Hide resolved

## 0.8.0 (June 4, 2024)
### Bug Fixes
* Fixed bug when opening a file in with `mode=r+`. The file will open without using the consolidated metadata. @mavaylon1 [#182](https://github.com/hdmf-dev/hdmf-zarr/issues/182)
Expand Down
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ classifiers = [
"Topic :: Scientific/Engineering :: Medical Science Apps."
]
dependencies = [
'hdmf>=3.9.0',
'hdmf>=3.14.2',
'zarr>=2.11.0, <3.0', # pin below 3.0 until HDMF-zarr supports zarr 3.0
'numpy>=1.24, <2.0', # pin below 2.0 until HDMF supports numpy 2.0
'numcodecs>=0.9.1',
Expand Down Expand Up @@ -109,7 +109,7 @@ force-exclude = '''
'''

[tool.ruff]
select = ["E", "F", "T100", "T201", "T203"]
lint.select = ["E", "F", "T100", "T201", "T203"]
exclude = [
".git",
".tox",
Expand All @@ -128,5 +128,5 @@ line-length = 120
"src/*/__init__.py" = ["F401"]
"test_gallery.py" = ["T201"]

[tool.ruff.mccabe]
[tool.ruff.lint.mccabe]
max-complexity = 17
2 changes: 1 addition & 1 deletion requirements-min.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
hdmf==3.12.0
hdmf==3.14.2
zarr==2.11.0
numcodecs==0.9.1
pynwb==2.5.0
Expand Down
6 changes: 4 additions & 2 deletions src/hdmf_zarr/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,9 @@ def __get_ref(self, ref_object, export_source=None):
builder = ref_object.builder
else:
builder = self.manager.build(ref_object)

path = self.__get_path(builder)

# TODO Add to get region for region references.
# Also add {'name': 'region', 'type': (slice, list, tuple),
# 'doc': 'the region reference indexing object', 'default': None},
Expand Down Expand Up @@ -1279,7 +1281,7 @@ def __list_fill__(self, parent, name, data, options=None): # noqa: C901
dset.attrs['zarr_dtype'] = type_str

# Write the data to file
if dtype == object:
if dtype == object: # noqa: E721
for c in np.ndindex(data_shape):
o = data
for i in c:
Expand Down Expand Up @@ -1313,7 +1315,7 @@ def __scalar_fill__(self, parent, name, data, options=None):
except Exception as exc:
msg = 'cannot add %s to %s - could not determine type' % (name, parent.name)
raise Exception(msg) from exc
if dtype == object:
if dtype == object: # noqa: E721
io_settings['object_codec'] = self.__codec_cls()

dset = parent.require_dataset(name, shape=(1, ), dtype=dtype, **io_settings)
Expand Down
9 changes: 9 additions & 0 deletions src/hdmf_zarr/zarr_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from zarr import Array as ZarrArray

from hdmf.build import DatasetBuilder
from hdmf.data_utils import append_data
from hdmf.array import Array
from hdmf.query import HDMFDataset, ReferenceResolver, ContainerResolver, BuilderResolver
from hdmf.utils import docval, popargs, get_docval
Expand Down Expand Up @@ -73,6 +74,14 @@ def __iter__(self):
def __next__(self):
return self._get_ref(super().__next__())

def append(self, arg):
# Create Builder
builder = self.io.manager.build(arg)

# Create ZarrReference
ref = self.io._ZarrIO__get_ref(builder)
append_data(self.dataset, ref)


class BuilderResolverMixin(BuilderResolver): # refactor to backend/utils.py
"""
Expand Down
47 changes: 47 additions & 0 deletions tests/unit/test_zarrio.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@
from zarr.storage import (DirectoryStore,
TempStore,
NestedDirectoryStore)
from tests.unit.utils import (Baz, BazData, BazBucket, get_baz_buildmanager)
import zarr
from hdmf_zarr.backend import ZarrIO
import os
import shutil
import warnings


CUR_DIR = os.path.dirname(os.path.realpath(__file__))
Expand Down Expand Up @@ -182,3 +185,47 @@ def test_force_open_without_consolidated_fails(self):
except ValueError as e:
self.fail("ZarrIO.__open_file_consolidated raised an unexpected ValueError: {}".format(e))


class TestDatasetofReferences(ZarrStoreTestCase):
def setUp(self):
self.store_path = "test_io.zarr"
self.store = DirectoryStore(self.store_path)

def tearDown(self):
"""
Remove all files and folders defined by self.store_path
"""
paths = self.store_path if isinstance(self.store_path, list) else [self.store_path, ]
for path in paths:
if os.path.exists(path):
if os.path.isdir(path):
shutil.rmtree(path)
elif os.path.isfile(path):
os.remove(path)
else:
warnings.warn("Could not remove: %s" % path)

def test_append_references(self):
# Setup a file container with references
num_bazs = 10
bazs = [] # set up dataset of references
for i in range(num_bazs):
bazs.append(Baz(name='baz%d' % i))
baz_data = BazData(name='baz_data', data=bazs)
container = BazBucket(bazs=bazs, baz_data=baz_data)
manager = get_baz_buildmanager()
# write to file
with ZarrIO(self.store, manager=manager, mode='w') as writer:
writer.write(container=container)
# read from file and validate references
with ZarrIO(self.store, manager=manager, mode='r+') as append_io:
read_container = append_io.read()
DoR = read_container.baz_data.data
DoR.append(DoR[0])

expected = {'source': '.', 'path': '/bazs/baz0',
'object_id': DoR[0].object_id,
'source_object_id': container.object_id}

self.assertEqual(len(read_container.baz_data.data), 11)
self.assertDictEqual(read_container.baz_data.data.dataset[10], expected)
mavaylon1 marked this conversation as resolved.
Show resolved Hide resolved
Loading