Skip to content

Commit

Permalink
clean up/adjust resolve_ref
Browse files Browse the repository at this point in the history
  • Loading branch information
mavaylon1 committed Sep 28, 2023
1 parent 13387a3 commit 862db84
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 13 deletions.
10 changes: 1 addition & 9 deletions src/hdmf_zarr/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import numpy as np
import tempfile
import logging
import pathlib

# Zarr imports
import zarr
Expand Down Expand Up @@ -550,14 +549,7 @@ def resolve_ref(self, zarr_ref):
try:
target_zarr_obj = target_zarr_obj[object_path]
except Exception:
# TODO: Find why the reference includes the root object.
# This is a fix to allow the target object to be found
try:
object_path = pathlib.Path(object_path)
rel_obj_path = object_path.relative_to(*object_path.parts[:2])
target_zarr_obj = target_zarr_obj[rel_obj_path]
except Exception:
raise ValueError("Found bad link to object %s in file %s" % (object_path, source_file))
raise ValueError("Found bad link to object %s in file %s" % (object_path, source_file))
# Return the create path
return target_name, target_zarr_obj

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/base_tests_zarrio.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def test_write_compound(self, test_data=None):
{'name': 'name', 'dtype': str}]
self.__dataset_builder = DatasetBuilder('my_data', data, dtype=data_type)
self.createGroupBuilder()
writer = ZarrIO(self.store, manager=self.manager, mode='a')
writer = ZarrIO(self.store, manager=self.manager, mode='w')
writer.write_builder(self.builder)
writer.close()

Expand Down
7 changes: 4 additions & 3 deletions tests/unit/test_io_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ def test_export_cpd_dset_refs(self):
bazs.append(b)
baz_pairs.append((i, b))
baz_cpd_data = BazCpdData(name='baz_cpd_data1', data=baz_pairs)
bucket = BazBucket(name='bucket1', bazs=bazs.copy(), baz_cpd_data=baz_cpd_data)
bucket = BazBucket(name='root', bazs=bazs.copy(), baz_cpd_data=baz_cpd_data)

with HDF5IO(self.path[0], manager=get_baz_buildmanager(), mode='w') as write_io:
write_io.write(bucket)
Expand Down Expand Up @@ -751,7 +751,7 @@ def test_export_cpd_dset_refs(self):
bazs.append(b)
baz_pairs.append((i, b))
baz_cpd_data = BazCpdData(name='baz_cpd_data1', data=baz_pairs)
bucket = BazBucket(name='bucket1', bazs=bazs.copy(), baz_cpd_data=baz_cpd_data)
bucket = BazBucket(name='root', bazs=bazs.copy(), baz_cpd_data=baz_cpd_data)

with ZarrIO(self.path[0], manager=get_baz_buildmanager(), mode='w') as write_io:
write_io.write(bucket)
Expand Down Expand Up @@ -797,12 +797,13 @@ def test_export_cpd_dset_refs(self):
bazs.append(b)
baz_pairs.append((i, b))
baz_cpd_data = BazCpdData(name='baz_cpd_data1', data=baz_pairs)
bucket = BazBucket(name='bucket1', bazs=bazs.copy(), baz_cpd_data=baz_cpd_data)
bucket = BazBucket(name='root', bazs=bazs.copy(), baz_cpd_data=baz_cpd_data)

with ZarrIO(self.path[0], manager=get_baz_buildmanager(), mode='w') as write_io:
write_io.write(bucket)
with ZarrIO(self.path[0], manager=get_baz_buildmanager(), mode='r') as read_io:
read_bucket1 = read_io.read()
read_bucket1.baz_cpd_data.data[0][0]
# NOTE: reference IDs might be the same between two identical files
# adding a Baz with a smaller name should change the reference IDs on export
new_baz = Baz(name='baz000')
Expand Down

0 comments on commit 862db84

Please sign in to comment.