Writing an NDArray whose elements are records containing enum fields raises:
AttributeError: 'numpy.uint64' object has no attribute 'value'
This affects any field of type T[] where T is a record with at least one enum field.
Call path
NDArraySerializerBase._write_data iterates over the flat structured array and calls element_serializer.write_numpy(stream, element) where element is a np.void scalar.
- The generated
RecordSerializer.write_numpy extracts each field with value['fieldname'] — yielding bare numpy scalars (e.g. np.uint64 for a flag field).
- It passes them to
RecordSerializer._write, which calls field_serializer.write(stream, scalar) for each field.
EnumSerializer.write does self._integer_serializer.write(stream, value.value) — but a np.uint64 scalar has no .value attribute.
Minimal reproducer
Tested with mrd-python v2.2.1, Python 3.13, numpy 2.4.3.
import io
import numpy as np
import mrd
from mrd.binary import AcquisitionHeaderSerializer
from mrd._binary import NDArraySerializer, CodedOutputStream
hdr_ser = AcquisitionHeaderSerializer()
arr = np.zeros((1,), dtype=hdr_ser.overall_dtype()) # structured array of AcquisitionHeader
arr_ser = NDArraySerializer(hdr_ser, 1)
arr_ser.write(CodedOutputStream(io.BytesIO()), arr)
# AttributeError: 'numpy.uint64' object has no attribute 'value'
Writing an
NDArraywhose elements are records containing enum fields raises:This affects any field of type
T[]whereTis a record with at least one enum field.Call path
NDArraySerializerBase._write_dataiterates over the flat structured array and callselement_serializer.write_numpy(stream, element)whereelementis anp.voidscalar.RecordSerializer.write_numpyextracts each field withvalue['fieldname']— yielding bare numpy scalars (e.g.np.uint64for a flag field).RecordSerializer._write, which callsfield_serializer.write(stream, scalar)for each field.EnumSerializer.writedoesself._integer_serializer.write(stream, value.value)— but anp.uint64scalar has no.valueattribute.Minimal reproducer
Tested with mrd-python v2.2.1, Python 3.13, numpy 2.4.3.