From aade2ec34d0144f1a5ce3e6ea5c3f1b936aeae85 Mon Sep 17 00:00:00 2001 From: James Tomlinson Date: Thu, 25 Apr 2024 12:47:22 +0100 Subject: [PATCH] feat: Upgrade polars to v0.39 This uses the new sorting API. --- Cargo.toml | 2 +- pywr-schema/src/timeseries/align_and_resample.rs | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e6e525a1..9beaa0dd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -39,7 +39,7 @@ thiserror = "1.0.25" num = "0.4.0" float-cmp = "0.9.0" ndarray = "0.15.3" -polars = { version = "0.38.1", features = ["lazy", "rows", "ndarray"] } +polars = { version = "0.39", features = ["lazy", "rows", "ndarray"] } pyo3-polars = "0.12.0" pyo3 = { version = "0.20.2", default-features = false } pyo3-log = "0.9.0" diff --git a/pywr-schema/src/timeseries/align_and_resample.rs b/pywr-schema/src/timeseries/align_and_resample.rs index bbd1830b..e91390c2 100644 --- a/pywr-schema/src/timeseries/align_and_resample.rs +++ b/pywr-schema/src/timeseries/align_and_resample.rs @@ -11,12 +11,16 @@ pub fn align_and_resample( domain: &ModelDomain, ) -> Result { // Ensure type of time column is datetime and that it is sorted + let sort_options = SortMultipleOptions::default() + .with_order_descending(false) + .with_maintain_order(true); + let df = df .clone() .lazy() .with_columns([col(time_col).cast(DataType::Datetime(TimeUnit::Nanoseconds, None))]) .collect()? - .sort([time_col], false, true)?; + .sort([time_col], sort_options)?; // Ensure that df start aligns with models start for any resampling let df = slice_start(df, time_col, domain)?;