Yaml-4.1 failed to serialize or deserialize numpy objects.
See original GitHub issue>>> import numpy as np
>>> yaml.dump(np.random.random((100,100)))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/lf2507/.local/lib/python2.7/site-packages/yaml/__init__.py", line 219, in dump
return dump_all([data], stream, Dumper=Dumper, **kwds)
File "/home/lf2507/.local/lib/python2.7/site-packages/yaml/__init__.py", line 198, in dump_all
dumper.represent(data)
File "/home/lf2507/.local/lib/python2.7/site-packages/yaml/representer.py", line 28, in represent
node = self.represent_data(data)
File "/home/lf2507/.local/lib/python2.7/site-packages/yaml/representer.py", line 67, in represent_data
node = self.yaml_representers[None](self, data)
File "/home/lf2507/.local/lib/python2.7/site-packages/yaml/representer.py", line 249, in represent_undefined
raise RepresenterError("cannot represent an object", data)
yaml.representer.RepresenterError: ('cannot represent an object', array([[0.78867287, 0.1145689 , 0.73455115, ..., 0.03162476, 0.06458778,
0.02051163],
[0.0648247 , 0.44383162, 0.80787024, ..., 0.07586477, 0.47848779,
0.05648012],
[0.84362173, 0.31730949, 0.99826481, ..., 0.8951278 , 0.87577464,
0.64970616],
...,
[0.98758733, 0.26062501, 0.68675972, ..., 0.82339569, 0.59255629,
0.24641607],
[0.11395974, 0.41112024, 0.64924667, ..., 0.33038519, 0.8491808 ,
0.87419596],
[0.44593807, 0.15025162, 0.16101452, ..., 0.25134148, 0.30600472,
0.38231974]]))
>>>
Issue Analytics
- State:
- Created 5 years ago
- Comments:8 (5 by maintainers)
Top Results From Across the Web
python serialize and deserialize numpy array inside an object
I would like to take a Python object and serialize/deserialize to/from JSON. The object has numpy arrays inside it:
Read more >Serialization — Ray 2.2.0 - the Ray documentation
Because Ray puts numpy arrays in the object store, when deserialized as arguments ... Lock() # could not be serialized! ray.get(ray.put(A(1))) # fail!...
Read more >BinaryFormatter Class (System.Runtime.Serialization ...
Serializes and deserializes an object, or an entire graph of connected objects, in binary format.
Read more >Deserialize JSON to Object in Python - GeeksforGeeks
Let us see how to deserialize a JSON document into a Python object. Deserialization is the process of decoding the data that is...
Read more >numpy.fromstring — NumPy v1.24 Manual
A new 1-D array initialized from text data in a string. Parameters: ... Reference object to allow the creation of arrays which are...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This is a deliberately change. Previously PyYAML’s default for serialization/deserialization was to use a dangerous subset of yaml that allowed handling arbitrary python objects - meaning that deserialization of untrusted input could lead to arbitrary code execution.
As a result, PyYAML 4 is now safe by default. Those wanting the previous behavior can use
yaml.danger_load
andyaml.danger_dump
.Loading an object using
yaml.load()
inpyyaml < 4
was dangerous, yes. Now the naming reflects this.On Tue, Jun 26, 2018 at 8:12 PM LFu notifications@github.com wrote:
– “I disapprove of what you say, but I will defend to the death your right to say it.” – Evelyn Beatrice Hall (summarizing Voltaire) “The people’s good is the highest law.” – Cicero GPG Key fingerprint: D1B3 ADC0 E023 8CA6