polars_ops/series/ops/
not.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use std::ops::Not;

use polars_core::with_match_physical_integer_polars_type;

use super::*;

pub fn negate_bitwise(s: &Series) -> PolarsResult<Series> {
    match s.dtype() {
        DataType::Boolean => Ok(s.bool().unwrap().not().into_series()),
        dt if dt.is_integer() => {
            with_match_physical_integer_polars_type!(dt, |$T| {
                let ca: &ChunkedArray<$T> = s.as_any().downcast_ref().unwrap();
                Ok(ca.apply_values(|v| !v).into_series())
            })
        },
        dt => polars_bail!(InvalidOperation: "dtype {:?} not supported in 'not' operation", dt),
    }
}