Skip to content

Commit

Permalink
Remove unused
Browse files Browse the repository at this point in the history
  • Loading branch information
mcrumiller committed Sep 18, 2024
1 parent 3a9fa0a commit 3cc6a38
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions crates/polars-ops/src/chunked_array/hist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,23 @@ where
let min_break: f64 = breaks[0];
let max_break: f64 = breaks[num_bins];
let width = breaks[1] - min_break; // guaranteed at least one bin
let is_integer = !T::get_dtype().is_float();

for chunk in ca.downcast_iter() {
for item in chunk.non_null_values_iter() {
let item = item.to_f64().unwrap();
if include_lower && item == min_break {
count[0] += 1;
} else if item > min_break && item <= max_break {
let idx = ((item - min_break) / width).ceil() as usize - 1;
// Due to floating-point precision, the last item may sometimes exceed the bin size
count[std::cmp::min(idx, num_bins - 1)] += 1;
let idx = (item - min_break) / width;
// This is needed for numeric stability for integers.
// We can fall directly on a boundary with an integer.
let idx = if is_integer && (idx.round() - idx).abs() < 0.0000001 {
idx.round() - 1.0
} else {
idx.ceil() - 1.0
};
count[idx as usize] += 1;
}
}
}
Expand Down

0 comments on commit 3cc6a38

Please sign in to comment.