polars_utils/
config.rs

1use polars_error::{PolarsResult, polars_bail};
2
3use crate::relaxed_cell::RelaxedCell;
4
5pub(crate) fn verbose() -> bool {
6    std::env::var("POLARS_VERBOSE").as_deref().unwrap_or("") == "1"
7}
8
9pub fn check_allow_importing_interval_as_struct(type_name: &'static str) -> PolarsResult<()> {
10    static ALLOW: RelaxedCell<bool> = RelaxedCell::new_bool(false);
11
12    if !ALLOW.load() {
13        ALLOW.fetch_or(std::env::var("POLARS_IMPORT_INTERVAL_AS_STRUCT").as_deref() == Ok("1"));
14    }
15
16    if ALLOW.load() {
17        return Ok(());
18    }
19
20    polars_bail!(
21        ComputeError:
22        "could not import from `{type_name}` type. \
23        Hint: This can be imported by setting \
24        POLARS_IMPORT_INTERVAL_AS_STRUCT=1 in the environment. \
25        Note however that this is unstable functionality \
26        that may change at any time."
27    )
28}