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

HeteroData: data.*_dict fix in case attribute does not exist #3897

Merged
merged 2 commits into from
Jan 20, 2022
Merged
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
11 changes: 6 additions & 5 deletions torch_geometric/data/hetero_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,12 @@ def __getattr__(self, key: str) -> Any:
# `data.*` => Link to the `_global_store`.
# Using `data.*_dict` is the same as using `collect()` for collecting
# nodes and edges features.
if bool(re.search('_dict$', key)):
out = self.collect(key[:-5])
if len(out) > 0:
return out
return getattr(self._global_store, key)
if hasattr(self._global_store, key):
return getattr(self._global_store, key)
elif bool(re.search('_dict$', key)):
return self.collect(key[:-5])
raise AttributeError(f"'{self.__class__.__name__}' has no "
f"attribute '{key}'")

def __setattr__(self, key: str, value: Any):
# NOTE: We aim to prevent duplicates in node or edge types.
Expand Down