Skip to content

Commit

Permalink
fix(rust): don't return NaN as free memory fraction (pola-rs#13860)
Browse files Browse the repository at this point in the history
  • Loading branch information
ByteNybbler authored and r-brink committed Jan 24, 2024
1 parent 40d923e commit e619dbb
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 e619dbb

Please sign in to comment.