dmlc / dmlc/dgl

examples/pytorch/mvgrl/graph fails: AttributeError: module 'numpy' has no attribute 'float' (this example isn't compatible with numpy-1.24)

Open
#5,669 8 comments 0 reactions 1 assignee Claimed by @Rhett-Ying View on GitHub
bug:confirmed
Dominant language
Python
Stars
14.3k
Forks
3.1k
PR merge metrics
No merged PRs in 30d

Description

## 🐛 Bug

```

$ python3.9 main.py
--2023-05-09 13:56:56-- https://ls11-www.cs.tu-dortmund.de/people/morris/graphkerneldatasets/MUTAG.zip
Resolving ls11-www.cs.tu-dortmund.de (ls11-www.cs.tu-dortmund.de)... 129.217.38.183
Connecting to ls11-www.cs.tu-dortmund.de (ls11-www.cs.tu-dortmund.de)|129.217.38.183|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 18394 (18K) [application/zip]
Saving to: ‘MUTAG.zip’

MUTAG.zip 100%[=============================================================================================================>] 17.96K 112KB/s in 0.2s

2023-05-09 13:56:58 (112 KB/s) - ‘MUTAG.zip’ saved [18394/18394]

Archive: MUTAG.zip
creating: MUTAG/
extracting: MUTAG/MUTAG_A.txt
extracting: MUTAG/MUTAG_edge_labels.txt
extracting: MUTAG/MUTAG_graph_indicator.txt
extracting: MUTAG/MUTAG_graph_labels.txt
extracting: MUTAG/MUTAG_node_labels.txt
extracting: MUTAG/README.txt
No node attributes
Traceback (most recent call last):
File "/usr/ports/math/py-dgl/work-py39/dgl-1.1.0/examples/pytorch/mvgrl/graph/main.py", line 70, in
dataset = load(args.dataname)
File "/usr/ports/math/py-dgl/work-py39/dgl-1.1.0/examples/pytorch/mvgrl/graph/dataset.py", line 145, in load
graphs, diff = process(dataset)
File "/usr/ports/math/py-dgl/work-py39/dgl-1.1.0/examples/pytorch/mvgrl/graph/dataset.py", line 133, in process
(np.array(u[1]["label"], dtype=np.float), f)
File "/usr/local/lib/python3.9/site-packages/numpy/__init__.py", line 284, in __getattr__
raise AttributeError("module {!r} has no attribute "
AttributeError: module 'numpy' has no attribute 'float'
```

numpy-1.24.1 has numpy.float deprecated.
According to [this](https://stackoverflow.com/questions/74844262/how-can-i-solve-error-module-numpy-has-no-attribute-float-in-python) stack overflow answer Python's ```float``` should be used instead.

After the replacement ```s/np.float/float/g``` is done in ```dataset.py``` this example still fails:
```
$ python3.9 main.py ^C
[yuri@yv /usr/ports/math/py-dgl/work-py39/dgl-1.1.0/examples/pytorch/mvgrl/graph]$ rm -rf data
[yuri@yv /usr/ports/math/py-dgl/work-py39/dgl-1.1.0/examples/pytorch/mvgrl/graph]$ python3.9 main.py
--2023-05-09 14:02:26-- https://ls11-www.cs.tu-dortmund.de/people/morris/graphkerneldatasets/MUTAG.zip
Resolving ls11-www.cs.tu-dortmund.de (ls11-www.cs.tu-dortmund.de)... 129.217.38.183
Connecting to ls11-www.cs.tu-dortmund.de (ls11-www.cs.tu-dortmund.de)|129.217.38.183|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 18394 (18K) [application/zip]
Saving to: ‘MUTAG.zip’

MUTAG.zip 100%[=============================================================================================================>] 17.96K 113KB/s in 0.2s

2023-05-09 14:02:27 (113 KB/s) - ‘MUTAG.zip’ saved [18394/18394]

Archive: MUTAG.zip
creating: MUTAG/
extracting: MUTAG/MUTAG_A.txt
extracting: MUTAG/MUTAG_edge_labels.txt
extracting: MUTAG/MUTAG_graph_indicator.txt
extracting: MUTAG/MUTAG_graph_labels.txt
extracting: MUTAG/MUTAG_node_labels.txt
extracting: MUTAG/README.txt
No node attributes
Traceback (most recent call last):
File "/usr/ports/math/py-dgl/work-py39/dgl-1.1.0/examples/pytorch/mvgrl/graph/main.py", line 70, in
dataset = load(args.dataname)
File "/usr/ports/math/py-dgl/work-py39/dgl-1.1.0/examples/pytorch/mvgrl/graph/dataset.py", line 156, in load
np.array(adj),
ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (188,) + inhomogeneous part.
```

## To Reproduce

```
examples/pytorch/mvgrl/graph && python3.9 main.py
```

## Environment

- DGL Version (e.g., 1.0): 1.1.0
- Backend Library & Version (e.g., PyTorch 0.4.1, MXNet/Gluon 1.3): PyTorch-2.0.0
- OS (e.g., Linux): FreeBSD 13.2
- How you installed DGL (`conda`, `pip`, source): FreeBSD port
- Build command you used (if compiling from source):
- Python version: 3.9
- CUDA/cuDNN version (if applicable):
- GPU models and configuration (e.g. V100):
- Any other relevant information:

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.