Repository: pyg-team/pytorch_geometric
Pull request #7939 (2023-08-27 16:06:41)

Drop Python 3.7 support
Drops Python 3.7 support as PyTorch 2.0.0 also did (https://github.com/pytorch/pytorch/issues/80513) and Python 3.7 reached EOL (https://devguide.python.org/versions/).

codecov[bot]: ## [Codecov](https://app.codecov.io/gh/pyg-team/pytorch_geometric/pull/7939?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pyg-team) Report
> Merging [#7939](https://app.codecov.io/gh/pyg-team/pytorch_geometric/pull/7939?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pyg-team) (a83f777) into [master](https://app.codecov.io/gh/pyg-team/pytorch_geometric/commit/143487bc18a5bf3e7968c2637823791781e6135a?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pyg-team) (143487b) will **decrease** coverage by `0.79%`.
> The diff coverage is `100.00%`.

> :exclamation: Current head a83f777 differs from pull request most recent head 45afe28. Consider uploading reports for the commit 45afe28 to get more accurate results

```diff
@@            Coverage Diff             @@
##           master    #7939      +/-   ##
==========================================
- Coverage   90.19%   89.41%   -0.79%     
==========================================
  Files         458      458              
  Lines       26877    26871       -6     
==========================================
- Hits        24243    24026     -217     
- Misses       2634     2845     +211     
```


| [Files Changed](https://app.codecov.io/gh/pyg-team/pytorch_geometric/pull/7939?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pyg-team) | Coverage Δ | |
|---|---|---|
| [torch\_geometric/io/planetoid.py](https://app.codecov.io/gh/pyg-team/pytorch_geometric/pull/7939?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pyg-team#diff-dG9yY2hfZ2VvbWV0cmljL2lvL3BsYW5ldG9pZC5weQ==) | `78.20% <100.00%> (+0.42%)` | :arrow_up: |

... and [32 files with indirect coverage changes](https://app.codecov.io/gh/pyg-team/pytorch_geometric/pull/7939/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pyg-team)

: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/.github/workflows/building_pyg_conda.yml b/.github/workflows/building_pyg_conda.yml
index 7bb78c34b..e92f6300c 100644
--- a/.github/workflows/building_pyg_conda.yml
+++ b/.github/workflows/building_pyg_conda.yml
@@ -11,7 +11,7 @@ jobs:
       fail-fast: false
       matrix:
         os: [ubuntu-latest, macos-latest, windows-latest]
-        python-version: ['3.7', '3.8', '3.9', '3.10', '3.11']
+        python-version: ['3.8', '3.9', '3.10', '3.11']
         torch-version: [1.12.0, 1.13.0, 2.0.0]
         cuda-version: ['cpu', 'cu102', 'cu113', 'cu116', 'cu117', 'cu118']
         exclude:
@@ -29,8 +29,6 @@ jobs:
             cuda-version: 'cu113'
           - torch-version: 1.13.0
             cuda-version: 'cu118'
-          - torch-version: 2.0.0
-            python-version: '3.7'
           - torch-version: 2.0.0
             cuda-version: 'cu102'
           - torch-version: 2.0.0
diff --git a/.github/workflows/building_rusty1s_conda.yml b/.github/workflows/building_rusty1s_conda.yml
index 3a2f369bb..973b316e4 100644
--- a/.github/workflows/building_rusty1s_conda.yml
+++ b/.github/workflows/building_rusty1s_conda.yml
@@ -11,7 +11,7 @@ jobs:
       fail-fast: false
       matrix:
         os: [ubuntu-latest, macos-latest, windows-latest]
-        python-version: ['3.7', '3.8', '3.9', '3.10', '3.11']
+        python-version: ['3.8', '3.9', '3.10', '3.11']
         torch-version: [1.12.0, 1.13.0, 2.0.0]
         cuda-version: ['cpu', 'cu102', 'cu113', 'cu116', 'cu117', 'cu118']
         exclude:
@@ -29,8 +29,6 @@ jobs:
             cuda-version: 'cu113'
           - torch-version: 1.13.0
             cuda-version: 'cu118'
-          - torch-version: 2.0.0
-            python-version: '3.7'
           - torch-version: 2.0.0
             cuda-version: 'cu102'
           - torch-version: 2.0.0
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a9e7f8fed..aa3d43cce 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -88,6 +88,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
 
 ### Changed
 
+- Fixed `from_networkx` conversion from `nx.stochastic_block_model` graphs ([#7941](https://github.com/pyg-team/pytorch_geometric/pull/7941))
 - Fixed the usage of `bias_initializer` in `HeteroLinear` ([#7923](https://github.com/pyg-team/pytorch_geometric/pull/7923))
 - Fixed broken links in `HGBDataset` ([#7907](https://github.com/pyg-team/pytorch_geometric/pull/7907))
 - Fixed an issue where `SetTransformerAggregation` produced `NaN` values for isolates nodes ([#7902](https://github.com/pyg-team/pytorch_geometric/pull/7902))
@@ -148,6 +149,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
 
 ### Removed
 
+- Dropped Python 3.7 support ([#7939](https://github.com/pyg-team/pytorch_geometric/pull/7939))
 - Removed `layer_type` argument in `contrib.explain.GraphMaskExplainer` ([#7445](https://github.com/pyg-team/pytorch_geometric/pull/7445))
 - Replaced `FastHGTConv` with `HGTConv` ([#7117](https://github.com/pyg-team/pytorch_geometric/pull/7117))
 
diff --git a/README.md b/README.md
index e4bbb2aa0..784846c40 100644
--- a/README.md
+++ b/README.md
@@ -358,7 +358,7 @@ These approaches have been implemented in PyG, and can benefit from the above GN
 
 ## Installation
 
-PyG is available for Python 3.7 to Python 3.11.
+PyG is available for Python 3.8 to Python 3.11.
 
 ### Anaconda
 
diff --git a/docs/source/install/installation.rst b/docs/source/install/installation.rst
index 9c696c70b..9d2677f4c 100644
--- a/docs/source/install/installation.rst
+++ b/docs/source/install/installation.rst
@@ -1,7 +1,7 @@
 Installation
 ============
 
-:pyg:`PyG` is available for Python 3.7 to Python 3.11.
+:pyg:`PyG` is available for Python 3.8 to Python 3.11.
 
 .. note::
    We do not recommend installation as a root user on your system Python.
diff --git a/torch_geometric/contrib/explain/__init__.py b/torch_geometric/contrib/explain/__init__.py
index aabe37cf1..14a3ff0ac 100644
--- a/torch_geometric/contrib/explain/__init__.py
+++ b/torch_geometric/contrib/explain/__init__.py
@@ -1,13 +1,13 @@
+from torch_geometric.deprecation import deprecated
+
 from .pgm_explainer import PGMExplainer
 from torch_geometric.explain.algorithm.graphmask_explainer import (
     GraphMaskExplainer as NewGraphMaskExplainer)
-from torch_geometric.deprecation import deprecated
 
 GraphMaskExplainer = deprecated(
     "use 'torch_geometric.explain.algorithm.GraphMaskExplainer' instead", )(
         NewGraphMaskExplainer)
 
 __all__ = classes = [
-    'GraphMaskExplainer',
     'PGMExplainer',
 ]
diff --git a/torch_geometric/datasets/hydro_net.py b/torch_geometric/datasets/hydro_net.py
index d501c6153..e2ac24f05 100644
--- a/torch_geometric/datasets/hydro_net.py
+++ b/torch_geometric/datasets/hydro_net.py
@@ -2,7 +2,7 @@ import copy
 import os
 import os.path as osp
 from dataclasses import dataclass
-from functools import lru_cache
+from functools import cached_property
 from glob import glob
 from pathlib import Path
 from typing import Callable, List, Optional, Tuple, Union
@@ -18,13 +18,6 @@ from torch_geometric.data import (
     extract_zip,
 )
 
-try:
-    from functools import cached_property
-except ImportError:  # Python 3.7 support.
-
-    def cached_property(func):
-        return property(fget=lru_cache(maxsize=1)(func))
-
 
 class HydroNet(InMemoryDataset):
     r"""The HydroNet dataest from the
diff --git a/torch_geometric/explain/algorithm/graphmask_explainer.py b/torch_geometric/explain/algorithm/graphmask_explainer.py
index 8a034b87c..27ace22ae 100644
--- a/torch_geometric/explain/algorithm/graphmask_explainer.py
+++ b/torch_geometric/explain/algorithm/graphmask_explainer.py
@@ -46,9 +46,9 @@ class GraphMaskExplainer(ExplainerAlgorithm):
 
     .. note::
         For an example of using :class:`GraphMaskExplainer`,
-        see `examples/contrib/graphmask_explainer.py
+        see `examples/explain/graphmask_explainer.py
         <https://github.com/pyg-team/pytorch_geometric/blob/master/examples/
-        /contrib/graphmask_explainer.py>`_.
+        /explain/graphmask_explainer.py>`_.
 
     Args:
         num_layers (int): The number of layers to use.
diff --git a/torch_geometric/io/planetoid.py b/torch_geometric/io/planetoid.py
index 3026b11f5..7ce372eba 100644
--- a/torch_geometric/io/planetoid.py
+++ b/torch_geometric/io/planetoid.py
@@ -1,5 +1,4 @@
 import os.path as osp
-import sys
 import warnings
 from itertools import repeat
 
@@ -93,11 +92,8 @@ def read_file(folder, prefix, name):
         return read_txt_array(path, dtype=torch.long)
 
     with open(path, 'rb') as f:
-        if sys.version_info > (3, 0):
-            warnings.filterwarnings('ignore', '.*`scipy.sparse.csr` name.*')
-            out = pickle.load(f, encoding='latin1')
-        else:
-            out = pickle.load(f)
+        warnings.filterwarnings('ignore', '.*`scipy.sparse.csr` name.*')
+        out = pickle.load(f, encoding='latin1')
 
     if name == 'graph':
         return out
diff --git a/torch_geometric/utils/convert.py b/torch_geometric/utils/convert.py
index e0fa499b5..dce666aa4 100644
--- a/torch_geometric/utils/convert.py
+++ b/torch_geometric/utils/convert.py
@@ -258,7 +258,7 @@ def from_networkx(
         else:
             try:
                 data[key] = torch.tensor(value)
-            except (ValueError, TypeError):
+            except (ValueError, TypeError, RuntimeError):
                 pass
 
     data['edge_index'] = edge_index.view(2, -1)


Test patch:
diff --git a/test/utils/test_convert.py b/test/utils/test_convert.py
index 8e4b8280a..5a259ee26 100644
--- a/test/utils/test_convert.py
+++ b/test/utils/test_convert.py
@@ -323,6 +323,25 @@ def test_from_networkx_subgraph_convert():
     assert sub_edge_index_1.tolist() == sub_edge_index_2.tolist()
 
 
+@withPackage('networkx')
+@pytest.mark.parametrize('n', [100])
+@pytest.mark.parametrize('p', [0.8])
+@pytest.mark.parametrize('q', [0.2])
+def test_from_networkx_sbm(n, p, q):
+    import networkx as nx
+    G = nx.stochastic_block_model(
+        sizes=[n // 2, n // 2],
+        p=[[p, q], [q, p]],
+        seed=0,
+        directed=False,
+    )
+
+    data = from_networkx(G)
+    assert data.num_nodes == 100
+    assert torch.equal(data.block[:50], data.block.new_zeros(50))
+    assert torch.equal(data.block[50:], data.block.new_ones(50))
+
+
 @withPackage('networkit')
 def test_to_networkit_vice_versa():
     edge_index = torch.tensor([[0, 1], [1, 0]])