From 829fca611283710ff60e22aca3687dc3e36ebc9b Mon Sep 17 00:00:00 2001 From: David Nadlinger Date: Mon, 30 Jul 2018 11:08:56 +0100 Subject: [PATCH] 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. --- artiq/protocols/pyon.py | 1 + artiq/test/test_serialization.py | 2 ++ 2 files changed, 3 insertions(+) diff --git a/artiq/protocols/pyon.py b/artiq/protocols/pyon.py index 932e95996..cfdaa892e 100644 --- a/artiq/protocols/pyon.py +++ b/artiq/protocols/pyon.py @@ -194,6 +194,7 @@ _eval_dict = { "false": False, "true": True, "slice": slice, + "nan": numpy.nan, "Fraction": Fraction, "OrderedDict": OrderedDict, diff --git a/artiq/test/test_serialization.py b/artiq/test/test_serialization.py index e54234e00..803e42cde 100644 --- a/artiq/test/test_serialization.py +++ b/artiq/test/test_serialization.py @@ -26,6 +26,8 @@ class PYON(unittest.TestCase): with self.subTest(enc=enc): self.assertEqual(pyon.decode(enc(_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): orig = {k: (np.array(v), np.array([v]))