[issue18303] json.dumps() claims numpy.ndarray and numpy.bool_ are not serializable

2013-06-25 Thread Ethan Furman

Ethan Furman added the comment:

For the curious, here are all the tracebacks:

--> json.dumps(a)
Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/lib/python3.3/json/__init__.py", line 236, in dumps
return _default_encoder.encode(obj)
  File "/usr/lib/python3.3/json/encoder.py", line 191, in encode
chunks = self.iterencode(o, _one_shot=True)
  File "/usr/lib/python3.3/json/encoder.py", line 249, in iterencode
return _iterencode(o, 0)
  File "/usr/lib/python3.3/json/encoder.py", line 173, in default
raise TypeError(repr(o) + " is not JSON serializable")
TypeError: array([ True,  True,  True,  True, False, False], dtype=bool) is not 
JSON serializable


--> json.dumps(a[0])
Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/lib/python3.3/json/__init__.py", line 236, in dumps
return _default_encoder.encode(obj)
  File "/usr/lib/python3.3/json/encoder.py", line 191, in encode
chunks = self.iterencode(o, _one_shot=True)
  File "/usr/lib/python3.3/json/encoder.py", line 249, in iterencode
return _iterencode(o, 0)
  File "/usr/lib/python3.3/json/encoder.py", line 173, in default
raise TypeError(repr(o) + " is not JSON serializable")
TypeError: True is not JSON serializable

While the repr says 'True', the type is .


and the success:

--> json.dumps(a.tolist()) #this works!
'[true, true, true, true, false, false]'


Summary
===

No bug here, defined behavior.  Raising the issue with NumPy won't help as this 
is not a bug... although perhaps they have a json handler already written 
somewhere?  At any rate, yes, said handler would have to be specified as the 
'default' parameter.

--
resolution:  -> invalid
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18303] json.dumps() claims numpy.ndarray and numpy.bool_ are not serializable

2013-06-25 Thread Ethan Furman

Changes by Ethan Furman :


--
nosy: +ethan.furman

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18303] json.dumps() claims numpy.ndarray and numpy.bool_ are not serializable

2013-06-25 Thread miscjunk

miscjunk added the comment:

Thanks for the explanation. I suppose this should be posted to the numpy 
tracker then? Would it be possible for numpy to 'just work' with the json 
module? Or will the final resolution be to use a handler (the default= 
parameter in json.loads) ?

Thanks

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18303] json.dumps() claims numpy.ndarray and numpy.bool_ are not serializable

2013-06-25 Thread R. David Murray

R. David Murray added the comment:

I would (naively) not expect either of these to be serializable.  They are not 
base data types, which is all the json module handles unless you add extra 
handlers yourself.

'crash' means interpreter crash (segfault), by the way.

--
nosy: +r.david.murray
type: crash -> behavior

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18303] json.dumps() claims numpy.ndarray and numpy.bool_ are not serializable

2013-06-25 Thread miscjunk

miscjunk added the comment:

numpy.ndarray is also not serializable by json.dumps()

import numpy as np
import json

a = np.array([1,2,3,4])
json.dumps(a) #crash
json.dumps(a[0]) #this works!

--
title: json.dumps() claims numpy.bool_ is not serializable -> json.dumps() 
claims numpy.ndarray and numpy.bool_ are not serializable

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com