Ben Chuanlong Du's Blog

It is never too late to learn.

Polars Series in Rust

Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!

In [2]:
:timing
:sccache 1
:dep polars = { version = "0.21.1", features = ["lazy", "parquet"] }
In [13]:
use polars::prelude::*;

ChunkedArray

Series

In [4]:
let s: Series = [10, 20, 30].iter().collect();
s
Out[4]:
shape: (3,)
Series: '' [i32]
[
	10
	20
	30
]
In [5]:
s.len()
Out[5]:
3
In [6]:
s.get(2)
Out[6]:
Int32(30)
In [15]:
match s.get(2) {
    AnyValue::Int32(x) => x,
    _ => panic!(),
}
Out[15]:
30

Convert a Series to a ChunkedArray.

In [9]:
{
    let ca = s.i32().unwrap();
    ca
}
Out[9]:
shape: (3,)
ChunkedArray: '' [Int32]
[
	10
	20
	30
]

Get the first element of the ChunkedArray.

In [10]:
{
    let ca = s.i32().unwrap();
    ca.get(0)
}
Out[10]:
Some(10)
In [ ]:

Comments