Attribute Error while using networkx.connected_component_subgraphs()

852 views
Skip to first unread message

Manisha

unread,
Aug 13, 2012, 11:37:35 AM8/13/12
to networkx-discuss
Hello friends,

Its been quite a time that I am using networkx, but for the first
time I am facing a strange problem and am unable to figure out what's
causing the error.

I have created some graphs and saved them as <filename>.gpickle files
using networkx.write_gpickle(<filename>).
I retrieved these graphs in another of my python programs using
networkx.read_gpickle(<filename>,<format type>). Then I try to get the
properties of these graphs using different in-built functions of
networkx. My codes and error are given below:

>>> import networkx as nx
>>> G=nx.read_gpickle('some_path/example_graph.gpickle')
>>> G.number_of_nodes()
14
>>> G.number_of_edges()
14
>>> nx.number_connected_components(G)
1
>>> len(nx.connected_component_subgraphs(G))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/site-packages/networkx-1.3-py2.7.egg/
networkx/algorithms/components/connected.py", line 157, in
connected_component_subgraphs
graph_list.append(G.subgraph(c))
File "/usr/local/lib/python2.7/site-packages/networkx-1.3-py2.7.egg/
networkx/classes/graph.py", line 1474, in subgraph
H.name = "Subgraph of (%s)"%(self.name)
AttributeError: 'Graph' object has no attribute 'name'


As to my knowledge, if we do not provide a graph name, networkx uses a
default name to avoid this error. I have used exacly the same codes
many times before on many other saved graphs but never gave such an
error. I am totally lost. Can anyone help me please????
Python I am using is 2.7 and networkx version is 1.3. and I am working
on a Rehat (Fedora) linux OS.


Dan Schult

unread,
Aug 14, 2012, 11:53:14 AM8/14/12
to networkx...@googlegroups.com
It looks like the "name" attribute is not working when you read the gpickle file.
When I write and then read a gpickle file with these routines, the name attribute
works fine. But your version of networkx is pretty old (current is v1.7). You
could try updating. You could also focus just on the "name" attribute and check
writing and reading gpickles for small test graphs.

Dan
> --
> You received this message because you are subscribed to the Google Groups "networkx-discuss" group.
> To post to this group, send email to networkx...@googlegroups.com.
> To unsubscribe from this group, send email to networkx-discu...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/networkx-discuss?hl=en.
>

Manisha

unread,
Aug 17, 2012, 6:16:54 AM8/17/12
to networkx-discuss
Hi Dan,

Thanks for the reply. I did an upgrade of version and works fine
now :)
Thanks again

Manisha
Reply all
Reply to author
Forward
0 new messages