Message191895
For the curious, here are all the tracebacks:
--> json.dumps(a)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
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 "<stdin>", line 1, in <module>
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 <class 'numpy.bool_'>.
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. |
|
Date |
User |
Action |
Args |
2013-06-26 06:09:58 | ethan.furman | set | recipients:
+ ethan.furman, r.david.murray, miscjunk |
2013-06-26 06:09:58 | ethan.furman | set | messageid: <1372226998.35.0.570802795479.issue18303@psf.upfronthosting.co.za> |
2013-06-26 06:09:58 | ethan.furman | link | issue18303 messages |
2013-06-26 06:09:58 | ethan.furman | create | |
|