first test fails

24 views
Skip to first unread message

nbecker

unread,
Feb 9, 2010, 7:10:54 AM2/9/10
to jsonpickle
In [1]: import jsonpickle

In [2]: import numpy as np

In [3]: u = np.arange (10)

In [5]: pickled = jsonpickle.encode (u)

In [6]: pickled
Out[6]: 'null'

David Aguilar

unread,
Feb 9, 2010, 11:39:39 AM2/9/10
to jsonp...@googlegroups.com, jsonpickle
On Feb 9, 2010, at 4:10 AM, nbecker <ndbe...@gmail.com> wrote:

> In [1]: import jsonpickle
>
> In [2]: import numpy as np

Numpy uses C extensions.
The best bet is to register a custom handler for u[0].__class__.

If you write one then it would be a good example to have in the source
tree, so do share.

There should be a testcase that demonstrates how to do this.

Have fun,

--
David

>
> In [3]: u = np.arange (10)
>
> In [5]: pickled = jsonpickle.encode (u)
>
> In [6]: pickled
> Out[6]: 'null'
>

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

David Aguilar

unread,
Feb 9, 2010, 12:36:17 PM2/9/10
to nbecker, jsonp...@googlegroups.com
On Tue, Feb 09, 2010 at 04:10:54AM -0800, nbecker wrote:
> In [1]: import jsonpickle
>
> In [2]: import numpy as np
>
> In [3]: u = np.arange (10)

Oops, I originally said u[0].__class__.

It's u that's not encoding correctly, so the handler should be
registered for u.__class__ instead, namely
<type 'numpy.ndarray'>.

See ExternalHandlerTestCase and its use of UnicodeMixin and
UnicodeMixinHandler in jsonpickle_test.py for an example of
how to do this.


> In [5]: pickled = jsonpickle.encode (u)
>
> In [6]: pickled
> Out[6]: 'null'
>

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

--
David

Reply all
Reply to author
Forward
0 new messages