Skip to main content

polars_core/utils/
cut.rs

1use polars_error::PolarsResult;
2use polars_utils::format_pl_smallstr;
3use polars_utils::pl_str::PlSmallStr;
4
5pub fn compute_cut_labels(breaks: &[f64], left_closed: bool) -> PolarsResult<Vec<PlSmallStr>> {
6    let lo = std::iter::once(&f64::NEG_INFINITY).chain(breaks.iter());
7    let hi = breaks.iter().chain(std::iter::once(&f64::INFINITY));
8
9    let ret = lo
10        .zip(hi)
11        .map(|(l, h)| {
12            if left_closed {
13                format_pl_smallstr!("[{}, {})", l, h)
14            } else {
15                format_pl_smallstr!("({}, {}]", l, h)
16            }
17        })
18        .collect();
19    Ok(ret)
20}