Skip to content

Commit

Permalink
fix(rust): don't return NaN as free memory fraction (#13860)
Browse files Browse the repository at this point in the history
  • Loading branch information
ByteNybbler committed Jan 22, 2024
1 parent 988a15a commit 08bfbca
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions crates/polars-pipe/src/executors/sinks/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@ impl MemTracker {
}

pub(super) fn free_memory_fraction_since_start(&self) -> f64 {
// we divide first to reduce the precision loss in floats
let available_at_start = (self.available_at_start / TO_MB) as f64;
// We divide first to reduce the precision loss in floats.
// We also add 1.0 to available_at_start to prevent division by zero.
let available_at_start = (self.available_at_start / TO_MB) as f64 + 1.0;
let available = (self.get_available() / TO_MB) as f64;
available / available_at_start
}
Expand Down

0 comments on commit 08bfbca

Please sign in to comment.