Skip to content

Commit

Permalink
cleanup feature flags (#13823)
Browse files Browse the repository at this point in the history
  • Loading branch information
flisky authored Jan 19, 2024
1 parent 713ec01 commit 8129d2c
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 37 deletions.
2 changes: 1 addition & 1 deletion crates/polars-lazy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ dtype-decimal = ["polars-plan/dtype-decimal", "polars-pipe?/dtype-decimal"]
dtype-date = ["polars-plan/dtype-date", "polars-time/dtype-date", "temporal"]
dtype-datetime = ["polars-plan/dtype-datetime", "polars-time/dtype-datetime", "temporal"]
dtype-duration = ["polars-plan/dtype-duration", "polars-time/dtype-duration", "temporal"]
dtype-time = ["polars-core/dtype-time", "temporal"]
dtype-time = ["polars-plan/dtype-time", "polars-time/dtype-time", "temporal"]
dtype-array = ["polars-plan/dtype-array", "polars-pipe?/dtype-array", "polars-ops/dtype-array"]
dtype-categorical = ["polars-plan/dtype-categorical", "polars-pipe?/dtype-categorical"]
dtype-struct = ["polars-plan/dtype-struct"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ impl PhysicalExpr for LiteralExpr {
Date(v) => Int32Chunked::full(LITERAL_NAME, *v, 1)
.into_date()
.into_series(),
#[cfg(feature = "dtype-datetime")]
#[cfg(feature = "dtype-time")]
Time(v) => Int64Chunked::full(LITERAL_NAME, *v, 1)
.into_time()
.into_series(),
Expand Down
15 changes: 11 additions & 4 deletions crates/polars-plan/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,14 @@ cloud = ["async", "polars-io/cloud"]
ipc = ["polars-io/ipc"]
json = ["polars-io/json", "polars-json"]
csv = ["polars-io/csv"]
temporal = ["polars-core/temporal", "dtype-date", "dtype-datetime", "dtype-time", "dtype-i8", "dtype-i16"]
temporal = [
"polars-core/temporal",
"polars-core/dtype-date",
"polars-core/dtype-datetime",
"polars-core/dtype-time",
"polars-core/dtype-i8",
"polars-core/dtype-i16",
]
# debugging purposes
fmt = ["polars-core/fmt"]
strings = ["polars-core/strings", "polars-ops/strings"]
Expand All @@ -69,10 +76,10 @@ dtype-u16 = ["polars-core/dtype-u16"]
dtype-i8 = ["polars-core/dtype-i8"]
dtype-i16 = ["polars-core/dtype-i16"]
dtype-decimal = ["polars-core/dtype-decimal"]
dtype-date = ["polars-core/dtype-date", "polars-time/dtype-date", "temporal"]
dtype-datetime = ["polars-core/dtype-datetime", "polars-time/dtype-datetime", "temporal"]
dtype-date = ["polars-time/dtype-date", "temporal"]
dtype-datetime = ["polars-time/dtype-datetime", "temporal"]
dtype-duration = ["polars-core/dtype-duration", "polars-time/dtype-duration", "temporal"]
dtype-time = ["polars-core/dtype-time", "polars-time/dtype-time"]
dtype-time = ["polars-time/dtype-time", "temporal"]
dtype-array = ["polars-core/dtype-array", "polars-ops/dtype-array"]
dtype-categorical = ["polars-core/dtype-categorical"]
dtype-struct = ["polars-core/dtype-struct"]
Expand Down
3 changes: 3 additions & 0 deletions crates/polars-plan/src/dsl/function_expr/strings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -554,10 +554,13 @@ pub(super) fn strptime(
options: &StrptimeOptions,
) -> PolarsResult<Series> {
match dtype {
#[cfg(feature = "dtype-date")]
DataType::Date => to_date(&s[0], options),
#[cfg(feature = "dtype-datetime")]
DataType::Datetime(time_unit, time_zone) => {
to_datetime(s, &time_unit, time_zone.as_ref(), options)
},
#[cfg(feature = "dtype-time")]
DataType::Time => to_time(&s[0], options),
dt => polars_bail!(ComputeError: "not implemented for dtype {}", dt),
}
Expand Down
20 changes: 10 additions & 10 deletions crates/polars-plan/src/logical_plan/lit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,11 @@ impl LiteralValue {
LiteralValue::String(_) => DataType::String,
LiteralValue::Binary(_) => DataType::Binary,
LiteralValue::Range { data_type, .. } => data_type.clone(),
#[cfg(all(feature = "temporal", feature = "dtype-date"))]
#[cfg(feature = "dtype-date")]
LiteralValue::Date(_) => DataType::Date,
#[cfg(all(feature = "temporal", feature = "dtype-datetime"))]
#[cfg(feature = "dtype-datetime")]
LiteralValue::DateTime(_, tu, tz) => DataType::Datetime(*tu, tz.clone()),
#[cfg(all(feature = "temporal", feature = "dtype-duration"))]
#[cfg(feature = "dtype-duration")]
LiteralValue::Duration(_, tu) => DataType::Duration(*tu),
LiteralValue::Series(s) => s.dtype().clone(),
LiteralValue::Null => DataType::Null,
Expand Down Expand Up @@ -190,13 +190,13 @@ impl TryFrom<AnyValue<'_>> for LiteralValue {
AnyValue::Int64(i) => Ok(Self::Int64(i)),
AnyValue::Float32(f) => Ok(Self::Float32(f)),
AnyValue::Float64(f) => Ok(Self::Float64(f)),
#[cfg(all(feature = "temporal", feature = "dtype-datetime"))]
#[cfg(feature = "dtype-date")]
AnyValue::Date(v) => Ok(LiteralValue::Date(v)),
#[cfg(all(feature = "temporal", feature = "dtype-datetime"))]
#[cfg(feature = "dtype-datetime")]
AnyValue::Datetime(value, tu, tz) => Ok(LiteralValue::DateTime(value, tu, tz.clone())),
#[cfg(all(feature = "temporal", feature = "dtype-duration"))]
#[cfg(feature = "dtype-duration")]
AnyValue::Duration(value, tu) => Ok(LiteralValue::Duration(value, tu)),
#[cfg(all(feature = "temporal", feature = "dtype-datetime"))]
#[cfg(feature = "dtype-time")]
AnyValue::Time(v) => Ok(LiteralValue::Time(v)),
AnyValue::List(l) => Ok(Self::Series(SpecialEq::new(l))),
AnyValue::StringOwned(o) => Ok(Self::String(o.into())),
Expand Down Expand Up @@ -255,7 +255,7 @@ impl Literal for Null {
}
}

#[cfg(all(feature = "temporal", feature = "dtype-datetime"))]
#[cfg(feature = "dtype-datetime")]
impl Literal for NaiveDateTime {
fn lit(self) -> Expr {
if in_nanoseconds_window(&self) {
Expand All @@ -274,7 +274,7 @@ impl Literal for NaiveDateTime {
}
}

#[cfg(all(feature = "temporal", feature = "dtype-duration"))]
#[cfg(feature = "dtype-duration")]
impl Literal for ChronoDuration {
fn lit(self) -> Expr {
if let Some(value) = self.num_nanoseconds() {
Expand All @@ -288,7 +288,7 @@ impl Literal for ChronoDuration {
}
}

#[cfg(all(feature = "temporal", feature = "dtype-datetime"))]
#[cfg(feature = "dtype-datetime")]
impl Literal for NaiveDate {
fn lit(self) -> Expr {
self.and_hms_opt(0, 0, 0).unwrap().lit()
Expand Down
9 changes: 5 additions & 4 deletions crates/polars-time/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ serde = { workspace = true, features = ["derive"], optional = true }
smartstring = { workspace = true }

[features]
dtype-date = ["polars-core/dtype-date", "polars-core/temporal"]
dtype-datetime = ["polars-core/dtype-date", "polars-core/temporal"]
dtype-time = ["polars-core/dtype-time", "polars-core/temporal"]
dtype-duration = ["polars-core/dtype-duration", "polars-core/temporal"]
dtype-date = ["polars-core/dtype-date", "temporal"]
dtype-datetime = ["polars-core/dtype-datetime", "temporal"]
dtype-time = ["polars-core/dtype-time", "temporal"]
dtype-duration = ["polars-core/dtype-duration", "temporal"]
rolling_window = ["polars-core/rolling_window", "dtype-duration"]
fmt = ["polars-core/fmt"]
temporal = ["polars-core/temporal"]
timezones = ["chrono-tz", "dtype-datetime", "polars-core/timezones", "arrow/timezones", "polars-ops/timezones"]

test = ["dtype-date", "dtype-datetime", "polars-core/fmt"]
Expand Down
2 changes: 0 additions & 2 deletions crates/polars-time/src/round.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ pub trait PolarsRound {
Self: Sized;
}

#[cfg(feature = "dtype-datetime")]
impl PolarsRound for DatetimeChunked {
fn round(&self, every: Duration, offset: Duration, tz: Option<&Tz>) -> PolarsResult<Self> {
let w = Window::new(every, every, offset);
Expand All @@ -26,7 +25,6 @@ impl PolarsRound for DatetimeChunked {
}
}

#[cfg(feature = "dtype-date")]
impl PolarsRound for DateChunked {
fn round(&self, every: Duration, offset: Duration, _tz: Option<&Tz>) -> PolarsResult<Self> {
let w = Window::new(every, every, offset);
Expand Down
2 changes: 1 addition & 1 deletion crates/polars-time/src/series/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ pub trait TemporalMethods: AsSeries {
self.to_string(format)
}

#[cfg(all(feature = "dtype-date", feature = "dtype-datetime"))]
#[cfg(feature = "temporal")]
/// Convert date(time) object to timestamp in [`TimeUnit`].
fn timestamp(&self, tu: TimeUnit) -> PolarsResult<Int64Chunked> {
let s = self.as_series();
Expand Down
3 changes: 0 additions & 3 deletions crates/polars-time/src/truncate.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use arrow::legacy::time_zone::Tz;
#[cfg(feature = "dtype-date")]
use arrow::temporal_conversions::{MILLISECONDS, SECONDS_IN_DAY};
use polars_core::chunked_array::ops::arity::try_binary_elementwise;
use polars_core::prelude::*;
Expand All @@ -12,7 +11,6 @@ pub trait PolarsTruncate {
Self: Sized;
}

#[cfg(feature = "dtype-datetime")]
impl PolarsTruncate for DatetimeChunked {
fn truncate(&self, tz: Option<&Tz>, every: &StringChunked, offset: &str) -> PolarsResult<Self> {
let offset = Duration::parse(offset);
Expand Down Expand Up @@ -48,7 +46,6 @@ impl PolarsTruncate for DatetimeChunked {
}
}

#[cfg(feature = "dtype-date")]
impl PolarsTruncate for DateChunked {
fn truncate(
&self,
Expand Down
42 changes: 31 additions & 11 deletions crates/polars/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -242,42 +242,62 @@ dtype-slim = [
# opt-in datatypes for Series
dtype-date = [
"polars-core/dtype-date",
"polars-lazy?/dtype-date",
"polars-io/dtype-date",
"polars-lazy?/dtype-date",
"polars-time?/dtype-date",
"polars-core/dtype-date",
"polars-ops/dtype-date",
]
dtype-datetime = [
"polars-core/dtype-datetime",
"polars-lazy?/dtype-datetime",
"polars-io/dtype-datetime",
"polars-lazy?/dtype-datetime",
"polars-time?/dtype-datetime",
"polars-ops/dtype-datetime",
]
dtype-duration = [
"polars-core/dtype-duration",
"polars-lazy?/dtype-duration",
"polars-time?/dtype-duration",
"polars-core/dtype-duration",
"polars-ops/dtype-duration",
]
dtype-time = ["polars-core/dtype-time", "polars-io/dtype-time", "polars-time?/dtype-time", "polars-ops/dtype-time"]
dtype-time = [
"polars-core/dtype-time",
"polars-io/dtype-time",
"polars-lazy?/dtype-time",
"polars-time?/dtype-time",
"polars-ops/dtype-time",
]
dtype-array = [
"polars-core/dtype-array",
"polars-lazy?/dtype-array",
"polars-ops/dtype-array",
]
dtype-i8 = ["polars-core/dtype-i8", "polars-lazy?/dtype-i8", "polars-ops/dtype-i8"]
dtype-i16 = ["polars-core/dtype-i16", "polars-lazy?/dtype-i16", "polars-ops/dtype-i16"]
dtype-i8 = [
"polars-core/dtype-i8",
"polars-lazy?/dtype-i8",
"polars-ops/dtype-i8",
]
dtype-i16 = [
"polars-core/dtype-i16",
"polars-lazy?/dtype-i16",
"polars-ops/dtype-i16",
]
dtype-decimal = [
"polars-core/dtype-decimal",
"polars-io/dtype-decimal",
"polars-lazy?/dtype-decimal",
"polars-ops/dtype-decimal",
"polars-io/dtype-decimal",
]
dtype-u8 = ["polars-core/dtype-u8", "polars-lazy?/dtype-u8", "polars-ops/dtype-u8"]
dtype-u16 = ["polars-core/dtype-u16", "polars-lazy?/dtype-u16", "polars-ops/dtype-u16"]
dtype-u8 = [
"polars-core/dtype-u8",
"polars-lazy?/dtype-u8",
"polars-ops/dtype-u8",
]
dtype-u16 = [
"polars-core/dtype-u16",
"polars-lazy?/dtype-u16",
"polars-ops/dtype-u16",
]
dtype-categorical = [
"polars-core/dtype-categorical",
"polars-io/dtype-categorical",
Expand All @@ -286,9 +306,9 @@ dtype-categorical = [
]
dtype-struct = [
"polars-core/dtype-struct",
"polars-io/dtype-struct",
"polars-lazy?/dtype-struct",
"polars-ops/dtype-struct",
"polars-io/dtype-struct",
]
hist = ["polars-ops/hist", "polars-lazy/hist"]

Expand Down

0 comments on commit 8129d2c

Please sign in to comment.