6

I want to write a Python extension using Rust with Ctypes or Pyo3 to get better performance than native Python. But how to exchange data such as Polars DataFrame or ndarray type between Rust and Python?

Hakase
  • 211
  • 1
  • 12
  • 1
    See: https://github.com/pola-rs/polars/tree/master/examples/python_rust_compiled_function – ritchie46 Mar 16 '22 at 12:17
  • Thanks for reply, I noticed that `fn array_to_rust` in the example has a comment `/// Take an arrow array from python and convert it to a rust arrow array.` , so is this means the other three func will copy data? If the data from rust is used to create a DataFrame, is `rust_series_to_py_series` more efficient? – Hakase Mar 16 '22 at 13:23
  • See: https://stackoverflow.com/questions/75292316/example-of-zero-copy-share-of-a-polars-dataframe-between-python-and-rust – Alex L Apr 17 '23 at 18:54
  • And: https://medium.com/@niklas.molin/0-copy-you-pyarrow-array-to-rust-23b138cb5bf2 – Alex L Apr 17 '23 at 18:54

0 Answers0