Skip to content

Commit

Permalink
more docs
Browse files Browse the repository at this point in the history
  • Loading branch information
IAlibay committed Sep 20, 2023
1 parent 1fb1e5c commit a4af422
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
4 changes: 4 additions & 0 deletions gufe/custom_codecs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
12 changes: 6 additions & 6 deletions gufe/tests/test_custom_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit a4af422

Please sign in to comment.