diff --git a/numpy/core/_internal.py b/numpy/core/_internal.py index 67ca1716faca..5298f412b396 100644 --- a/numpy/core/_internal.py +++ b/numpy/core/_internal.py @@ -363,6 +363,7 @@ def _index_fields(ary, fields): 'L': 'L', 'q': 'q', 'Q': 'Q', + 'e': 'e', 'f': 'f', 'd': 'd', 'g': 'g', @@ -388,6 +389,7 @@ def _index_fields(ary, fields): 'L': 'u4', 'q': 'i8', 'Q': 'u8', + 'e': 'f2', 'f': 'f', 'd': 'd', 'Zf': 'F', diff --git a/numpy/core/src/multiarray/buffer.c b/numpy/core/src/multiarray/buffer.c index 16164011f44d..3f9059d1f536 100644 --- a/numpy/core/src/multiarray/buffer.c +++ b/numpy/core/src/multiarray/buffer.c @@ -348,6 +348,7 @@ _buffer_format_string(PyArray_Descr *descr, _tmp_string_t *str, break; case NPY_LONGLONG: if (_append_char(str, 'q')) return -1; break; case NPY_ULONGLONG: if (_append_char(str, 'Q')) return -1; break; + case NPY_HALF: if (_append_char(str, 'e')) return -1; break; case NPY_FLOAT: if (_append_char(str, 'f')) return -1; break; case NPY_DOUBLE: if (_append_char(str, 'd')) return -1; break; case NPY_LONGDOUBLE: if (_append_char(str, 'g')) return -1; break; diff --git a/numpy/core/tests/test_multiarray.py b/numpy/core/tests/test_multiarray.py index 811fb33ab4e4..724aad25ffb5 100644 --- a/numpy/core/tests/test_multiarray.py +++ b/numpy/core/tests/test_multiarray.py @@ -1954,9 +1954,11 @@ def test_roundtrip(self): ('l', 'S4'), ('m', 'U4'), ('n', 'V3'), - ('o', '?')] + ('o', '?'), + ('p', np.half), + ] x = np.array([(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - asbytes('aaaa'), 'bbbb', asbytes('xxx'), True)], + asbytes('aaaa'), 'bbbb', asbytes('xxx'), True, 1.0)], dtype=dt) self._check_roundtrip(x) @@ -1988,6 +1990,25 @@ def test_roundtrip(self): x = np.array([1,2,3], dtype='