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

Update heterograph.py #6506

Merged
merged 8 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
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:
willarliss marked this conversation as resolved.
Show resolved Hide resolved
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)
frozenbugs marked this conversation as resolved.
Show resolved Hide resolved


@parametrize_idtype
def test_isolated_nodes(idtype):
Expand Down