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::Mutex;
31use std::time::{SystemTime, UNIX_EPOCH};
32
33pub use datatypes::SchemaExtPl;
34pub use hashing::IdBuildHasher;
35use once_cell::sync::Lazy;
36use rayon::{ThreadPool, ThreadPoolBuilder};
37
38#[cfg(feature = "dtype-categorical")]
39pub use crate::chunked_array::logical::categorical::string_cache::*;
40
41pub static PROCESS_ID: Lazy<u128> = Lazy::new(|| {
42    SystemTime::now()
43        .duration_since(UNIX_EPOCH)
44        .unwrap()
45        .as_nanos()
46});
47
48// this is re-exported in utils for polars child crates
49#[cfg(not(target_family = "wasm"))] // only use this on non wasm targets
50pub static POOL: Lazy<ThreadPool> = Lazy::new(|| {
51    let thread_name = std::env::var("POLARS_THREAD_NAME").unwrap_or_else(|_| "polars".to_string());
52    ThreadPoolBuilder::new()
53        .num_threads(
54            std::env::var("POLARS_MAX_THREADS")
55                .map(|s| s.parse::<usize>().expect("integer"))
56                .unwrap_or_else(|_| {
57                    std::thread::available_parallelism()
58                        .unwrap_or(std::num::NonZeroUsize::new(1).unwrap())
59                        .get()
60                }),
61        )
62        .thread_name(move |i| format!("{}-{}", thread_name, i))
63        .build()
64        .expect("could not spawn threads")
65});
66
67#[cfg(all(target_os = "emscripten", target_family = "wasm"))] // Use 1 rayon thread on emscripten
68pub static POOL: Lazy<ThreadPool> = Lazy::new(|| {
69    ThreadPoolBuilder::new()
70        .num_threads(1)
71        .use_current_thread()
72        .build()
73        .expect("could not create pool")
74});
75
76#[cfg(all(not(target_os = "emscripten"), target_family = "wasm"))] // use this on other wasm targets
77pub static POOL: Lazy<polars_utils::wasm::Pool> = Lazy::new(|| polars_utils::wasm::Pool);
78
79// utility for the tests to ensure a single thread can execute
80pub static SINGLE_LOCK: Lazy<Mutex<()>> = Lazy::new(|| Mutex::new(()));
81
82/// Default length for a `.head()` call
83pub(crate) const HEAD_DEFAULT_LENGTH: usize = 10;
84/// Default length for a `.tail()` call
85pub(crate) const TAIL_DEFAULT_LENGTH: usize = 10;