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