Skip to content

Commit 4daf0dd

Browse files
committed
clarify how to encode structured data types
1 parent 9311f4f commit 4daf0dd

File tree

1 file changed

+30
-7
lines changed

1 file changed

+30
-7
lines changed

docs/spec/v2.rst

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,31 @@ the `NumPy documentation on Datetimes and Timedeltas
140140
<https://docs.scipy.org/doc/numpy/reference/arrays.datetime.html#datetime-units>`_.
141141
For example, ``"<M8[ns]"`` specifies a datetime64 data type with nanosecond time units.
142142

143-
Structured data types (i.e., with multiple named fields) are encoded as a list
144-
of two-element lists, following `NumPy array protocol type descriptions (descr)
145-
<http://docs.scipy.org/doc/numpy/reference/arrays.interface.html#>`_. For
146-
example, the JSON list ``[["r", "|u1"], ["g", "|u1"], ["b", "|u1"]]`` defines a
147-
data type composed of three single-byte unsigned integers labelled "r", "g" and
148-
"b".
149-
143+
Structured data types (i.e., with multiple named fields) are encoded
144+
as a list of lists, following `NumPy array protocol type descriptions
145+
(descr)
146+
<http://docs.scipy.org/doc/numpy/reference/arrays.interface.html#>`_. Each
147+
sub-list has the form ``[fieldname, datatype, shape]`` where ``shape``
148+
is optional. ``fieldname`` is a string, ``datatype`` is a string
149+
specifying a simple data type (see above), and ``shape`` is a list of
150+
integers specifying subarray shape. For example, the JSON list below
151+
defines a data type composed of three single-byte unsigned integer
152+
fields named "r", "g" and "b"::
153+
154+
[["r", "|u1"], ["g", "|u1"], ["b", "|u1"]]
155+
156+
For example, the JSON list below defines a data type composed of three
157+
fields named "x", "y" and "z", where "x" and "y" each contain 32-bit
158+
floats, and each item in "z" is a 2 by 2 array of floats::
159+
160+
[["x", "<f4"], ["y", "<f4"], ["z", "<f4", [2, 2]]]
161+
162+
Structured data types may also be nested, e.g., the following JSON
163+
list defines a data type with two fields "foo" and "bar", where "bar"
164+
has two sub-fields "baz" and "qux"::
165+
166+
[["foo", "<f4"], ["bar", [["baz", "<f4"], ["qux", "<i4"]]]]
167+
150168
.. _spec_v2_array_fill_value:
151169

152170
Fill value encoding
@@ -512,6 +530,11 @@ initially published to clarify ambiguities and add some missing information.
512530
either arrays or groups, and if absent then custom attributes should be treated as
513531
empty.
514532

533+
* The specification now clarifies that structured datatypes with
534+
subarray shapes and/or with nested structured data types are
535+
supported, and describes the JSON syntax for encoding them in array
536+
metadata (:issue:`111`, :issue:`296`).
537+
515538

516539
Changes from version 1 to version 2
517540
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

0 commit comments

Comments
 (0)