Path: blob/main/crates/polars-ops/src/series/ops/floor_divide.rs
6939 views
use polars_compute::arithmetic::ArithmeticKernel;1use polars_core::chunked_array::ops::arity::apply_binary_kernel_broadcast;2use polars_core::prelude::*;3#[cfg(feature = "dtype-struct")]4use polars_core::series::arithmetic::_struct_arithmetic;5use polars_core::series::arithmetic::NumericListOp;6use polars_core::with_match_physical_numeric_polars_type;78fn floor_div_ca<T: PolarsNumericType>(9lhs: &ChunkedArray<T>,10rhs: &ChunkedArray<T>,11) -> ChunkedArray<T> {12apply_binary_kernel_broadcast(13lhs,14rhs,15|l, r| ArithmeticKernel::wrapping_floor_div(l.clone(), r.clone()),16|l, r| ArithmeticKernel::wrapping_floor_div_scalar_lhs(l, r.clone()),17|l, r| ArithmeticKernel::wrapping_floor_div_scalar(l.clone(), r),18)19}2021pub fn floor_div_series(a: &Series, b: &Series) -> PolarsResult<Series> {22match (a.dtype(), b.dtype()) {23#[cfg(feature = "dtype-struct")]24(DataType::Struct(_), DataType::Struct(_)) => {25return _struct_arithmetic(a, b, floor_div_series);26},27(DataType::List(_), _) | (_, DataType::List(_)) => {28return NumericListOp::floor_div().execute(a, b);29},30#[cfg(feature = "dtype-array")]31(DataType::Array(..), _) | (_, DataType::Array(..)) => {32return polars_core::series::arithmetic::NumericFixedSizeListOp::floor_div()33.execute(a, b);34},35_ => {},36}3738if !a.dtype().is_primitive_numeric() {39polars_bail!(op = "floor_div", a.dtype());40}4142let logical_type = a.dtype();4344let a = a.to_physical_repr();45let b = b.to_physical_repr();4647let out = with_match_physical_numeric_polars_type!(a.dtype(), |$T| {48let a: &ChunkedArray<$T> = a.as_ref().as_ref().as_ref();49let b: &ChunkedArray<$T> = b.as_ref().as_ref().as_ref();5051floor_div_ca(a, b).into_series()52});5354unsafe { out.from_physical_unchecked(logical_type) }55}565758