Browse Source

Automatically convert from `StructScalar` to `ArrayData` in ROS2 publish method

tags/v0.2.5-alpha.3
Philipp Oppermann 2 years ago
parent
commit
7f90c13cc2
Failed to extract signature
2 changed files with 11 additions and 3 deletions
  1. +1
    -1
      examples/python-ros2-dataflow/random_turtle.py
  2. +10
    -2
      libraries/extensions/ros2-bridge/python/src/lib.rs

+ 1
- 1
examples/python-ros2-dataflow/random_turtle.py View File

@@ -51,7 +51,7 @@ for i in range(500):
},
}

direction_arrow = pa.array([pa.scalar(direction)])
direction_arrow = pa.scalar(direction)
twist_writer.publish(direction_arrow)

case "external":


+ 10
- 2
libraries/extensions/ros2-bridge/python/src/lib.rs View File

@@ -11,7 +11,7 @@ use eyre::{eyre, Context, ContextCompat};
use futures::{Stream, StreamExt};
use pyo3::{
prelude::{pyclass, pymethods},
types::PyModule,
types::{PyList, PyModule},
PyAny, PyObject, PyResult, Python,
};
use typed::{
@@ -182,7 +182,15 @@ pub struct Ros2Publisher {
#[pymethods]
impl Ros2Publisher {
pub fn publish(&self, data: &PyAny) -> eyre::Result<()> {
// TODO: add support for arrow types
let pyarrow = PyModule::import(data.py(), "pyarrow")?;

let data = if data.is_instance(pyarrow.getattr("StructScalar")?)? {
let list = PyList::new(data.py(), [data]);
pyarrow.getattr("array")?.call1((list,))?
} else {
data
};

let value = arrow::array::ArrayData::from_pyarrow(data)?;
//// add type info to ensure correct serialization (e.g. struct types
//// and map types need to be serialized differently)


Loading…
Cancel
Save