Skip to content

Commit

Permalink
Update heterograph.py (#6506)
Browse files Browse the repository at this point in the history
Co-authored-by: Hongzhi (Steve), Chen <chenhongzhi.nkcs@gmail.com>
  • Loading branch information
willarliss and frozenbugs committed Nov 16, 2023
1 parent c76a43c commit 12f02c3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
8 changes: 5 additions & 3 deletions python/dgl/heterograph.py
Original file line number Diff line number Diff line change
Expand Up @@ -6061,9 +6061,11 @@ def local_scope(self):
old_eframes = self._edge_frames
self._node_frames = [fr.clone() for fr in self._node_frames]
self._edge_frames = [fr.clone() for fr in self._edge_frames]
yield
self._node_frames = old_nframes
self._edge_frames = old_eframes
try:
yield
finally:
self._node_frames = old_nframes
self._edge_frames = old_eframes

def formats(self, formats=None):
r"""Get a cloned graph with the specified allowed sparse format(s) or
Expand Down
13 changes: 13 additions & 0 deletions tests/python/common/function/test_basics.py
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,19 @@ def foo(g):

foo(g)

# test exception handling
def foo(g):
try:
with g.local_scope():
g.ndata["hh"] = F.ones((g.num_nodes(), 1))
# throw TypeError
1 + "1"
except TypeError:
pass
assert "hh" not in g.ndata

foo(g)


@parametrize_idtype
def test_isolated_nodes(idtype):
Expand Down

0 comments on commit 12f02c3

Please sign in to comment.