microsoft / microsoft/yardl

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

Open
#284 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
C++
Stars
35
Forks
14
Avg merge
5d 17h
Merged PRs (30d)
1

Description

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'

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at NDArraySerializerBase._write_data and follow the mentioned generated RecordSerializer.write_numpy, RecordSerializer._write, and EnumSerializer.write call path. Reproduce the failure with the minimal NDArray example in the issue, then verify that an NDArray of records containing enum fields serializes without AttributeError.

Written by the indexing model from the issue text.

Assessment

Tech stack
numpy, python
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.