From 8463def11dff7ca01de62c562691e616e1edb983 Mon Sep 17 00:00:00 2001 From: Ritchie Vink Date: Tue, 17 Oct 2023 11:32:26 +0400 Subject: [PATCH] fix: fix key in object-store cache (#11790) --- .../polars-io/src/cloud/object_store_setup.rs | 8 ++-- crates/polars-ops/src/series/ops/cum_agg.rs | 38 ------------------- .../polars-ops/src/series/ops/pct_change.rs | 37 ------------------ 3 files changed, 4 insertions(+), 79 deletions(-) diff --git a/crates/polars-io/src/cloud/object_store_setup.rs b/crates/polars-io/src/cloud/object_store_setup.rs index 91119dbbf248..be7c4a28d822 100644 --- a/crates/polars-io/src/cloud/object_store_setup.rs +++ b/crates/polars-io/src/cloud/object_store_setup.rs @@ -4,7 +4,7 @@ use tokio::sync::RwLock; use super::*; -type CacheKey = (CloudType, Option); +type CacheKey = (String, Option); /// A very simple cache that only stores a single object-store. /// This greatly reduces the query times as multiple object stores (when reading many small files) @@ -34,9 +34,8 @@ fn err_missing_configuration(feature: &str, scheme: &str) -> BuildResult { pub async fn build_object_store(url: &str, options: Option<&CloudOptions>) -> BuildResult { let cloud_location = CloudLocation::new(url)?; - let cloud_type = CloudType::from_str(url)?; let options = options.cloned(); - let key = (cloud_type, options); + let key = (url.to_string(), options); { let cache = OBJECT_STORE_CACHE.read().await; @@ -47,7 +46,8 @@ pub async fn build_object_store(url: &str, options: Option<&CloudOptions>) -> Bu } } - let store = match key.0 { + let cloud_type = CloudType::from_str(url)?; + let store = match cloud_type { CloudType::File => { let local = LocalFileSystem::new(); Ok::<_, PolarsError>(Arc::new(local) as Arc) diff --git a/crates/polars-ops/src/series/ops/cum_agg.rs b/crates/polars-ops/src/series/ops/cum_agg.rs index 12faeb193ac5..70fb1a0bfcf6 100644 --- a/crates/polars-ops/src/series/ops/cum_agg.rs +++ b/crates/polars-ops/src/series/ops/cum_agg.rs @@ -228,41 +228,3 @@ pub fn cumcount(s: &Series, reverse: bool) -> PolarsResult { Ok(ca.into_series()) } } - -#[cfg(test)] -mod test { - use polars_core::prelude::*; - - #[test] - #[cfg(feature = "dtype-u8")] - fn test_cummax() { - let ca = UInt8Chunked::new("foo", &[None, Some(1), Some(3), None, Some(1)]); - let out = ca.cummax(true); - assert_eq!(Vec::from(&out), &[None, Some(3), Some(3), None, Some(1)]); - let out = ca.cummax(false); - assert_eq!(Vec::from(&out), &[None, Some(1), Some(3), None, Some(3)]); - } - - #[test] - #[cfg(feature = "dtype-u8")] - fn test_cummin() { - let ca = UInt8Chunked::new("foo", &[None, Some(1), Some(3), None, Some(2)]); - let out = ca.cummin(true); - assert_eq!(Vec::from(&out), &[None, Some(1), Some(2), None, Some(2)]); - let out = ca.cummin(false); - assert_eq!(Vec::from(&out), &[None, Some(1), Some(1), None, Some(1)]); - } - - #[test] - fn test_cumsum() { - let ca = Int32Chunked::new("foo", &[None, Some(1), Some(3), None, Some(1)]); - let out = ca.cumsum(true); - assert_eq!(Vec::from(&out), &[None, Some(5), Some(4), None, Some(1)]); - let out = ca.cumsum(false); - assert_eq!(Vec::from(&out), &[None, Some(1), Some(4), None, Some(5)]); - - // just check if the trait bounds allow for floats - let ca = Float32Chunked::new("foo", &[None, Some(1.0), Some(3.0), None, Some(1.0)]); - let _out = ca.cumsum(false); - } -} diff --git a/crates/polars-ops/src/series/ops/pct_change.rs b/crates/polars-ops/src/series/ops/pct_change.rs index bd03bdd67e05..24df891b382e 100644 --- a/crates/polars-ops/src/series/ops/pct_change.rs +++ b/crates/polars-ops/src/series/ops/pct_change.rs @@ -23,40 +23,3 @@ pub fn pct_change(s: &Series, n: &Series) -> PolarsResult { Ok(Series::full_null(s.name(), s.len(), s.dtype())) } } - -#[cfg(test)] -mod test { - use polars_core::prelude::Series; - - use super::pct_change; - - #[test] - fn test_nulls() -> PolarsResult<()> { - let s = Series::new("", &[Some(1), None, Some(2), None, Some(3)]); - assert_eq!( - pct_change(s, Series::new("i", &[1]))?, - Series::new("", &[None, Some(0.0f64), Some(1.0), Some(0.), Some(0.5)]) - ); - Ok(()) - } - - #[test] - fn test_same() -> PolarsResult<()> { - let s = Series::new("", &[Some(1), Some(1), Some(1)]); - assert_eq!( - pct_change(s, Series::new("i", &[1]))?, - Series::new("", &[None, Some(0.0f64), Some(0.0)]) - ); - Ok(()) - } - - #[test] - fn test_two_periods() -> PolarsResult<()> { - let s = Series::new("", &[Some(1), Some(2), Some(4), Some(8), Some(16)]); - assert_eq!( - pct_change(s, Series::new("i", &[2]))?, - Series::new("", &[None, None, Some(3.0f64), Some(3.0), Some(3.0)]) - ); - Ok(()) - } -}