Error when trying to modify a Sframe of graph vertices

User 1616 | 3/23/2015, 5:46:05 PM

Hi everyone:

So I have a graph and I want to update one of Sframe columns of its vertices with the following formula graph.vertices['movie_desc'] = graph.vertices.apply(lambda vert: numpy.array(vert['moviedesc']) if labelmap[vert['__id']]==1 else numpy.zeros(nummovieclasses))

The goal is to keep the column movie_desc untouched when the property is verified, and set it to 0 otherwise

when I compute each side of the equality independently, it works, they have the same number of rows and they seem to be the same type, but when I compute the equality I get the following error message, which also shows when I compute the right side of the equality and then try to add it as column with add_column under another name:

<b class="Bold"> Traceback (most recent call last):

File "<ipython-input-49-b7de5c02616b>", line 1, in <module> graph.vertices['movie_desc'] = graph.vertices.apply(lambda vert: numpy.array(vert['moviedesc']) if labelmap[vert['__id']]==1 else numpy.zeros(nummovieclasses))

File "/home/student/graphlab/lib/python2.7/site-packages/graphlab/data_structures/gframe.py", line 224, in setitem super(GFrame, self).setitem(key, value)

File "/home/student/graphlab/lib/python2.7/site-packages/graphlab/datastructures/sframe.py", line 3233, in setitem self.addcolumn(sa_value, tmpname)

File "/home/student/graphlab/lib/python2.7/site-packages/graphlab/datastructures/gframe.py", line 96, in addcolumn self.graph.proxy = graph_proxy

File "/home/student/graphlab/lib/python2.7/site-packages/graphlab/cython/context.py", line 39, in exit raise exctype(excvalue)

RuntimeError: Runtime Exception. Runtime Exception. Traceback (most recent call last): File "<ipython-input-49-b7de5c02616b>", line 1, in <lambda> KeyError: 3945L</b>

In can not figure what the problem is.

Thank you in advance for your help

Comments

User 1190 | 3/23/2015, 7:55:18 PM

Hi @Lien,

The error suggest that the dict "label_map" does not have key "3945L".

The reason evaluating each side separately works is because of the "lazy evaluation", the new column is not fully materialized, so the "key error" does not happen until later in the column.

If my hypothesis is correct, you should see the same error for the following code:

<pre><code> x = graph.vertices['moviedesc'].apply(lambda x: 1 if labelmap[x] == 1 else 0) x.materialize() </code></pre>

Thanks, -jay


User 1616 | 3/23/2015, 9:29:59 PM

Indeed, the problem was that my code was trying to evaluate the labelmap in a index out of bounds. I fixed my labelmap and now it works just fine.

Thank you Jay.