dmlc / dmlc/dgl

combine_frames doesn't allow for no edges

Open
#7,826 0 comments 0 reactions 0 assignees View on GitHub
bug:confirmed
Dominant language
Python
Stars
14.3k
Forks
3.1k
PR merge metrics
No merged PRs in 30d

Description

## 🐛 Bug

## To Reproduce

This is a niche corner case, but hopefully one with an easy-ish solution. If I create a DGL heterograph with no edges, trying to convert it with `to_homogeneous` raises an error from having no edges.

```
import dgl

heterograph = dgl.heterograph(
{("node", "forward", "node"): ([], []), ("node", "reverse", "node"): ([], [])},
num_nodes_dict={"node": 1}
)
dgl.to_homogeneous(heterograph)
```

raises the error:
```
TypeError Traceback (most recent call last)
Cell In[24], line 1
----> 1 dgl.to_homogeneous(heterograph)

File dgl/convert.py:1026, in to_homogeneous(G, ndata, edata, store_type, return_count)
1022 edata = []
1023 comb_nf = combine_frames(
1024 G._node_frames, range(len(G.ntypes)), col_names=ndata
1025 )
-> 1026 comb_ef = combine_frames(
1027 G._edge_frames, range(len(G.etypes)), col_names=edata
1028 )
1029 if comb_nf is not None:
1030 retg.ndata.update(comb_nf)

File dgl/heterograph.py:6579, in combine_frames(frames, ids, col_names)
6576 else:
6577 del schemes[key]
-> 6579 if len(schemes) == 0:
6580 return None
6582 # concatenate the columns

TypeError: object of type 'NoneType' has no len()
```

## Expected behavior

I was hoping DGL would simply be able to batch this through with all the other normal graphs. I think the error is due to this initial definition of `schemes` as None, and then skipping over each frame as they have 0 rows.

https://github.com/dmlc/dgl/blob/d92c98d927d6ef0c0bcb7475194495f6f417e091/python/dgl/heterograph.py#L6581

Would it be possible to incorporate a check for None for `schemes`?

## Environment

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

## Additional context

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.