Path: blob/main/crates/polars-plan/src/dsl/function_expr/range.rs
6940 views
use std::fmt;12use polars_core::prelude::*;3use polars_ops::series::ClosedInterval;4#[cfg(feature = "temporal")]5use polars_time::{ClosedWindow, Duration};6#[cfg(feature = "serde")]7use serde::{Deserialize, Serialize};89use super::{DataTypeExpr, FunctionExpr};1011#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]12#[cfg_attr(feature = "dsl-schema", derive(schemars::JsonSchema))]13#[derive(Clone, PartialEq, Debug, Hash)]14pub enum RangeFunction {15IntRange {16step: i64,17dtype: DataTypeExpr,18},19IntRanges {20dtype: DataTypeExpr,21},22LinearSpace {23closed: ClosedInterval,24},25LinearSpaces {26closed: ClosedInterval,27array_width: Option<usize>,28},29#[cfg(feature = "dtype-date")]30DateRange {31interval: Duration,32closed: ClosedWindow,33},34#[cfg(feature = "dtype-date")]35DateRanges {36interval: Duration,37closed: ClosedWindow,38},39#[cfg(feature = "dtype-datetime")]40DatetimeRange {41interval: Duration,42closed: ClosedWindow,43time_unit: Option<TimeUnit>,44time_zone: Option<TimeZone>,45},46#[cfg(feature = "dtype-datetime")]47DatetimeRanges {48interval: Duration,49closed: ClosedWindow,50time_unit: Option<TimeUnit>,51time_zone: Option<TimeZone>,52},53#[cfg(feature = "dtype-time")]54TimeRange {55interval: Duration,56closed: ClosedWindow,57},58#[cfg(feature = "dtype-time")]59TimeRanges {60interval: Duration,61closed: ClosedWindow,62},63}6465impl From<RangeFunction> for FunctionExpr {66fn from(value: RangeFunction) -> Self {67Self::Range(value)68}69}7071impl fmt::Display for RangeFunction {72fn fmt(&self, f: &mut fmt::Formatter<'_>) -> std::fmt::Result {73use RangeFunction::*;74let s = match self {75IntRange { .. } => "int_range",76IntRanges { .. } => "int_ranges",77LinearSpace { .. } => "linear_space",78LinearSpaces { .. } => "linear_spaces",79#[cfg(feature = "dtype-date")]80DateRange { .. } => "date_range",81#[cfg(feature = "temporal")]82DateRanges { .. } => "date_ranges",83#[cfg(feature = "dtype-datetime")]84DatetimeRange { .. } => "datetime_range",85#[cfg(feature = "dtype-datetime")]86DatetimeRanges { .. } => "datetime_ranges",87#[cfg(feature = "dtype-time")]88TimeRange { .. } => "time_range",89#[cfg(feature = "dtype-time")]90TimeRanges { .. } => "time_ranges",91};92write!(f, "{s}")93}94}959697