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

Have VectorData expandable by default #1064

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
2 changes: 2 additions & 0 deletions src/hdmf/common/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from ..data_utils import DataIO, AbstractDataChunkIterator
from ..utils import docval, getargs, ExtenderMeta, popargs, pystr, AllowPositional, check_type
from ..term_set import TermSetWrapper
from ..backends.hdf5.h5_utils import H5DataIO


@register_class('VectorData')
Expand All @@ -41,6 +42,7 @@ class VectorData(Data):
'doc': 'a dataset where the first dimension is a concatenation of multiple vectors', 'default': list()},
allow_positional=AllowPositional.WARNING)
def __init__(self, **kwargs):
kwargs['data'] = H5DataIO(data=kwargs['data'], maxshape=(None,))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hardcoding H5DataIO will probably create issues with ZarrIO. In the best case, ZarrIO ignores the wrapper and worst case it would fail.... I'm not sure which. For ZarrIO we should not need to wrap for datasets to be expandable, but the problem is, we won't know which backend will be used until we call write to know which wrapper to use.

Not sure what the best solution is for this. I could imagine a few approaches:

  1. Have "expandable" as an option on the base DataIO class and wrap with DataIO as a generic wrapper that the specific backend (HD5FIO, ZarrIO etc.) would then need to know how to translate. ---> I think this should be feasible, but would require changes in both HDF5IO and ZarrIO
  2. Maybe we would need to wrap in the build process ---> I think this could work, but may be tricky
  3. Wrap with H5DataIO and require that the other backends know how to translate it ---> I don't like this one, because it hard-codes backend-specific wrappers in the Container

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what was going through my mind as well. I made a note documenting that. I had a expandable field idea.

description = popargs('description', kwargs)
super().__init__(**kwargs)
self.description = description
Expand Down
5 changes: 4 additions & 1 deletion src/hdmf/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,10 @@ def __init__(self, **kwargs):

@property
def data(self):
return self.__data
if isinstance(self.__data, DataIO):
return self.__data.data
else:
return self.__data

@property
def shape(self):
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/common/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ def test_add_column_auto_index_bool(self):
description='qux column',
data=expected,
index=True)

self.assertListEqual(table['qux'][:], expected)
self.assertListEqual(table.qux_index.data, [3, 7])
# Add more rows after we created the column
Expand Down Expand Up @@ -1805,6 +1806,7 @@ def test_get_2d(self):
elements=['a', 'b', 'c'],
data=np.array([[0, 0], [1, 1], [2, 2]]))
dat = ed[0]
breakpoint()
np.testing.assert_array_equal(dat, ['a', 'a'])

def test_get_2d_w_2d(self):
Expand Down
Loading