Skip to content

mcap-ros2-support Fails to Serialize float64[] Array Fields (NumPy Conflict) #1469

@hungngyenn

Description

@hungngyenn

Description

When attempting to serialize a ROS 2 message (like sensor_msgs/msg/Imu) where a fixed-size array field (e.g., orientation_covariance: float64[9]) is initialized as a NumPy ndarray, the mcap-ros2-support library throws a ValueError. The serialization checker strictly expects a standard Python sequence (list or tuple) for array types, even though the array is numeric.

  • Version:
    mcap-ros2-support (PyPI)
    mcap 1.3.0 (PyPI)

  • Platform:
    ROS2 Jazzy
    Python 3.12

Steps To Reproduce

  1. Set up a minimal ROS 2 package environment with the recorder running.
  2. Publish a sensor_msgs/msg/Imu message using a tool (e.g., ros2 topic pub) that initializes the fixed-size array fields (like orientation_covariance) as a NumPy ndarray object.

Note: The issue persists even when initializing with a Python list structure, indicating the conversion to ndarray happens upstream of the writer.

Expected Behavior
The message should be successfully serialized and recorded, as the fixed-size array conversion should be handled by the installed mcap-ros2-support version.

** Actual Behavior**

ValueError: Field "orientation_covariance" is not an array (<class 'numpy.ndarray'>) but has array type "float64[]"
...
File "/home/user/.local/lib/python3.12/site-packages/mcap_ros2/_dynamic.py", line 431, in _write_complex_type
    raise ValueError( 

Proposed Fix Location
The fix likely needs to ensure that numpy.ndarray objects for numeric fixed-size arrays (float64[]) are explicitly handled within the dynamic encoding logic:

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions