From f7eb162e91ac48575cba6afc0ef8a6926d35223c Mon Sep 17 00:00:00 2001 From: Orson Peters Date: Thu, 17 Oct 2024 00:08:57 +0200 Subject: [PATCH] delete more stuff --- .../polars-arrow/src/legacy/kernels/atan2.rs | 12 ----- .../polars-arrow/src/legacy/kernels/float.rs | 54 ------------------- crates/polars-arrow/src/legacy/kernels/mod.rs | 2 - crates/polars-core/src/chunked_array/float.rs | 9 ++-- .../src/dsl/function_expr/trigonometry.rs | 22 ++------ 5 files changed, 8 insertions(+), 91 deletions(-) delete mode 100644 crates/polars-arrow/src/legacy/kernels/atan2.rs delete mode 100644 crates/polars-arrow/src/legacy/kernels/float.rs diff --git a/crates/polars-arrow/src/legacy/kernels/atan2.rs b/crates/polars-arrow/src/legacy/kernels/atan2.rs deleted file mode 100644 index 40d3d527b24a..000000000000 --- a/crates/polars-arrow/src/legacy/kernels/atan2.rs +++ /dev/null @@ -1,12 +0,0 @@ -use num_traits::Float; - -use crate::array::PrimitiveArray; -use crate::compute::arity::binary; -use crate::types::NativeType; - -pub fn atan2(arr_1: &PrimitiveArray, arr_2: &PrimitiveArray) -> PrimitiveArray -where - T: Float + NativeType, -{ - binary(arr_1, arr_2, arr_1.dtype().clone(), |a, b| a.atan2(b)) -} diff --git a/crates/polars-arrow/src/legacy/kernels/float.rs b/crates/polars-arrow/src/legacy/kernels/float.rs deleted file mode 100644 index 22413fd0b4c5..000000000000 --- a/crates/polars-arrow/src/legacy/kernels/float.rs +++ /dev/null @@ -1,54 +0,0 @@ -use num_traits::Float; - -use crate::array::{ArrayRef, BooleanArray, PrimitiveArray}; -use crate::bitmap::Bitmap; -use crate::legacy::array::default_arrays::FromData; -use crate::types::NativeType; - -pub fn is_nan(arr: &PrimitiveArray) -> ArrayRef -where - T: NativeType + Float, -{ - let values = Bitmap::from_trusted_len_iter(arr.values().iter().map(|v| v.is_nan())); - - Box::new(BooleanArray::from_data_default( - values, - arr.validity().cloned(), - )) -} - -pub fn is_not_nan(arr: &PrimitiveArray) -> ArrayRef -where - T: NativeType + Float, -{ - let values = Bitmap::from_trusted_len_iter(arr.values().iter().map(|v| !v.is_nan())); - - Box::new(BooleanArray::from_data_default( - values, - arr.validity().cloned(), - )) -} - -pub fn is_finite(arr: &PrimitiveArray) -> ArrayRef -where - T: NativeType + Float, -{ - let values = Bitmap::from_trusted_len_iter(arr.values().iter().map(|v| v.is_finite())); - - Box::new(BooleanArray::from_data_default( - values, - arr.validity().cloned(), - )) -} - -pub fn is_infinite(arr: &PrimitiveArray) -> ArrayRef -where - T: NativeType + Float, -{ - let values = Bitmap::from_trusted_len_iter(arr.values().iter().map(|v| v.is_infinite())); - - Box::new(BooleanArray::from_data_default( - values, - arr.validity().cloned(), - )) -} diff --git a/crates/polars-arrow/src/legacy/kernels/mod.rs b/crates/polars-arrow/src/legacy/kernels/mod.rs index cdb7cb9c2057..dcc99b8e372f 100644 --- a/crates/polars-arrow/src/legacy/kernels/mod.rs +++ b/crates/polars-arrow/src/legacy/kernels/mod.rs @@ -2,12 +2,10 @@ use std::iter::Enumerate; use crate::array::BooleanArray; use crate::bitmap::utils::BitChunks; -pub mod atan2; pub mod concatenate; pub mod ewm; #[cfg(feature = "compute_take")] pub mod fixed_size_list; -pub mod float; #[cfg(feature = "compute_take")] pub mod list; pub mod pow; diff --git a/crates/polars-core/src/chunked_array/float.rs b/crates/polars-core/src/chunked_array/float.rs index 8376629cc403..5d9bae240062 100644 --- a/crates/polars-core/src/chunked_array/float.rs +++ b/crates/polars-core/src/chunked_array/float.rs @@ -1,4 +1,3 @@ -use arrow::legacy::kernels::float::*; use arrow::legacy::kernels::set::set_at_nulls; use num_traits::Float; use polars_utils::total_ord::{canonical_f32, canonical_f64}; @@ -12,16 +11,16 @@ where T::Native: Float, { pub fn is_nan(&self) -> BooleanChunked { - self.apply_kernel_cast(&is_nan::) + unary_elementwise_values(self, |x| x.is_nan()) } pub fn is_not_nan(&self) -> BooleanChunked { - self.apply_kernel_cast(&is_not_nan::) + unary_elementwise_values(self, |x| !x.is_nan()) } pub fn is_finite(&self) -> BooleanChunked { - self.apply_kernel_cast(&is_finite) + unary_elementwise_values(self, |x| x.is_finite()) } pub fn is_infinite(&self) -> BooleanChunked { - self.apply_kernel_cast(&is_infinite) + unary_elementwise_values(self, |x| x.is_infinite()) } #[must_use] diff --git a/crates/polars-plan/src/dsl/function_expr/trigonometry.rs b/crates/polars-plan/src/dsl/function_expr/trigonometry.rs index c0d83822aef9..5398f43f4323 100644 --- a/crates/polars-plan/src/dsl/function_expr/trigonometry.rs +++ b/crates/polars-plan/src/dsl/function_expr/trigonometry.rs @@ -1,5 +1,5 @@ -use arrow::legacy::kernels::atan2::atan2 as atan2_kernel; use num::Float; +use polars_core::chunked_array::ops::arity::broadcast_binary_elementwise; use polars_core::export::num; use super::*; @@ -117,23 +117,9 @@ where .unpack_series_matching_type(x.as_materialized_series()) .unwrap(); - if x.len() == 1 { - let x_value = x - .get(0) - .ok_or_else(|| polars_err!(ComputeError: "arctan2 x value is null"))?; - - Ok(Some(y.apply_values(|v| v.atan2(x_value)).into_column())) - } else if y.len() == 1 { - let y_value = y - .get(0) - .ok_or_else(|| polars_err!(ComputeError: "arctan2 y value is null"))?; - - Ok(Some(x.apply_values(|v| y_value.atan2(v)).into_column())) - } else { - Ok(Some( - polars_core::prelude::arity::binary(y, x, atan2_kernel).into_column(), - )) - } + Ok(Some( + broadcast_binary_elementwise(y, x, |yv, xv| Some(yv?.atan2(xv?))).into_column(), + )) } fn apply_trigonometric_function_to_float(