Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pola-rs
GitHub Repository: pola-rs/polars
Path: blob/main/crates/polars-python/src/functions/meta.rs
7889 views
1
use polars_core::POOL;
2
use polars_core::fmt::FloatFmt;
3
use polars_core::prelude::IDX_DTYPE;
4
use pyo3::exceptions::PyValueError;
5
use pyo3::prelude::*;
6
7
use crate::conversion::Wrap;
8
9
#[pyfunction]
10
pub fn get_index_type(py: Python) -> PyResult<Bound<PyAny>> {
11
Wrap(IDX_DTYPE).into_pyobject(py)
12
}
13
14
#[pyfunction]
15
pub fn thread_pool_size() -> usize {
16
POOL.current_num_threads()
17
}
18
19
#[pyfunction]
20
pub fn set_float_fmt(fmt: &str) -> PyResult<()> {
21
let fmt = match fmt {
22
"full" => FloatFmt::Full,
23
"mixed" => FloatFmt::Mixed,
24
e => {
25
return Err(PyValueError::new_err(format!(
26
"fmt must be one of {{'full', 'mixed'}}, got {e}",
27
)));
28
},
29
};
30
polars_core::fmt::set_float_fmt(fmt);
31
Ok(())
32
}
33
34
#[pyfunction]
35
pub fn get_float_fmt() -> PyResult<String> {
36
let strfmt = match polars_core::fmt::get_float_fmt() {
37
FloatFmt::Full => "full",
38
FloatFmt::Mixed => "mixed",
39
};
40
Ok(strfmt.to_string())
41
}
42
43
#[pyfunction]
44
#[pyo3(signature = (precision))]
45
pub fn set_float_precision(precision: Option<usize>) -> PyResult<()> {
46
use polars_core::fmt::set_float_precision;
47
set_float_precision(precision);
48
Ok(())
49
}
50
51
#[pyfunction]
52
pub fn get_float_precision() -> PyResult<Option<usize>> {
53
use polars_core::fmt::get_float_precision;
54
Ok(get_float_precision())
55
}
56
57
#[pyfunction]
58
#[pyo3(signature = (sep))]
59
pub fn set_thousands_separator(sep: Option<char>) -> PyResult<()> {
60
use polars_core::fmt::set_thousands_separator;
61
set_thousands_separator(sep);
62
Ok(())
63
}
64
65
#[pyfunction]
66
pub fn get_thousands_separator() -> PyResult<Option<String>> {
67
use polars_core::fmt::get_thousands_separator;
68
Ok(Some(get_thousands_separator()))
69
}
70
71
#[pyfunction]
72
#[pyo3(signature = (sep))]
73
pub fn set_decimal_separator(sep: Option<char>) -> PyResult<()> {
74
use polars_core::fmt::set_decimal_separator;
75
set_decimal_separator(sep);
76
Ok(())
77
}
78
79
#[pyfunction]
80
pub fn get_decimal_separator() -> PyResult<Option<char>> {
81
use polars_core::fmt::get_decimal_separator;
82
Ok(Some(get_decimal_separator()))
83
}
84
85
#[pyfunction]
86
#[pyo3(signature = (trim))]
87
pub fn set_trim_decimal_zeros(trim: Option<bool>) -> PyResult<()> {
88
use polars_core::fmt::set_trim_decimal_zeros;
89
set_trim_decimal_zeros(trim);
90
Ok(())
91
}
92
93
#[pyfunction]
94
pub fn get_trim_decimal_zeros() -> PyResult<Option<bool>> {
95
use polars_core::fmt::get_trim_decimal_zeros;
96
Ok(Some(get_trim_decimal_zeros()))
97
}
98
99