Module polars_io::ipc [−][src]
This is supported on crate feature
ipc
only.Expand description
(De)serializing Arrows IPC format.
Arrow IPC is a binary format format. It is the recommended way to serialize and deserialize Polars DataFrames as this is most true to the data schema.
Example
use polars_core::prelude::*;
use polars_io::prelude::*;
use std::io::Cursor;
let s0 = Series::new("days", &[0, 1, 2, 3, 4]);
let s1 = Series::new("temp", &[22.1, 19.9, 7., 2., 3.]);
let mut df = DataFrame::new(vec![s0, s1]).unwrap();
// Create an in memory file handler.
// Vec<u8>: Read + Write
// Cursor<T>: Seek
let mut buf: Cursor<Vec<u8>> = Cursor::new(Vec::new());
// write to the in memory buffer
IpcWriter::new(&mut buf).finish(&mut df).expect("ipc writer");
// reset the buffers index after writing to the beginning of the buffer
buf.set_position(0);
// read the buffer into a DataFrame
let df_read = IpcReader::new(buf).finish().unwrap();
assert!(df.frame_equal(&df_read));