Skip to content

Commit

Permalink
first
Browse files Browse the repository at this point in the history
  • Loading branch information
mavaylon1 committed Dec 13, 2023
1 parent 9692a98 commit 005bfbc
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 10 deletions.
11 changes: 10 additions & 1 deletion src/hdmf_zarr/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -1018,11 +1018,20 @@ def write_dataset(self, **kwargs): # noqa: C901
**options['io_settings'])
self._written_builders.set_written(builder) # record that the builder has been written
dset.attrs['zarr_dtype'] = type_str
new_items = []
for j, item in enumerate(data):
new_item = list(item)
for i in refs:
new_item[i] = self.__get_ref(item[i], export_source=export_source)
dset[j] = new_item
new_items.append(tuple(new_item))
# dset[j] = new_item

generated_dtype = []
for item in builder.dtype:
if item['dtype'] == type('string'):
item['dtype'] = 'U25'
generated_dtype.append((item['name'], item['dtype']))
dset[...] = np.array(new_items, dtype=generated_dtype)
else:
# write a compound datatype
dset = self.__list_fill__(parent, name, data, options)
Expand Down
3 changes: 2 additions & 1 deletion src/hdmf_zarr/zarr_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ def dtype(self):
return self.__dtype

def __getitem__(self, arg):
rows = copy(super().__getitem__(arg))
rows = list(copy(super().__getitem__(arg)))
# breakpoint()
if np.issubdtype(type(arg), np.integer):
self.__swap_refs(rows)
else:
Expand Down
29 changes: 21 additions & 8 deletions tests/unit/base_tests_zarrio.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,20 +426,33 @@ def test_read_reference(self):
builder = self.createReferenceBuilder()['ref_dataset']
read_builder = self.root['ref_dataset']
# Load the linked arrays and confirm we get the same data as we had in the original builder
for i, v in enumerate(read_builder['data']):
self.assertTrue(np.all(builder['data'][i]['builder']['data'] == v['data'][:]))
breakpoint()
# for i, v in enumerate(read_builder['data']):
# self.assertTrue(np.all(builder['data'][i]['builder']['data'] == v['data'][:]))

def test_read_reference_compound(self):
self.test_write_reference_compound()
self.read()
builder = self.createReferenceCompoundBuilder()['ref_dataset']
read_builder = self.root['ref_dataset']
# Load the elements of each entry in the compound dataset and compar the index, string, and referenced array
for i, v in enumerate(read_builder['data']):
self.assertEqual(v[0], builder['data'][i][0]) # Compare index value from compound tuple
self.assertEqual(v[1], builder['data'][i][1]) # Compare string value from compound tuple
self.assertTrue(np.all(v[2]['data'][:] == builder['data'][i][2]['builder']['data'][:])) # Compare ref array
# print(read_builder)
read_builder['data'][0]
#Load the elements of each entry in the compound dataset and compare the index, string, and referenced array
breakpoint()
# for i, v in enumerate(read_builder['data']):
# # self.assertEqual(v[0], builder['data'][i][0]) # Compare index value from compound tuple
# self.assertEqual(v[1], builder['data'][i][1]) # Compare string value from compound tuple
# self.assertTrue(np.all(v[2]['data'][:] == builder['data'][i][2]['builder']['data'][:])) # Compare ref array

# self.assertEqual(read_builder['data'].dataset[0][0], builder['data'][0][0])
# self.assertEqual(read_builder['data'].dataset[0][0], builder['data'][1][0])
# self.assertEqual(read_builder['data'].dataset[0][1], 'dataset_1')
# self.assertEqual(read_builder['data'].dataset[1][1], 'dataset_2')
# self.assertEqual(read_builder['data'].dataset[0][1], '/dataset_1')
# self.assertEqual(read_builder['data'].dataset[1][1], '/dataset_2')

# self.assertEqual(v[1], builder['data'][i][1]) # Compare string value from compound tuple
# self.assertTrue(np.all(v[2]['data'][:] == builder['data'][i][2]['builder']['data'][:])) # Compare ref array


def test_read_reference_compound_buf(self):
data_1 = np.arange(100, 200, 10).reshape(2, 5)
Expand Down

0 comments on commit 005bfbc

Please sign in to comment.