TypeError while using add_edge_list

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

TypeError while using add_edge_list

ashutosh
Hi,

I'm trying to convert two columns of my pandas dataframe into network using
them as edge list.
A  similar query
<https://stackoverflow.com/questions/35459597/graph-tool-reading-edge-lists-from-pandas-dataframe>  
was posted in StackOverflow but with different problem and it didn't help
me.

When I am trying the following code it gives me error:
*
myGraph.add_edge_list(i for i in df[['node1','node2']].values.tolist())*

Where, my Graph is the graph;  df is the dataframe with 4 columns out of
which I am using two 'node1' and 'node2'.

*File "/usr/lib/python3/dist-packages/graph_tool/__init__.py", line 2109, in
add_edge_list
    libcore.add_edge_list_iter(self.__graph, edge_list, eprops)*

*TypeError: No registered converter was able to produce a C++ rvalue of type
unsigned long from this Python object of type str
*


I tried upgrading my boost library but it doesn't solve the problem. Any
suggestions ?



--
Sent from: http://main-discussion-list-for-the-graph-tool-project.982480.n3.nabble.com/
_______________________________________________
graph-tool mailing list
[hidden email]
https://lists.skewed.de/mailman/listinfo/graph-tool
Reply | Threaded
Open this post in threaded view
|

Re: TypeError while using add_edge_list

Tiago Peixoto
Administrator
Am 18.07.2018 um 08:37 schrieb ashutosh:
>
> I tried upgrading my boost library but it doesn't solve the problem. Any
> suggestions ?

Without a minimal and self-contained example that shows the problem, it's
difficult to say anything.

Please provide a small example that we can run, so we can understand what
the problem may be.

--
Tiago de Paula Peixoto <[hidden email]>
_______________________________________________
graph-tool mailing list
[hidden email]
https://lists.skewed.de/mailman/listinfo/graph-tool
--
Tiago de Paula Peixoto <tiago@skewed.de>
Reply | Threaded
Open this post in threaded view
|

Re: TypeError while using add_edge_list

Alexandre Hannud Abdo
In reply to this post by ashutosh
Ni! Hi ashu,

Please, always try to *read errors carefully* and consult the documentation. Not to mention, provide self-contained examples.

Python is throwing a "TypeError" and telling you it expects an integer ('unsigned long', the C++ type for vertex indices) while you are passing it a string ('str').

As you can see in the documentation, if you want to pass strings to add_edge_list you should set two additional arguments: `hash=True` and `string_vals=True`.

If that doesn't fix it, you'll have to provide a self-contained example where the error occurs, otherwise we can't really help.

.~´



On Wed, Jul 18, 2018 at 9:37 AM, ashutosh <[hidden email]> wrote:
Hi,

I'm trying to convert two columns of my pandas dataframe into network using
them as edge list.
A  similar query
<https://stackoverflow.com/questions/35459597/graph-tool-reading-edge-lists-from-pandas-dataframe
was posted in StackOverflow but with different problem and it didn't help
me.

When I am trying the following code it gives me error:
*
myGraph.add_edge_list(i for i in df[['node1','node2']].values.tolist())*

Where, my Graph is the graph;  df is the dataframe with 4 columns out of
which I am using two 'node1' and 'node2'.

*File "/usr/lib/python3/dist-packages/graph_tool/__init__.py", line 2109, in
add_edge_list
    libcore.add_edge_list_iter(self.__graph, edge_list, eprops)*

*TypeError: No registered converter was able to produce a C++ rvalue of type
unsigned long from this Python object of type str
*


I tried upgrading my boost library but it doesn't solve the problem. Any
suggestions ?



--
Sent from: http://main-discussion-list-for-the-graph-tool-project.982480.n3.nabble.com/
_______________________________________________
graph-tool mailing list
[hidden email]
https://lists.skewed.de/mailman/listinfo/graph-tool


_______________________________________________
graph-tool mailing list
[hidden email]
https://lists.skewed.de/mailman/listinfo/graph-tool
Reply | Threaded
Open this post in threaded view
|

Re: TypeError while using add_edge_list

Alexandre Hannud Abdo
Tiny typo, the first argument is `hashed=True`.

On Wed, Jul 18, 2018 at 1:18 PM, Alexandre Hannud Abdo <[hidden email]> wrote:
Ni! Hi ashu,

Please, always try to *read errors carefully* and consult the documentation. Not to mention, provide self-contained examples.

Python is throwing a "TypeError" and telling you it expects an integer ('unsigned long', the C++ type for vertex indices) while you are passing it a string ('str').

As you can see in the documentation, if you want to pass strings to add_edge_list you should set two additional arguments: `hash=True` and `string_vals=True`.

If that doesn't fix it, you'll have to provide a self-contained example where the error occurs, otherwise we can't really help.

.~´



On Wed, Jul 18, 2018 at 9:37 AM, ashutosh <[hidden email]> wrote:
Hi,

I'm trying to convert two columns of my pandas dataframe into network using
them as edge list.
A  similar query
<https://stackoverflow.com/questions/35459597/graph-tool-reading-edge-lists-from-pandas-dataframe
was posted in StackOverflow but with different problem and it didn't help
me.

When I am trying the following code it gives me error:
*
myGraph.add_edge_list(i for i in df[['node1','node2']].values.tolist())*

Where, my Graph is the graph;  df is the dataframe with 4 columns out of
which I am using two 'node1' and 'node2'.

*File "/usr/lib/python3/dist-packages/graph_tool/__init__.py", line 2109, in
add_edge_list
    libcore.add_edge_list_iter(self.__graph, edge_list, eprops)*

*TypeError: No registered converter was able to produce a C++ rvalue of type
unsigned long from this Python object of type str
*


I tried upgrading my boost library but it doesn't solve the problem. Any
suggestions ?



--
Sent from: http://main-discussion-list-for-the-graph-tool-project.982480.n3.nabble.com/
_______________________________________________
graph-tool mailing list
[hidden email]
https://lists.skewed.de/mailman/listinfo/graph-tool



_______________________________________________
graph-tool mailing list
[hidden email]
https://lists.skewed.de/mailman/listinfo/graph-tool
Reply | Threaded
Open this post in threaded view
|

Re: TypeError while using add_edge_list

ashutosh
In reply to this post by Tiago Peixoto
sampleFile.tab
<http://main-discussion-list-for-the-graph-tool-project.982480.n3.nabble.com/file/t496073/sampleFile.tab>  

above is the sample file.

and below is the code that produces the error as i mentioned before

import pandas as pd
import graph_tool.all as gtx
df = pd.read_csv("file_path",sep='\t',headers=True)

myGraph = gtx.Graph()

myGraph.add_edge_list(df.values.tolist())



--
Sent from: http://main-discussion-list-for-the-graph-tool-project.982480.n3.nabble.com/
_______________________________________________
graph-tool mailing list
[hidden email]
https://lists.skewed.de/mailman/listinfo/graph-tool
Reply | Threaded
Open this post in threaded view
|

Re: TypeError while using add_edge_list

ashutosh
In reply to this post by Alexandre Hannud Abdo
I got the problem.

Graph Tool by default accepts only vertex objects or int(index) values on
edge list and hence either I pass on vertex object list or keep the options*
hashed=True and string_vals=True* in the add_edge_list option.

The problem is resolved now. Thank you



--
Sent from: http://main-discussion-list-for-the-graph-tool-project.982480.n3.nabble.com/
_______________________________________________
graph-tool mailing list
[hidden email]
https://lists.skewed.de/mailman/listinfo/graph-tool