"...hubert/git@developer.sourcefind.cn:OpenDAS/torchaudio.git" did not exist on "87f0d1989014f2da9d56a326b54507a7a1cbc712"
Unverified Commit 8c8c5b1d authored by Andrew's avatar Andrew Committed by GitHub
Browse files

[Bug fix] Stop erasing schemas of frames with no data rows (#2529)



* added option for batching empty data, fixes #2526

* added option for batching empty data, fixes #2526

* decreased line lengths

* removed trailing whitespace

* fixed wrong feature name

* [Bugfix] stop erasing schema of frames w/ no cols (fixes #2528)

* removed arg doc
Co-authored-by: default avatarQuan (Andy) Gan <coin2028@hotmail.com>
Co-authored-by: default avatarMinjie Wang <wmjlyjemaine@gmail.com>
parent 673cc64c
...@@ -505,31 +505,25 @@ class Frame(MutableMapping): ...@@ -505,31 +505,25 @@ class Frame(MutableMapping):
def _append(self, other): def _append(self, other):
"""Append ``other`` frame to ``self`` frame.""" """Append ``other`` frame to ``self`` frame."""
# NOTE: `other` can be empty. # pad columns that are not provided in the other frame with initial values
if self.num_rows == 0: for key, col in self._columns.items():
# if no rows in current frame; append is equivalent to if key in other:
# directly updating columns. continue
self._columns = {key: Column.create(data) for key, data in other.items()} scheme = col.scheme
else: ctx = F.context(col.data)
# pad columns that are not provided in the other frame with initial values if self.get_initializer(key) is None:
for key, col in self._columns.items(): self._set_zero_default_initializer()
if key in other: initializer = self.get_initializer(key)
continue new_data = initializer((other.num_rows,) + scheme.shape,
scheme = col.scheme scheme.dtype, ctx,
ctx = F.context(col.data) slice(self._num_rows, self._num_rows + other.num_rows))
if self.get_initializer(key) is None: other[key] = new_data
self._set_zero_default_initializer() # append other to self
initializer = self.get_initializer(key) for key, col in other._columns.items():
new_data = initializer((other.num_rows,) + scheme.shape, if key not in self._columns:
scheme.dtype, ctx, # the column does not exist; init a new column
slice(self._num_rows, self._num_rows + other.num_rows)) self.add_column(key, col.scheme, F.context(col.data))
other[key] = new_data self._columns[key].extend(col.data, col.scheme)
# append other to self
for key, col in other._columns.items():
if key not in self._columns:
# the column does not exist; init a new column
self.add_column(key, col.scheme, F.context(col.data))
self._columns[key].extend(col.data, col.scheme)
def append(self, other): def append(self, other):
"""Append another frame's data into this frame. """Append another frame's data into this frame.
......
...@@ -338,6 +338,14 @@ def test_hypersparse_query(): ...@@ -338,6 +338,14 @@ def test_hypersparse_query():
assert g.out_degree(0) == 1 assert g.out_degree(0) == 1
assert g.out_degree(1) == 0 assert g.out_degree(1) == 0
def test_empty_data_initialized():
g = dgl.DGLGraph()
g = g.to(F.ctx())
g.ndata["ha"] = F.tensor([])
g.add_nodes(1, {"hb": F.tensor([1])})
assert "ha" in g.ndata
assert len(g.ndata["ha"]) == 1
if __name__ == '__main__': if __name__ == '__main__':
test_query() test_query()
test_mutation() test_mutation()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment