polars_core/scalar/
new.rs

1use std::sync::Arc;
2
3use super::Scalar;
4use crate::prelude::{AnyValue, DataType, TimeUnit, TimeZone};
5
6impl Scalar {
7    #[cfg(feature = "dtype-date")]
8    pub fn new_date(value: i32) -> Self {
9        Scalar::new(DataType::Date, AnyValue::Date(value))
10    }
11
12    #[cfg(feature = "dtype-datetime")]
13    pub fn new_datetime(value: i64, time_unit: TimeUnit, tz: Option<TimeZone>) -> Self {
14        Scalar::new(
15            DataType::Datetime(time_unit, tz.clone()),
16            AnyValue::DatetimeOwned(value, time_unit, tz.map(Arc::new)),
17        )
18    }
19
20    #[cfg(feature = "dtype-duration")]
21    pub fn new_duration(value: i64, time_unit: TimeUnit) -> Self {
22        Scalar::new(
23            DataType::Duration(time_unit),
24            AnyValue::Duration(value, time_unit),
25        )
26    }
27}