empty `Graph` evaluates to True
Bug reports:
Please follow the general troubleshooting steps first:
-
Are you running the latest graph-tool
version? -- Nearly -
Do you observe the problem with the current git version? -- Presumably -
Are you using Macports or Homebrew? If yes, please submit an issue there instead: https://github.com/Homebrew/brew/issues and https://trac.macports.org/newticket -- No -
Did you compile graph-tool
manually? -- No -
If you answered yes above, did you use the exact same compiler to build graph-tool
,boost-python
andPython
?
Please replace this section with a brief summary of your issue.
Do not forget to supply the following information:
-
A minimal and self-contained example that shows the problem. -
Your operating system. -
The Python version you are using.
graph-tool version 2.44, python 3.9.12, Ubuntu 18.04
In graph-tool, an empty Graph
instance evaluates to True:
from graph_tool import Graph
bool(Graph())
# True
This is in contrast to python convention:
bool(list())
# False
bool(tuple())
# False
bool(dict())
# False
Notably, other network analysis libraries adhere to this convention:
from networkx import Graph
bool(Graph())
# False
from igraph import Graph
bool(Graph())
# False
I am the author of netgraph, a graph drawing library that supports various network analysis libraries, and it would make my life easier if I didn't have to check if the data object is a graph-tool Graph
each time I defend against empty graphs.