gephi-plugins icon indicating copy to clipboard operation
gephi-plugins copied to clipboard

iterating through g.nodes returns None eventually

Open claudiomartella opened this issue 12 years ago • 10 comments

(console script plugin)

I'm iterating over g.nodes and changing the color of a node according to its position

f = #scaling factor from X,Y range to RGB range for v in g.nodes: color_node(v)

def color_node(v): x, y = v.position r = int(x_f) b = int(y_f) v.color = Color(r, 0 ,b)

it works for a few nodes until it throws an exception as NoneType has not position attribute. I don't see why it should eventually reach a None object. Data Table shows no empty rows, same iteration with only print(v) also doesn't fail. could be some concurrency related stuff.

claudiomartella avatar Sep 25 '12 18:09 claudiomartella

This is weird. I tried reproducing your bug with a few graphs here and couldn't reproduce. Can you give more details or perhaps share a gephi file with me so I can reproduce your bug? Thanks!

luizribeiro avatar Nov 04 '12 09:11 luizribeiro

Here's a graph: https://gist.github.com/4028111

>>> g.nodes
set([None])
>>> g.edges
set([e7186, e5613, e4621, e5529, e6463, ....., ]) 
>>> e = g.edges.pop()
>>> e
e2559
>>> e.source
Traceback (most recent call last):
File "<input>", line 1, in <module>
AttributeError: 'org.gephi.scripting.wrappers.GyEdge' object has no attribute 'source'   
>>> e.target
Traceback (most recent call last):
File "<input>", line 1, in <module>
AttributeError: 'org.gephi.scripting.wrappers.GyEdge' object has no attribute 'target'

gka avatar Nov 06 '12 22:11 gka

Have you solved this problem? I encountered the same problem. Able to access g.edges not g.nodes. I guess that the edges' id in gephi are numbers, but nodes are not numbers. Maybe this is the problem.

prohorry avatar Jan 05 '13 04:01 prohorry

I can reproduce this problem by loading the following file in 0.8.2 on Mac (File->Open->min-alpha.csv):

min-alpha.csv

a;b
b;c
c;a
>>> g.nodes
set([None])
>>> g.edges
set([e186, e187, e185])

while numeric graph works:

min-num.csv

1;2
2;3
3;1
>>> g.nodes
set([v3, v1, v2])
>>> g.edges
set([e190, e189, e188])

Both graphs can be manipulated in the Gephi GUI and visualized.

petricek avatar Mar 08 '13 21:03 petricek

Hey guys, sorry for not being very responsive. I think @prohorry might be right. I'll try to investigate this during this weekend and will keep you updated.

luizribeiro avatar Mar 08 '13 21:03 luizribeiro

I have the same problem (Product Version: Gephi 0.8.2 201210100934 Java: 1.7.0_17; Java HotSpot(TM) 64-Bit Server VM 23.7-b01 System: Linux version 3.5.0-26-generic running on amd64;).

This can be easily reproduced, steps:

  1. File/Generate/Random graph- verify that g.nodes displays properly
  2. File/Export/Graph File, as csv
  3. File/Close project
  4. File/Open - reload the csv you've just exported - g.nodes comes up as set([None])

feczo avatar Mar 22 '13 01:03 feczo

another note, I create 3 nodes in the data laboratory

g.nodes set([v1906, v1905, v1907])

than import a spreadsheet of 600 nodes I get

g.nodes set([v1906, v1905, v1907, None])

UPDATE: I think the problem is with non-numeric node IDs in this case I've managed to import the nodes in a way to show up in the g.nodes set by putting their names into the label column and generating automatic numeric ids during the import

feczo avatar Mar 22 '13 01:03 feczo

yet another problem that looks like id 0 is not understood either

I have seven nodes running with ids from 0 to 6, here is what I get on the console

Jython Completion Shell Jython 2.5.2 (Release_2_5_2:Unversioned directory, Jan 5 2012, 12:11:16) [Java HotSpot(TM) 64-Bit Server VM (Oracle Corporation)] on java1.7.0_17

g <org.gephi.scripting.wrappers.GyGraph object at 0x5> g.nodes set([v4, None, v5, v1, v6, v3, v2])

feczo avatar Mar 25 '13 03:03 feczo

I have imported a list of edges from CSV. I have chose to create missing nodes. Jython does not find any nodes there.

g.edges works fine
g.nodes  prints " set([None])"

A clue: I am able to iterate edges and print their weights, but I was not able to retrieve .source or .target of an edge:

  Traceback (most recent call last):
   File "<input>", line 2, in <module>
 AttributeError: 'org.gephi.scripting.wrappers.GyEdge' object has no attribute 'source'

aidiss avatar Mar 18 '14 17:03 aidiss

This bug appears to be caused by lines 291 and 301 of ScriptingAPI/src/org/gephi/scripting/util/GyNamespace.java . As you can see, GyEdges and GyNodes don't get constructed unless they match this regex after the respective es and vs are popped off:

if (Pattern.compile("[1-9][0-9]*").matcher(strId).matches())

I imagine this is meant to keep nodes from becoming invalid identifiers. That said, a more permissive regex could be used.

darkniobe avatar Oct 06 '14 19:10 darkniobe