Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoGorelli committed May 31, 2024
1 parent 5017402 commit 4d7edd4
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions crates/polars-time/src/truncate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ impl PolarsTruncate for DatetimeChunked {
}
}
}
let mut duration_cache = match duration_cache_opt {
Some(cache) => cache,
None => FastFixedCache::new((every.len() as f64).sqrt() as usize),
};

let func = match self.time_unit() {
TimeUnit::Nanoseconds => Window::truncate_ns,
Expand All @@ -71,10 +75,8 @@ impl PolarsTruncate for DatetimeChunked {
opt_every,
) {
(Some(timestamp), Some(every)) => {
let every = duration_cache_opt
.as_mut()
.map(|cache| *cache.get_or_insert_with(every, |every| Duration::parse(every)))
.unwrap();
let every =
*duration_cache.get_or_insert_with(every, |every| Duration::parse(every));

if every.negative {
polars_bail!(ComputeError: "cannot truncate a Datetime to a negative duration")
Expand Down

0 comments on commit 4d7edd4

Please sign in to comment.