From a4af42247cff6e1c6e90b62435c2c5ebd4e61a83 Mon Sep 17 00:00:00 2001 From: IAlibay Date: Wed, 20 Sep 2023 08:33:43 +0100 Subject: [PATCH] more docs --- gufe/custom_codecs.py | 4 ++++ gufe/tests/test_custom_json.py | 12 ++++++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/gufe/custom_codecs.py b/gufe/custom_codecs.py index dd09a043..f334e266 100644 --- a/gufe/custom_codecs.py +++ b/gufe/custom_codecs.py @@ -73,6 +73,10 @@ def is_openff_quantity_dict(dct): ) +# Note that this has inconsistent behaviour for some generic types +# which end up being handled by the default JSON encoder/decoder. +# The main example of this is np.float64 which will be turned into +# a float type on serialization. NPY_DTYPE_CODEC = JSONCodec( cls=np.generic, to_dict=lambda obj: { diff --git a/gufe/tests/test_custom_json.py b/gufe/tests/test_custom_json.py index f82a54c3..8222e51a 100644 --- a/gufe/tests/test_custom_json.py +++ b/gufe/tests/test_custom_json.py @@ -45,10 +45,10 @@ def test_add_existing_codec(self): assert len(serialization.codecs) == 1 -@pytest.mark.parametrize('obj', - [np.array([[1.0, 0.0], [2.0, 3.2]]), - np.float32(1.1)], -) +@pytest.mark.parametrize('obj', [ + np.array([[1.0, 0.0], [2.0, 3.2]]), + np.float32(1.1) +]) @pytest.mark.parametrize('codecs', [ [BYTES_CODEC, NUMPY_CODEC, NPY_DTYPE_CODEC], [NPY_DTYPE_CODEC, BYTES_CODEC, NUMPY_CODEC], @@ -105,7 +105,7 @@ class TestNumpyCoding(CustomJSONCodingTest): def setup_method(self): self.codec = NUMPY_CODEC self.objs = [np.array([[1.0, 0.0], [2.0, 3.2]]), np.array([1, 0]), - np.array([1.0, 2.0, 3.0], dtype=np.float32),] + np.array([1.0, 2.0, 3.0], dtype=np.float32)] shapes = [[2, 2], [2,], [3,]] dtypes = [str(arr.dtype) for arr in self.objs] # may change by system? byte_reps = [arr.tobytes() for arr in self.objs] @@ -146,7 +146,7 @@ def setup_method(self): # object). self.objs = [np.bool_(True), np.float16(1.0), np.float32(1.0), np.complex128(1.0), - np.clongdouble(1.0), np.uint64(1),] + np.clongdouble(1.0), np.uint64(1)] dtypes = [str(a.dtype) for a in self.objs] byte_reps = [a.tobytes() for a in self.objs] # Overly complicated extraction of the class name