Skip to content

'DiGraph' object has no attribute 'leaves' #44

@JacobH140

Description

@JacobH140

I am trying to create a Clustering object as follows:

G = nx.DiGraph()
G.add_nodes_from(['A', 'B', 'C', 'D', 'E', 'F'])
G.add_edges_from([('E', 'A'), ('E', 'B'), ('F', 'C'), ('F', 'D')])

clu2elm_dict = {
    'A': [10, 11, 12, 13, 14],
    'B': [15, 16, 17, 18, 19],
    'C': [0, 1, 2, 3, 4],
    'D': [5, 6, 7, 8, 9]
}

clu = Clustering()
clu.from_digraph(hier_graph=G, clu2elm_dict=clu2elm_dict)

However, upon doing so I get error

File "/opt/miniconda3/envs/geodesicdcd/lib/python3.10/site-packages/clusim/clustering.py", line 660, in from_digraph
    self.hier_clusdict()
  File "/opt/miniconda3/envs/geodesicdcd/lib/python3.10/site-packages/clusim/clustering.py", line 678, in hier_clusdict
    self.hierclusdict[cluster] = self.downstream_elements(cluster)
  File "/opt/miniconda3/envs/geodesicdcd/lib/python3.10/site-packages/clusim/clustering.py", line 530, in downstream_elements
    if cluster in self.hier_graph.leaves():
AttributeError: 'DiGraph' object has no attribute 'leaves'

I think that one resolution is to just pass the nx.DiGraph() straight into the Clustering constructor, since then it will be turned into a DAG and thus have the required attributes once they are required. But I wonder if the from_digraph function should turn the input digraph into a DAG itself, or otherwise allow a DAG to be provided as input (i.e. change if not type(hier_graph) is nx.DiGraph to instead be if not isinstance(hier_graph, nx.DiGraph).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions