polars_core/
lib.rs

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
10extern crate core;
11
12#[macro_use]
13pub mod utils;
14pub mod chunked_array;
15pub mod config;
16pub mod datatypes;
17pub mod error;
18pub mod fmt;
19pub mod frame;
20pub mod functions;
21pub mod hashing;
22mod named_from;
23pub mod prelude;
24#[cfg(feature = "random")]
25pub mod random;
26pub mod scalar;
27pub mod schema;
28#[cfg(feature = "serde")]
29pub mod serde;
30pub mod series;
31pub mod testing;
32#[cfg(test)]
33mod tests;
34
35use std::sync::{LazyLock, Mutex};
36use std::time::{SystemTime, UNIX_EPOCH};
37
38pub use datatypes::SchemaExtPl;
39pub use hashing::IdBuildHasher;
40use rayon::{ThreadPool, ThreadPoolBuilder};
41
42pub 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
51pub 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
69pub 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
78pub 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
81pub static SINGLE_LOCK: LazyLock<Mutex<()>> = LazyLock::new(|| Mutex::new(()));
82
83/// Default length for a `.head()` call
84pub(crate) const HEAD_DEFAULT_LENGTH: usize = 10;
85/// Default length for a `.tail()` call
86pub(crate) const TAIL_DEFAULT_LENGTH: usize = 10;
87pub const CHEAP_SERIES_HASH_LIMIT: usize = 1000;