Skip to content

Python EnumSerializer raises AttributeError on NDArray of Record types containing enum fields #284

@naegelejd

Description

@naegelejd

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

  1. NDArraySerializerBase._write_data iterates over the flat structured array and calls element_serializer.write_numpy(stream, element) where element is a np.void scalar.
  2. The generated RecordSerializer.write_numpy extracts each field with value['fieldname'] — yielding bare numpy scalars (e.g. np.uint64 for a flag field).
  3. It passes them to RecordSerializer._write, which calls field_serializer.write(stream, scalar) for each field.
  4. 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'

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions