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

add append for Datasets in Data objects #161

Merged
merged 5 commits into from
Oct 2, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions src/hdmf/common/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def __init__(self, **kwargs):
@docval({'name': 'val', 'type': None, 'doc': 'the value to add to this column'})
def add_row(self, **kwargs):
val = getargs('val', kwargs)
self.data.append(val)
self.append(val)


@register_class('VectorIndex')
Expand Down Expand Up @@ -332,7 +332,7 @@ def add_row(self, **kwargs):
row_id = data.pop('id', None)
if row_id is None:
row_id = len(self)
self.id.data.append(row_id)
self.id.append(row_id)

for colname, colnum in self.__colids.items():
if colname not in data:
Expand Down
11 changes: 11 additions & 0 deletions src/hdmf/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from .utils import docval, get_docval, call_docval_func, getargs, ExtenderMeta
from .data_utils import DataIO
from warnings import warn
import h5py


class AbstractContainer(with_metaclass(ExtenderMeta, object)):
Expand Down Expand Up @@ -414,6 +415,11 @@ def append(self, arg):
self.data.append(arg)
elif isinstance(self.data, np.ndarray):
self.__data = np.append(self.__data, [arg])
elif isinstance(self.data, h5py.Dataset):
shape = list(self.__data.shape)
shape[0] += 1
self.__data.resize(shape)
self.__data[-1] = arg
else:
msg = "Data cannot append to object of type '%s'" % type(self.__data)
raise ValueError(msg)
Expand All @@ -423,6 +429,11 @@ def extend(self, arg):
self.data.extend(arg)
elif isinstance(self.data, np.ndarray):
self.__data = np.append(self.__data, [arg])
elif isinstance(h5py.Dataset):
bendichter marked this conversation as resolved.
Show resolved Hide resolved
shape = list(self.__data.shape)
shape[0] += len(arg)
self.__data.resize(shape)
self.__data[-len(arg):] = arg
else:
msg = "Data cannot extend object of type '%s'" % type(self.__data)
raise ValueError(msg)
Expand Down