AssertionError: The 'data' field must be of type 'float' in rclpy: Humble asserts, Jazzy and Lyrical abort at publish, measured
When rclpy rejects a value with The 'data' field must be of type 'float', or a Jazzy or Lyrical node aborts at publish() with a convert_from_py assertion, the value you assigned has the wrong Python type for that field, so convert it where you assign: float(value), int(value), .to_msg() or .tolist(). I ran 69 assignments on 2026-11-02 in the official ros:humble-ros-base, ros:jazzy-ros-base and ros:lyrical-ros-base Docker images.
AssertionError: The 'data' field must be of type 'float'
On Jazzy and Lyrical the same mistake usually shows no AssertionError. The process dies when you publish:
python3: ./.obj-x86_64-linux-gnu/rosidl_generator_py/std_msgs/msg/_float64_s.c:58: std_msgs__msg__float64__convert_from_py: Assertion `PyFloat_Check(field)' failed.
A Python message field takes exactly one Python type. A float64 or float32 field needs a float, an integer field needs an int, a string field needs a str, and a sub-message field needs that message class. Python's 1 is an int, so msg.data = 1 fails on a Float64. Convert at the point where you assign:
msg.data = float(value) # float64 / float32 fields, also for numpy.float32 and numpy.int64
msg.data = int(value) # int32, uint8, ... fields
msg.header.stamp = node.get_clock().now().to_msg() # not time.time(), not clock.now()
point.time_from_start = Duration(seconds=1).to_msg() # rclpy Duration -> builtin_interfaces Duration
arr_msg.data = np_array.astype(float).tolist() # float64[] from numpy on Humble
On Humble the check runs in the setter, so you get the AssertionError at the line that assigns the value. On Jazzy and Lyrical the setter check is off unless you set ROS_PYTHON_CHECK_FIELDS=1. A wrong scalar type then reaches the C conversion code and aborts the interpreter with exit code 134 and no Python traceback. Some wrong values don't fail at all. They arrive changed. Turn the checks on while you develop on Jazzy and Lyrical:
export ROS_PYTHON_CHECK_FIELDS=1

Which value caused each error message
All of these came from assigning one value to one field. With checks on (Humble by default, Jazzy and Lyrical with ROS_PYTHON_CHECK_FIELDS=1), the text was the same on all three distros, except for the sequence wording noted in the last rows.
| What you assigned | AssertionError text |
|---|---|
Float64.data = 1, True, '1.0', None, np.float32(1.5) or np.int64(1) |
The 'data' field must be of type 'float' |
Vector3(x=1, y=2.0, z=3.0) (constructor keyword) |
The 'x' field must be of type 'float' |
Float32.data = 1e39 |
The 'data' field must be a float in [-3.402823466e+38, 3.402823466e+38] |
Int32.data = 1.0 or np.int64(5) |
The 'data' field must be of type 'int' |
Int32.data = 2**31 |
The 'data' field must be an integer in [-2147483648, 2147483647] |
UInt8.data = 256 or -1 |
The 'data' field must be an unsigned integer in [0, 255] |
Bool.data = 1 |
The 'data' field must be of type 'bool' |
String.data = 5 or b'abc', Header.frame_id = None |
The 'data' field must be of type 'str' (or 'frame_id') |
Header.stamp = time.time() or node.get_clock().now() |
The 'stamp' field must be a sub message of type 'Time' |
JointTrajectoryPoint.time_from_start = Duration(seconds=1) (rclpy) or 1.0 |
The 'time_from_start' field must be a sub message of type 'Duration' |
Wrench.force = [1.0, 2.0, 3.0] |
The 'force' field must be a sub message of type 'Vector3' |
Float64MultiArray.data = [1, 2, 3], a numpy array, a generator, a nested list or a scalar |
The 'data' field must be a set or sequence and each value of type 'float' and each double in [-1797... (Lyrical: must be sequence and each value) |
Imu.orientation_covariance = [0.0]*8 or [0]*9 |
The 'orientation_covariance' field must be a set or sequence with length 9 and each value of type 'float' ... (Lyrical: must be sequence with length 9) |
Float64MultiArray.data = array.array('f', ...) |
The 'data' array.array() must have the type code of 'd' |
Imu.orientation_covariance = np.zeros(9, dtype=np.float32) |
The 'orientation_covariance' numpy.ndarray() must have the dtype of 'numpy.float64' |
The sequence message prints the double range as two 309-digit numbers, so the line is very long. The useful part is the field name at the start. The error comes from the setter, so the traceback points at your own assignment line or at the message constructor. With checks on, nothing reaches publish(): publisher.publish() of a Float64 with data = 1 never ran on Humble because the assignment failed first.
Test setup: 69 assignments, three modes, three ros-base images
On 2026-11-02 I used the official ros:humble-ros-base, ros:jazzy-ros-base and ros:lyrical-ros-base images with no extra packages. One script assigned 69 different values to fields of std_msgs, geometry_msgs, sensor_msgs and trajectory_msgs messages and printed either the stored type or the exception. I ran it twice per distro: with the default environment, and with ROS_PYTHON_CHECK_FIELDS=1. A second script took 24 of the wrong values, assigned one, then ran serialize_message and deserialize_message, which use the same C conversion as publish(). Each of these ran in its own process, because a wrong type can abort the interpreter. I ran that set in three modes: default, ROS_PYTHON_CHECK_FIELDS=1, and python3 -O. Three of the cases also went through a real publisher.publish(). I also printed the generated setter for std_msgs/Float64.data on each distro.
This is the setter on Humble:
@data.setter
def data(self, value):
if __debug__:
assert \
isinstance(value, float), \
"The 'data' field must be of type 'float'"
And on Jazzy:
ros_python_check_fields = getenv('ROS_PYTHON_CHECK_FIELDS', default='')
...
self._check_fields = ros_python_check_fields == '1'
...
@data.setter
def data(self, value):
if self._check_fields:
assert \
isinstance(value, float), \
"The 'data' field must be of type 'float'"
Lyrical has the same _check_fields switch and adds a type hint (def data(self, value: float) -> None). The check is a plain isinstance, so it has no tolerance. An int is not a float, and numpy.float32 is not a float either. numpy.float64 passed on all three distros, and so did an element taken from a float64 numpy array, because that type is a subclass of Python float. Int32.data = True also passed, because bool is a subclass of int. The reverse, Bool.data = 1, failed.
Jazzy and Lyrical: no AssertionError, then a crash at publish
With the default environment, every wrong assignment in the table above succeeded on Jazzy and Lyrical. The setter stored whatever it got (int 1, str '1.0', NoneType None, an rclpy Time object). The failure came later, when the message was converted for the wire. For these cases the process printed one line from a C assert and exited with code 134 (SIGABRT):
| Stored wrong value | Abort line (Jazzy file and line) |
|---|---|
Float64.data as int, str, None, np.float32, np.int64 |
_float64_s.c:58: ... Assertion `PyFloat_Check(field)' failed. |
Int32.data as float or np.int64 |
_int32_s.c:58: ... Assertion `PyLong_Check(field)' failed. |
Bool.data = 1 |
_bool_s.c:58: ... Assertion `PyBool_Check(field)' failed. |
String.data as int or bytes, Header.frame_id = None |
Assertion `PyUnicode_Check(field)' failed. |
Header.stamp = time.time() or clock.now() |
_time_s.c:50: ... Assertion `strncmp("builtin_interfaces.msg._time.Time", full_classname_dest, 33) == 0' failed. |
time_from_start = rclpy Duration |
_duration_s.c:50: ... Assertion `strncmp("builtin_interfaces.msg._duration.Duration", full_classname_dest, 41) == 0' failed. |
Wrench.force = a list |
_vector3_s.c:50: ... Assertion `strncmp("geometry_msgs.msg._vector3.Vector3", full_classname_dest, 34) == 0' failed. |
A real publisher.publish() of a Float64 with data = 1 aborted the same way on Jazzy and Lyrical, with exit code 134. So did a String with data = 5. There is no Python exception and no traceback, only that one line and the exit code.
If you see a convert_from_py line like this, the fix is the same as for the AssertionError. Set ROS_PYTHON_CHECK_FIELDS=1, run again, and the AssertionError will name the field.
Wrong values that don't fail at all
These are the cases worth knowing about even if your node never crashes. With checks off (Jazzy and Lyrical by default, Humble under python3 -O), these values went through serialize_message and came back changed, with no error:
| Assigned | Received after serialize and deserialize |
|---|---|
Int32.data = 2**31 |
-2147483648 |
UInt8.data = 256 |
0 |
Float32.data = 1e39 |
inf |
Imu.orientation_covariance = [0.0]*8 (8 values for a 9-value field) |
9 values. The ninth was 6.2390559063634e-310 on Humble, 6.80997452258134e-310 on Jazzy and 3.95e-322 on Lyrical, whatever was in memory |
UInt8.data = -1 didn't wrap. It raised SystemError: <built-in method rclpy_serialize ...> returned a result with an exception set. The covariance row is the worst of these, because the extra value differed between runs and looked like a plausible tiny number. With checks on, all of these were rejected at assignment with the range or length messages from the first table.
With checks on, Float32.data = 1e39 was rejected. Only float('inf') and float('nan') passed the range check, on all three distros, for both Float32 and Float64.
Arrays: numpy, lists of ints and fixed sizes
Sequence fields such as float64[] behaved differently from scalars. On Jazzy and Lyrical with the default environment, the setter turned the value into array.array('d', value). That conversion accepts ints and numpy arrays. A list [1, 2, 3], a float64, float32 or int64 numpy array, a raveled 2-D array and a generator were all stored as array('d'), and the list and the numpy array serialized without error. array.array('f', ...) was stored as array('d') on Jazzy but kept as array('f') on Lyrical. I didn't serialize that one. A 2-D array still failed, with TypeError: only length-1 arrays can be converted to Python scalars.
On Humble, and on Jazzy and Lyrical with checks on, the check asks for a Sequence whose items are all float. A numpy array is not a Sequence, so even a float64 array failed with the long "set or sequence" message. These forms worked everywhere:
msg.data = arr.tolist() # float64 array -> list of float
msg.data = arr.astype(float).tolist() # int array -> list of float
msg.data = array.array('d', arr) # skips the per-item check (typecode must be 'd')
msg.data = [1.0, 2.0, 3.0] # or a tuple
Fixed-size fields like Imu.orientation_covariance (float64[9]) are stored as a numpy array. Here the checks accepted a 9-element list of floats, np.zeros(9), np.eye(3).flatten(), and setting one element with an int (cov[0] = 1). A float32 array was rejected with the dtype message. One case slipped past the checks on every distro: np.eye(3), a 3x3 array. The setter accepted it, even with checks on, and serialize_message then aborted with Assertion `PyArray_NDIM(seq_field) == 1' failed. Flatten 2-D arrays before you assign them.
For point clouds, read_points_numpy turns a PointCloud2 into an xyz NumPy array without a Python loop.
What each conversion costs on 100,000 values
The fix is always a conversion. For a single value it costs nothing you'd notice. 1,000 Float64.data = 1.0 assignments took 1.003 ms on Humble, 0.518 ms on Jazzy and 0.405 ms on Lyrical. For a 100,000-element Float64MultiArray.data the choice matters a bit more. Best of five, per assignment, including the conversion:
| Assignment (100,000 values) | Humble | Jazzy, default | Jazzy, checks on | Lyrical, default |
|---|---|---|---|---|
| list of Python floats | 16.861 ms | 2.955 ms | 12.780 ms | 2.715 ms |
| numpy float64 array, as is | AssertionError | 10.793 ms | AssertionError | 11.430 ms |
arr.tolist() |
18.736 ms | 5.455 ms | 15.328 ms | 5.085 ms |
array.array('d', arr) |
10.442 ms | 10.956 ms | 10.722 ms | 11.402 ms |
[float(x) for x in arr] |
26.790 ms | 11.686 ms | 22.070 ms | 12.077 ms |
The per-item check is most of the cost of a big list: on Jazzy, turning it on raised the plain-list case from 2.955 ms to 12.780 ms. array.array('d', arr) stayed between 10.4 and 11.4 ms in every mode, because the setter takes an array('d') without checking each item. On Humble that made it the fastest fix that works. With checks off, arr.tolist() was faster. A list comprehension with float(x) was the slowest everywhere. If large arrays are slow in your node for other reasons, such as arrays of nested messages, that is a different problem, measured in rclpy publish() slow with large custom message arrays.
The fix options in short:
- Convert at assignment with
float(),int(),.to_msg()or.tolist(). Works on every distro and in every mode. - Write float literals:
2022.0, not2022;Vector3(x=1.0, ...), notx=1. - Turn checks on during development on Jazzy and Lyrical with
ROS_PYTHON_CHECK_FIELDS=1, or per message with thecheck_fields=Trueconstructor keyword.Float64(data=1, check_fields=True)raised the usual AssertionError on Jazzy and Lyrical. On Humble that keyword doesn't exist and gaveAssertionError: Invalid arguments passed to constructor: check_fields. - Don't fix it with
python3 -O. On Humble,-Oremoves the setter checks (they sit underif __debug__:). The result matched the Jazzy default exactly: the same aborts and the same silent wraps.
Where Humble, Jazzy and Lyrical differed
The main change is when the check runs. On Humble (rosidl_generator_py 0.14.6) it runs whenever Python runs without -O. On Jazzy (0.22.2) and Lyrical (0.27.2) it runs only with ROS_PYTHON_CHECK_FIELDS=1 or check_fields=True, and it is off by default. python3 -O had no extra effect on Jazzy or Lyrical. With checks on, the AssertionError texts were identical on all three, with one exception. For sequence and fixed-array fields, Lyrical says must be sequence and each value where Humble and Jazzy say must be a set or sequence and each value. If you search for the error, use the part before that wording. The C abort lines moved from _float64_s.c:58 on Humble and Jazzy to _float64_s.c:55 on Lyrical, and _imu_s.c:106 to :103. numpy was 1.21.5, 1.26.4 and 2.3.5, and the numpy results matched across all three versions. Lyrical only prints numpy scalars differently (np.float64(1.5)).
Not tested
Custom .msg packages (I only used the standard message packages), service requests and action goals, ros2 topic pub YAML, rclcpp, nodes started from a launch file and how the abort shows up there, serializing an array('f') on Lyrical, non-default RMW implementations, byte[] and char fields, bounded strings, Foxy, Iron, Kilted and Rolling.
Measured on 2026-11-02 with ros:humble-ros-base (sha256:d9bcf2e6f72d..., rclpy 3.3.22, rclcpp 16.0.21, ros2cli 0.18.20, rosidl_generator_py 0.14.6, Python 3.10.12, numpy 1.21.5), ros:jazzy-ros-base (sha256:8eed0a4669bb..., rclpy 7.1.12, rclcpp 28.1.22, ros2cli 0.32.13, rosidl_generator_py 0.22.2, Python 3.12.3, numpy 1.26.4) and ros:lyrical-ros-base (sha256:3224ee150cb0..., rclpy 10.0.11, rclcpp 32.0.3, ros2cli 0.40.9, rosidl_generator_py 0.27.2, Python 3.14.4, numpy 2.3.5), default RMW (Fast DDS), on a 2 vCPU x86_64 machine. Full digests are in digests.txt.
Script and raw output: evidence folder. Questions this answers: Timestamp message ros2 - python, float error while using a float - custom messages, Best way to integrate ndarray into ros2, AssertionError: The 'time_from_start' field must be a sub message of type 'Duration', Publish an Array of Values as Wrench Message in ROS2 and Python, rosidl_python: Integers should be accepted as floats.
If the error names a field you didn't expect, print type(value) just before the assignment and compare it with the field type from ros2 interface show for that message. On Jazzy and Lyrical, run once with ROS_PYTHON_CHECK_FIELDS=1 so a wrong type stops at the assignment line instead of aborting at publish() or arriving changed.