Skip to content

Commit

Permalink
#handle zero-length lists and tuples in convert_dtype (#57)
Browse files Browse the repository at this point in the history
* #56 handle zero-length lists and tuples in convert_dtype

* #56 empty value test

* #56 fix return type when zero-length list passed to ObjectMapper.convert_dtype
  • Loading branch information
NileGraddis authored and oruebel committed May 22, 2019
1 parent bbe5c31 commit 5a864ef
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/hdmf/build/map.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,8 @@ def convert_dtype(cls, spec, value):
ret = np.asarray(value).astype(dtype_func)
ret_dtype = ret.dtype.type
elif isinstance(value, (tuple, list)):
if len(value) == 0:
return value, spec_dtype
ret = list()
for elem in value:
tmp, tmp_dtype = cls.convert_dtype(spec, elem)
Expand Down
8 changes: 8 additions & 0 deletions tests/unit/build_tests/test_io_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,14 @@ def test_build(self):
attributes={'attr1': 'value1', 'attr2': 10})
self.assertDictEqual(builder, expected)

def test_build_empty(self):
''' Test default mapping functionality when no attributes are nested '''
container = Bar('my_bar', [], 'value1', 10)
builder = self.mapper.build(container, self.manager)
expected = GroupBuilder('my_bar', datasets={'data': DatasetBuilder('data', [])},
attributes={'attr1': 'value1', 'attr2': 10})
self.assertDictEqual(builder, expected)

def test_construct(self):
builder = GroupBuilder('my_bar', datasets={'data': DatasetBuilder('data', list(range(10)))},
attributes={'attr1': 'value1', 'attr2': 10, 'data_type': 'Bar',
Expand Down

0 comments on commit 5a864ef

Please sign in to comment.