"docs/git@developer.sourcefind.cn:change/sglang.git" did not exist on "1e2cf2b541c7b22dbf5f0d5bf6da78d93eaa3648"
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):
def _append(self, other):
"""Append ``other`` frame to ``self`` frame."""
# NOTE: `other` can be empty.
if self.num_rows == 0:
# if no rows in current frame; append is equivalent to
# directly updating columns.
self._columns = {key: Column.create(data) for key, data in other.items()}
else:
# pad columns that are not provided in the other frame with initial values
for key, col in self._columns.items():
if key in other:
continue
scheme = col.scheme
ctx = F.context(col.data)
if self.get_initializer(key) is None:
self._set_zero_default_initializer()
initializer = self.get_initializer(key)
new_data = initializer((other.num_rows,) + scheme.shape,
scheme.dtype, ctx,
slice(self._num_rows, self._num_rows + other.num_rows))
other[key] = new_data
# 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)
# pad columns that are not provided in the other frame with initial values
for key, col in self._columns.items():
if key in other:
continue
scheme = col.scheme
ctx = F.context(col.data)
if self.get_initializer(key) is None:
self._set_zero_default_initializer()
initializer = self.get_initializer(key)
new_data = initializer((other.num_rows,) + scheme.shape,
scheme.dtype, ctx,
slice(self._num_rows, self._num_rows + other.num_rows))
other[key] = new_data
# 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):
"""Append another frame's data into this frame.
......
......@@ -338,6 +338,14 @@ def test_hypersparse_query():
assert g.out_degree(0) == 1
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__':
test_query()
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