Repository: pyg-team/pytorch_geometric
Pull request #7573 (2023-06-13 16:37:07)

Added `edge_index` property to `TemporalData`
Added the `edge_index` property in order to make it easier to visualize time series of temporal by simply doing a `test_data.edge_index` and using `networkx` which is useful for large multiple graph datasets. 


codecov[bot]: ## [Codecov](https://app.codecov.io/gh/pyg-team/pytorch_geometric/pull/7573?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pyg-team) Report
> Merging [#7573](https://app.codecov.io/gh/pyg-team/pytorch_geometric/pull/7573?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pyg-team) (6bf7bfd) into [master](https://app.codecov.io/gh/pyg-team/pytorch_geometric/commit/5ff3295250715f765ac60dfd6c34e0fc7f1cd904?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pyg-team) (5ff3295) will **decrease** coverage by `0.01%`.
> The diff coverage is `66.66%`.

```diff
@@            Coverage Diff             @@
##           master    #7573      +/-   ##
==========================================
- Coverage   91.41%   91.40%   -0.01%     
==========================================
  Files         449      449              
  Lines       25119    25122       +3     
==========================================
+ Hits        22962    22964       +2     
- Misses       2157     2158       +1     
```


| [Impacted Files](https://app.codecov.io/gh/pyg-team/pytorch_geometric/pull/7573?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pyg-team) | Coverage Δ | |
|---|---|---|
| [torch\_geometric/data/temporal.py](https://app.codecov.io/gh/pyg-team/pytorch_geometric/pull/7573?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pyg-team#diff-dG9yY2hfZ2VvbWV0cmljL2RhdGEvdGVtcG9yYWwucHk=) | `94.40% <66.66%> (-0.69%)` | :arrow_down: |

:mega: We’re building smart automated test selection to slash your CI/CD build times. [Learn more](https://about.codecov.io/iterative-testing/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pyg-team)


Patch:
diff --git a/torch_geometric/data/temporal.py b/torch_geometric/data/temporal.py
index 2b618a185..c2e99af78 100644
--- a/torch_geometric/data/temporal.py
+++ b/torch_geometric/data/temporal.py
@@ -212,6 +212,16 @@ class TemporalData(BaseData):
         r"""Alias for :meth:`~torch_geometric.data.TemporalData.num_events`."""
         return self.num_events
 
+    @property
+    def edge_index(self) -> Tensor:
+        r"""Returns the edge indices of the graph."""
+        if 'edge_index' in self:
+            return self._store['edge_index']
+        if self.src is not None and self.dst is not None:
+            return torch.stack([self.src, self.dst], dim=0)
+        raise ValueError(f"{self.__class__.__name__} does not contain "
+                         f"'edge_index' information")
+
     def size(
         self, dim: Optional[int] = None
     ) -> Union[Tuple[Optional[int], Optional[int]], Optional[int]]:


Test patch:
diff --git a/test/data/test_temporal.py b/test/data/test_temporal.py
index 47d2701c6..7c6acfc06 100644
--- a/test/data/test_temporal.py
+++ b/test/data/test_temporal.py
@@ -26,6 +26,12 @@ def test_temporal_data():
     assert data.src.tolist() == [0, 1, 2]
     assert data['src'].tolist() == [0, 1, 2]
 
+    assert data.edge_index.tolist() == [[0, 1, 2], [3, 4, 5]]
+    data.edge_index = 'edge_index'
+    assert data.edge_index == 'edge_index'
+    del data.edge_index
+    assert data.edge_index.tolist() == [[0, 1, 2], [3, 4, 5]]
+
     assert sorted(data.keys) == ['dst', 'msg', 'src', 't', 'y']
     assert sorted(data.to_dict().keys()) == sorted(data.keys)