polars_python/
py_modules.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use pyo3::prelude::*;
use pyo3::sync::GILOnceCell;

static POLARS: GILOnceCell<Py<PyModule>> = GILOnceCell::new();
static UTILS: GILOnceCell<PyObject> = GILOnceCell::new();
static SERIES: GILOnceCell<PyObject> = GILOnceCell::new();

pub(crate) fn polars(py: Python<'_>) -> &Py<PyModule> {
    POLARS.get_or_init(py, || py.import("polars").unwrap().unbind())
}

pub(crate) fn pl_utils(py: Python<'_>) -> &PyObject {
    UTILS.get_or_init(py, || polars(py).getattr(py, "_utils").unwrap())
}

pub(crate) fn pl_series(py: Python<'_>) -> &PyObject {
    SERIES.get_or_init(py, || polars(py).getattr(py, "Series").unwrap())
}