Skip to content

Commit

Permalink
fix: fix key in object-store cache (#11790)
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 authored Oct 17, 2023
1 parent 4476fbd commit 8463def
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 79 deletions.
8 changes: 4 additions & 4 deletions crates/polars-io/src/cloud/object_store_setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use tokio::sync::RwLock;

use super::*;

type CacheKey = (CloudType, Option<CloudOptions>);
type CacheKey = (String, Option<CloudOptions>);

/// 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)
Expand Down Expand Up @@ -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;
Expand All @@ -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<dyn ObjectStore>)
Expand Down
38 changes: 0 additions & 38 deletions crates/polars-ops/src/series/ops/cum_agg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,41 +228,3 @@ pub fn cumcount(s: &Series, reverse: bool) -> PolarsResult<Series> {
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);
}
}
37 changes: 0 additions & 37 deletions crates/polars-ops/src/series/ops/pct_change.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,40 +23,3 @@ pub fn pct_change(s: &Series, n: &Series) -> PolarsResult<Series> {
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(())
}
}

0 comments on commit 8463def

Please sign in to comment.