pyon: Correctly deserialize bare NaNs

This also fixes (non-numpy) lists containing NaNs.

Previously, accidentally storing a NaN in a dataset would
bring down large parts of the system.
This commit is contained in:
David Nadlinger 2018-07-30 11:08:56 +01:00
parent 08ee91beb2
commit 829fca6112
2 changed files with 3 additions and 0 deletions

View File

@ -194,6 +194,7 @@ _eval_dict = {
"false": False, "false": False,
"true": True, "true": True,
"slice": slice, "slice": slice,
"nan": numpy.nan,
"Fraction": Fraction, "Fraction": Fraction,
"OrderedDict": OrderedDict, "OrderedDict": OrderedDict,

View File

@ -26,6 +26,8 @@ class PYON(unittest.TestCase):
with self.subTest(enc=enc): with self.subTest(enc=enc):
self.assertEqual(pyon.decode(enc(_pyon_test_object)), self.assertEqual(pyon.decode(enc(_pyon_test_object)),
_pyon_test_object) _pyon_test_object)
# NaNs don't compare equal, so test separately.
assert np.isnan(pyon.decode(enc(np.nan)))
def test_encdec_array(self): def test_encdec_array(self):
orig = {k: (np.array(v), np.array([v])) orig = {k: (np.array(v), np.array([v]))