Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add float16 support #1692

Merged
merged 3 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

- Fix ``numpy.ma.MaskedArray`` saving for numpy 2.x [#1769]

- Add ``float16`` support [#1692]


3.1.0 (2024-02-27)
------------------

Expand Down Expand Up @@ -52,6 +55,7 @@ The ASDF Standard is at v1.6.0

- Deprecate ``AsdfFile.version_map`` [#1745]


3.0.1 (2023-10-30)
------------------

Expand Down
23 changes: 8 additions & 15 deletions asdf/_tests/tags/core/tests/test_ndarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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]
Expand Down
1 change: 1 addition & 0 deletions asdf/tags/core/ndarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"uint16": "u2",
"uint32": "u4",
"uint64": "u8",
"float16": "f2",
"float32": "f4",
"float64": "f8",
"complex64": "c8",
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Loading