polars_python/functions/
meta.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
use polars_core::fmt::FloatFmt;
use polars_core::prelude::IDX_DTYPE;
use polars_core::POOL;
use pyo3::exceptions::PyValueError;
use pyo3::prelude::*;

use crate::conversion::Wrap;

#[pyfunction]
pub fn get_index_type(py: Python) -> PyResult<Bound<PyAny>> {
    Wrap(IDX_DTYPE).into_pyobject(py)
}

#[pyfunction]
pub fn thread_pool_size() -> usize {
    POOL.current_num_threads()
}

#[pyfunction]
pub fn set_float_fmt(fmt: &str) -> PyResult<()> {
    let fmt = match fmt {
        "full" => FloatFmt::Full,
        "mixed" => FloatFmt::Mixed,
        e => {
            return Err(PyValueError::new_err(format!(
                "fmt must be one of {{'full', 'mixed'}}, got {e}",
            )))
        },
    };
    polars_core::fmt::set_float_fmt(fmt);
    Ok(())
}

#[pyfunction]
pub fn get_float_fmt() -> PyResult<String> {
    let strfmt = match polars_core::fmt::get_float_fmt() {
        FloatFmt::Full => "full",
        FloatFmt::Mixed => "mixed",
    };
    Ok(strfmt.to_string())
}

#[pyfunction]
#[pyo3(signature = (precision=None))]
pub fn set_float_precision(precision: Option<usize>) -> PyResult<()> {
    use polars_core::fmt::set_float_precision;
    set_float_precision(precision);
    Ok(())
}

#[pyfunction]
pub fn get_float_precision() -> PyResult<Option<usize>> {
    use polars_core::fmt::get_float_precision;
    Ok(get_float_precision())
}

#[pyfunction]
#[pyo3(signature = (sep=None))]
pub fn set_thousands_separator(sep: Option<char>) -> PyResult<()> {
    use polars_core::fmt::set_thousands_separator;
    set_thousands_separator(sep);
    Ok(())
}

#[pyfunction]
pub fn get_thousands_separator() -> PyResult<Option<String>> {
    use polars_core::fmt::get_thousands_separator;
    Ok(Some(get_thousands_separator()))
}

#[pyfunction]
#[pyo3(signature = (sep=None))]
pub fn set_decimal_separator(sep: Option<char>) -> PyResult<()> {
    use polars_core::fmt::set_decimal_separator;
    set_decimal_separator(sep);
    Ok(())
}

#[pyfunction]
pub fn get_decimal_separator() -> PyResult<Option<char>> {
    use polars_core::fmt::get_decimal_separator;
    Ok(Some(get_decimal_separator()))
}

#[pyfunction]
#[pyo3(signature = (trim=None))]
pub fn set_trim_decimal_zeros(trim: Option<bool>) -> PyResult<()> {
    use polars_core::fmt::set_trim_decimal_zeros;
    set_trim_decimal_zeros(trim);
    Ok(())
}

#[pyfunction]
pub fn get_trim_decimal_zeros() -> PyResult<Option<bool>> {
    use polars_core::fmt::get_trim_decimal_zeros;
    Ok(Some(get_trim_decimal_zeros()))
}