diff --git a/CHANGES.rst b/CHANGES.rst index 62efb8c4a..a3e913ec0 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -3,6 +3,9 @@ - Fix ``numpy.ma.MaskedArray`` saving for numpy 2.x [#1769] +- Add ``float16`` support [#1692] + + 3.1.0 (2024-02-27) ------------------ @@ -52,6 +55,7 @@ The ASDF Standard is at v1.6.0 - Deprecate ``AsdfFile.version_map`` [#1745] + 3.0.1 (2023-10-30) ------------------ diff --git a/asdf/_tests/tags/core/tests/test_ndarray.py b/asdf/_tests/tags/core/tests/test_ndarray.py index bab255ba3..339567e8d 100644 --- a/asdf/_tests/tags/core/tests/test_ndarray.py +++ b/asdf/_tests/tags/core/tests/test_ndarray.py @@ -117,9 +117,9 @@ def with_custom_extension(): @contextlib.contextmanager -def roundtrip(af, raw=False): +def roundtrip(af, raw=False, standard_version=None): if not isinstance(af, asdf.AsdfFile): - af = asdf.AsdfFile(af) + af = asdf.AsdfFile(af, version=standard_version) b = io.BytesIO() af.write_to(b) b.seek(0) @@ -171,21 +171,14 @@ def test_byteorder(tmp_path): assert my_tree["little"].dtype.byteorder == "<" -def test_all_dtypes(tmp_path): +@pytest.mark.parametrize("dtype", ndarray._datatype_names.values()) +def test_all_dtypes(dtype): + standard_version = "1.6.0" if dtype == "f2" else None tree = {} for byteorder in (">", "<"): - for dtype in ndarray._datatype_names.values(): - # Python 3 can't expose these dtypes in non-native byte - # order, because it's using the new Python buffer - # interface. - if dtype in ("c32", "f16"): - continue - - arr = np.array([True, False]) if dtype == "b1" else np.arange(0, 10, dtype=str(byteorder + dtype)) - - tree[byteorder + dtype] = arr - - with roundtrip(tree) as af: + arr = np.array([True, False]) if dtype == "b1" else np.arange(0, 10, dtype=str(byteorder + dtype)) + tree[byteorder + dtype] = arr + with roundtrip(tree, standard_version=standard_version) as af: for k in tree: pre = tree[k] post = af[k] diff --git a/asdf/tags/core/ndarray.py b/asdf/tags/core/ndarray.py index b59e331aa..37574073f 100644 --- a/asdf/tags/core/ndarray.py +++ b/asdf/tags/core/ndarray.py @@ -16,6 +16,7 @@ "uint16": "u2", "uint32": "u4", "uint64": "u8", + "float16": "f2", "float32": "f4", "float64": "f8", "complex64": "c8", diff --git a/pyproject.toml b/pyproject.toml index 582029927..372b29373 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -19,7 +19,7 @@ dynamic = [ 'version', ] dependencies = [ - "asdf-standard>=1.0.1", + "asdf-standard>=1.1.0", "asdf-transform-schemas>=0.3", "asdf-unit-schemas>=0.1", "importlib-metadata>=4.11.4",