Cannot pickle graph

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

Cannot pickle graph

Helen Lampesis
Hi everyone,

The following code snippet gives me a TypeError and I am wondering if you have any suggestion.

------------------------------------------------
import graph_tool as gt
import pickle 

g = gt.Graph()
pickle.dump(g, open('test_file', 'w’))
------------------------------------------------

The error: TypeError: coercing to Unicode: need string or buffer, _io.BytesIO found

I am working on Yosemite OS with graph_tool 2.2.35 (installed via macports).


Thank you very much and happy new year!!
Helen



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

Re: Cannot pickle graph

Elliot

    graph.save('filename.xml')

On Dec 27, 2014 9:45 PM, "Helen Lampesis" <[hidden email]> wrote:
Hi everyone,

The following code snippet gives me a TypeError and I am wondering if you have any suggestion.

------------------------------------------------
import graph_tool as gt
import pickle 

g = gt.Graph()
pickle.dump(g, open('test_file', 'w’))
------------------------------------------------

The error: TypeError: coercing to Unicode: need string or buffer, _io.BytesIO found

I am working on Yosemite OS with graph_tool 2.2.35 (installed via macports).


Thank you very much and happy new year!!
Helen



_______________________________________________
graph-tool mailing list
[hidden email]
http://lists.skewed.de/mailman/listinfo/graph-tool


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

Re: Cannot pickle graph

Helen Lampesis
Hi,

Thanks fro the prompt reply. 

I might consider refactoring the code by using the graph.save function.

To that end, if I save a graph in an xml format, with older versions of graph_tool (e.g., 2.32.2) is it still guaranteed that all the property maps will be stored correctly with it?  With such an old version I cannot save it in the most new formats.

Thanks a lot!
Helen




On Dec 27, 2014, at 10:05 PM, ... <[hidden email]> wrote:

    graph.save('filename.xml')

On Dec 27, 2014 9:45 PM, "Helen Lampesis" <[hidden email]> wrote:
Hi everyone,

The following code snippet gives me a TypeError and I am wondering if you have any suggestion.

------------------------------------------------
import graph_tool as gt
import pickle 

g = gt.Graph()
pickle.dump(g, open('test_file', 'w’))
------------------------------------------------

The error: TypeError: coercing to Unicode: need string or buffer, _io.BytesIO found

I am working on Yosemite OS with graph_tool 2.2.35 (installed via macports).


Thank you very much and happy new year!!
Helen



_______________________________________________
graph-tool mailing list
[hidden email]
http://lists.skewed.de/mailman/listinfo/graph-tool

_______________________________________________
graph-tool mailing list
[hidden email]
http://lists.skewed.de/mailman/listinfo/graph-tool


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

Re: Cannot pickle graph

Elliot

I'm sure, but can't speak authoritatively.  xml is definately what you want to save it in.

On Dec 28, 2014 12:29 AM, "Helen Lampesis" <[hidden email]> wrote:
Hi,

Thanks fro the prompt reply. 

I might consider refactoring the code by using the graph.save function.

To that end, if I save a graph in an xml format, with older versions of graph_tool (e.g., 2.32.2) is it still guaranteed that all the property maps will be stored correctly with it?  With such an old version I cannot save it in the most new formats.

Thanks a lot!
Helen




On Dec 27, 2014, at 10:05 PM, ... <[hidden email]> wrote:

    graph.save('filename.xml')

On Dec 27, 2014 9:45 PM, "Helen Lampesis" <[hidden email]> wrote:
Hi everyone,

The following code snippet gives me a TypeError and I am wondering if you have any suggestion.

------------------------------------------------
import graph_tool as gt
import pickle 

g = gt.Graph()
pickle.dump(g, open('test_file', 'w’))
------------------------------------------------

The error: TypeError: coercing to Unicode: need string or buffer, _io.BytesIO found

I am working on Yosemite OS with graph_tool 2.2.35 (installed via macports).


Thank you very much and happy new year!!
Helen



_______________________________________________
graph-tool mailing list
[hidden email]
http://lists.skewed.de/mailman/listinfo/graph-tool

_______________________________________________
graph-tool mailing list
[hidden email]
http://lists.skewed.de/mailman/listinfo/graph-tool


_______________________________________________
graph-tool mailing list
[hidden email]
http://lists.skewed.de/mailman/listinfo/graph-tool


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

Re: Cannot pickle graph

Tiago Peixoto
Administrator
In reply to this post by Helen Lampesis
On 28.12.2014 04:44, Helen Lampesis wrote:

> Hi everyone,
>
> The following code snippet gives me a TypeError and I am wondering if you have any suggestion.
>
> ------------------------------------------------
> import graph_tool as gt
> import pickle
>
> g = gt.Graph()
> pickle.dump(g, open('test_file', 'w’))
> ------------------------------------------------
>
> The error: TypeError: coercing to Unicode: need string or buffer,
> _io.BytesIO found
This is a bug in graph-tool when used with Python 2 (Python 3 is fine).
It has already been fixed in git a while ago.

Best,
Tiago

--
Tiago de Paula Peixoto <[hidden email]>


_______________________________________________
graph-tool mailing list
[hidden email]
http://lists.skewed.de/mailman/listinfo/graph-tool

signature.asc (836 bytes) Download Attachment
--
Tiago de Paula Peixoto <tiago@skewed.de>
Reply | Threaded
Open this post in threaded view
|

Re: Cannot pickle graph

Tiago Peixoto
Administrator
In reply to this post by Helen Lampesis
On 28.12.2014 07:27, Helen Lampesis wrote:

> Hi,
>
> Thanks fro the prompt reply.
>
> I might consider refactoring the code by using the graph.save function.
>
> To that end, if I save a graph in an xml format, with older versions
> of graph_tool (e.g., 2.32.2) is it still guaranteed that all the
> property maps will be stored correctly with it?  With such an old
> version I cannot save it in the most new formats.
Yes, the graphml format is backwards compatible across all versions,

Best,
Tiago

--
Tiago de Paula Peixoto <[hidden email]>


_______________________________________________
graph-tool mailing list
[hidden email]
http://lists.skewed.de/mailman/listinfo/graph-tool

signature.asc (836 bytes) Download Attachment
--
Tiago de Paula Peixoto <tiago@skewed.de>
Reply | Threaded
Open this post in threaded view
|

Re: Cannot pickle graph

Tiago Peixoto
Administrator
In reply to this post by Elliot
On 28.12.2014 21:49, ... wrote:
> I'm sure, but can't speak authoritatively.  xml is definately what you
> want to save it in.

This is true if you want backwards compatibility.

But if you care only about forwards compatibility, you should also
consider the 'gt' binary format, which is much faster than 'xml', and
supports all property maps as well.

Best,
Tiago

--
Tiago de Paula Peixoto <[hidden email]>


_______________________________________________
graph-tool mailing list
[hidden email]
http://lists.skewed.de/mailman/listinfo/graph-tool

signature.asc (836 bytes) Download Attachment
--
Tiago de Paula Peixoto <tiago@skewed.de>