From 3365ba7cf25ef4689c63e27d6aff9870a9327a70 Mon Sep 17 00:00:00 2001 From: Brett Date: Mon, 20 Nov 2023 10:52:03 -0500 Subject: [PATCH 1/3] add float16 support (and dev asdf-standard dep) --- asdf/_tests/tags/core/tests/test_ndarray.py | 23 +++++++-------------- asdf/tags/core/ndarray.py | 1 + pyproject.toml | 3 ++- 3 files changed, 11 insertions(+), 16 deletions(-) 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..d62292a89 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -19,7 +19,8 @@ dynamic = [ 'version', ] dependencies = [ - "asdf-standard>=1.0.1", + #"asdf-standard>=1.0.1", + "asdf-standard @ git+https://github.com/braingram/asdf-standard.git@f16", "asdf-transform-schemas>=0.3", "asdf-unit-schemas>=0.1", "importlib-metadata>=4.11.4", From c16e0600afbeaa117f3b4425c976132669bb1071 Mon Sep 17 00:00:00 2001 From: Brett Date: Mon, 20 Nov 2023 11:04:13 -0500 Subject: [PATCH 2/3] add changelog --- CHANGES.rst | 4 ++++ 1 file changed, 4 insertions(+) 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) ------------------ From b57ddb0fe8387507624c6ebc96cd460f0f3aa8bd Mon Sep 17 00:00:00 2001 From: Brett Date: Sat, 9 Mar 2024 12:47:05 -0500 Subject: [PATCH 3/3] remove asdf-standard dev dep --- pyproject.toml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index d62292a89..372b29373 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -19,8 +19,7 @@ dynamic = [ 'version', ] dependencies = [ - #"asdf-standard>=1.0.1", - "asdf-standard @ git+https://github.com/braingram/asdf-standard.git@f16", + "asdf-standard>=1.1.0", "asdf-transform-schemas>=0.3", "asdf-unit-schemas>=0.1", "importlib-metadata>=4.11.4",