polars_python/
py_modules.rs1use pyo3::prelude::*;
2use pyo3::sync::GILOnceCell;
3
4static POLARS: GILOnceCell<Py<PyModule>> = GILOnceCell::new();
5static POLARS_RS: GILOnceCell<PyObject> = GILOnceCell::new();
6static UTILS: GILOnceCell<PyObject> = GILOnceCell::new();
7static SERIES: GILOnceCell<PyObject> = GILOnceCell::new();
8static DATAFRAME: GILOnceCell<PyObject> = GILOnceCell::new();
9
10pub(crate) fn polars(py: Python<'_>) -> &Py<PyModule> {
11 POLARS.get_or_init(py, || py.import("polars").unwrap().unbind())
12}
13
14pub(crate) fn polars_rs(py: Python<'_>) -> &PyObject {
15 POLARS_RS.get_or_init(py, || polars(py).getattr(py, "polars").unwrap())
16}
17
18pub(crate) fn pl_utils(py: Python<'_>) -> &PyObject {
19 UTILS.get_or_init(py, || polars(py).getattr(py, "_utils").unwrap())
20}
21
22pub(crate) fn pl_series(py: Python<'_>) -> &PyObject {
23 SERIES.get_or_init(py, || polars(py).getattr(py, "Series").unwrap())
24}
25
26pub(crate) fn pl_df(py: Python<'_>) -> &PyObject {
27 DATAFRAME.get_or_init(py, || polars(py).getattr(py, "DataFrame").unwrap())
28}