Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pola-rs
GitHub Repository: pola-rs/polars
Path: blob/main/crates/polars-core/src/lib.rs
6939 views
1
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
2
#![cfg_attr(feature = "simd", feature(portable_simd))]
3
#![allow(ambiguous_glob_reexports)]
4
#![cfg_attr(
5
feature = "allow_unused",
6
allow(unused, dead_code, irrefutable_let_patterns)
7
)] // Maybe be caused by some feature
8
// combinations
9
#![cfg_attr(feature = "nightly", allow(clippy::non_canonical_partial_ord_impl))] // remove once stable
10
extern crate core;
11
12
#[macro_use]
13
pub mod utils;
14
pub mod chunked_array;
15
pub mod config;
16
pub mod datatypes;
17
pub mod error;
18
pub mod fmt;
19
pub mod frame;
20
pub mod functions;
21
pub mod hashing;
22
mod named_from;
23
pub mod prelude;
24
#[cfg(feature = "random")]
25
pub mod random;
26
pub mod scalar;
27
pub mod schema;
28
#[cfg(feature = "serde")]
29
pub mod serde;
30
pub mod series;
31
pub mod testing;
32
#[cfg(test)]
33
mod tests;
34
35
use std::sync::{LazyLock, Mutex};
36
use std::time::{SystemTime, UNIX_EPOCH};
37
38
pub use datatypes::SchemaExtPl;
39
pub use hashing::IdBuildHasher;
40
use rayon::{ThreadPool, ThreadPoolBuilder};
41
42
pub static PROCESS_ID: LazyLock<u128> = LazyLock::new(|| {
43
SystemTime::now()
44
.duration_since(UNIX_EPOCH)
45
.unwrap()
46
.as_nanos()
47
});
48
49
// this is re-exported in utils for polars child crates
50
#[cfg(not(target_family = "wasm"))] // only use this on non wasm targets
51
pub static POOL: LazyLock<ThreadPool> = LazyLock::new(|| {
52
let thread_name = std::env::var("POLARS_THREAD_NAME").unwrap_or_else(|_| "polars".to_string());
53
ThreadPoolBuilder::new()
54
.num_threads(
55
std::env::var("POLARS_MAX_THREADS")
56
.map(|s| s.parse::<usize>().expect("integer"))
57
.unwrap_or_else(|_| {
58
std::thread::available_parallelism()
59
.unwrap_or(std::num::NonZeroUsize::new(1).unwrap())
60
.get()
61
}),
62
)
63
.thread_name(move |i| format!("{thread_name}-{i}"))
64
.build()
65
.expect("could not spawn threads")
66
});
67
68
#[cfg(all(target_os = "emscripten", target_family = "wasm"))] // Use 1 rayon thread on emscripten
69
pub static POOL: LazyLock<ThreadPool> = LazyLock::new(|| {
70
ThreadPoolBuilder::new()
71
.num_threads(1)
72
.use_current_thread()
73
.build()
74
.expect("could not create pool")
75
});
76
77
#[cfg(all(not(target_os = "emscripten"), target_family = "wasm"))] // use this on other wasm targets
78
pub static POOL: LazyLock<polars_utils::wasm::Pool> = LazyLock::new(|| polars_utils::wasm::Pool);
79
80
// utility for the tests to ensure a single thread can execute
81
pub static SINGLE_LOCK: LazyLock<Mutex<()>> = LazyLock::new(|| Mutex::new(()));
82
83
/// Default length for a `.head()` call
84
pub(crate) const HEAD_DEFAULT_LENGTH: usize = 10;
85
/// Default length for a `.tail()` call
86
pub(crate) const TAIL_DEFAULT_LENGTH: usize = 10;
87
pub const CHEAP_SERIES_HASH_LIMIT: usize = 1000;
88
89