From 53dca1fca01bba03f020f74314a0c6d5a1c5b224 Mon Sep 17 00:00:00 2001 From: Piotr Findeisen Date: Mon, 2 Dec 2024 14:57:21 +0100 Subject: [PATCH] Remove deprecated unary_dyn and try_unary_dyn `unary_dyn` and `try_unary_dyn` were deprecated since v 46.0.0. Remove them along with utility functions used in their implementations. --- arrow-arith/src/arity.rs | 142 +-------------------------------------- 1 file changed, 1 insertion(+), 141 deletions(-) diff --git a/arrow-arith/src/arity.rs b/arrow-arith/src/arity.rs index a6f5780056a..9b3272abb61 100644 --- a/arrow-arith/src/arity.rs +++ b/arrow-arith/src/arity.rs @@ -18,14 +18,12 @@ //! Kernels for operating on [`PrimitiveArray`]s use arrow_array::builder::BufferBuilder; -use arrow_array::types::ArrowDictionaryKeyType; use arrow_array::*; use arrow_buffer::buffer::NullBuffer; use arrow_buffer::ArrowNativeType; use arrow_buffer::{Buffer, MutableBuffer}; use arrow_data::ArrayData; use arrow_schema::ArrowError; -use std::sync::Arc; /// See [`PrimitiveArray::unary`] pub fn unary(array: &PrimitiveArray, op: F) -> PrimitiveArray @@ -71,97 +69,6 @@ where array.try_unary_mut(op) } -/// A helper function that applies an infallible unary function to a dictionary array with primitive value type. -fn unary_dict(array: &DictionaryArray, op: F) -> Result -where - K: ArrowDictionaryKeyType + ArrowNumericType, - T: ArrowPrimitiveType, - F: Fn(T::Native) -> T::Native, -{ - let dict_values = array.values().as_any().downcast_ref().unwrap(); - let values = unary::(dict_values, op); - Ok(Arc::new(array.with_values(Arc::new(values)))) -} - -/// A helper function that applies a fallible unary function to a dictionary array with primitive value type. -fn try_unary_dict(array: &DictionaryArray, op: F) -> Result -where - K: ArrowDictionaryKeyType + ArrowNumericType, - T: ArrowPrimitiveType, - F: Fn(T::Native) -> Result, -{ - if !PrimitiveArray::::is_compatible(&array.value_type()) { - return Err(ArrowError::CastError(format!( - "Cannot perform the unary operation of type {} on dictionary array of value type {}", - T::DATA_TYPE, - array.value_type() - ))); - } - - let dict_values = array.values().as_any().downcast_ref().unwrap(); - let values = try_unary::(dict_values, op)?; - Ok(Arc::new(array.with_values(Arc::new(values)))) -} - -/// Applies an infallible unary function to an array with primitive values. -#[deprecated(since = "46.0.0", note = "Use arrow_array::AnyDictionaryArray")] -pub fn unary_dyn(array: &dyn Array, op: F) -> Result -where - T: ArrowPrimitiveType, - F: Fn(T::Native) -> T::Native, -{ - downcast_dictionary_array! { - array => unary_dict::<_, F, T>(array, op), - t => { - if PrimitiveArray::::is_compatible(t) { - Ok(Arc::new(unary::( - array.as_any().downcast_ref::>().unwrap(), - op, - ))) - } else { - Err(ArrowError::NotYetImplemented(format!( - "Cannot perform unary operation of type {} on array of type {}", - T::DATA_TYPE, - t - ))) - } - } - } -} - -/// Applies a fallible unary function to an array with primitive values. -#[deprecated(since = "46.0.0", note = "Use arrow_array::AnyDictionaryArray")] -pub fn try_unary_dyn(array: &dyn Array, op: F) -> Result -where - T: ArrowPrimitiveType, - F: Fn(T::Native) -> Result, -{ - downcast_dictionary_array! { - array => if array.values().data_type() == &T::DATA_TYPE { - try_unary_dict::<_, F, T>(array, op) - } else { - Err(ArrowError::NotYetImplemented(format!( - "Cannot perform unary operation on dictionary array of type {}", - array.data_type() - ))) - }, - t => { - if PrimitiveArray::::is_compatible(t) { - Ok(Arc::new(try_unary::( - array.as_any().downcast_ref::>().unwrap(), - op, - )?)) - } else { - Err(ArrowError::NotYetImplemented(format!( - "Cannot perform unary operation of type {} on array of type {}", - T::DATA_TYPE, - t - ))) - } - } - } -} - /// Allies a binary infallable function to two [`PrimitiveArray`]s, /// producing a new [`PrimitiveArray`] /// @@ -510,8 +417,8 @@ where #[cfg(test)] mod tests { use super::*; - use arrow_array::builder::*; use arrow_array::types::*; + use std::sync::Arc; #[test] #[allow(deprecated)] @@ -523,53 +430,6 @@ mod tests { result, Float64Array::from(vec![None, Some(7.0), None, Some(7.0)]) ); - - let result = unary_dyn::<_, Float64Type>(&input_slice, |n| n + 1.0).unwrap(); - - assert_eq!( - result.as_any().downcast_ref::().unwrap(), - &Float64Array::from(vec![None, Some(7.8), None, Some(8.2)]) - ); - } - - #[test] - #[allow(deprecated)] - fn test_unary_dict_and_unary_dyn() { - let mut builder = PrimitiveDictionaryBuilder::::new(); - builder.append(5).unwrap(); - builder.append(6).unwrap(); - builder.append(7).unwrap(); - builder.append(8).unwrap(); - builder.append_null(); - builder.append(9).unwrap(); - let dictionary_array = builder.finish(); - - let mut builder = PrimitiveDictionaryBuilder::::new(); - builder.append(6).unwrap(); - builder.append(7).unwrap(); - builder.append(8).unwrap(); - builder.append(9).unwrap(); - builder.append_null(); - builder.append(10).unwrap(); - let expected = builder.finish(); - - let result = unary_dict::<_, _, Int32Type>(&dictionary_array, |n| n + 1).unwrap(); - assert_eq!( - result - .as_any() - .downcast_ref::>() - .unwrap(), - &expected - ); - - let result = unary_dyn::<_, Int32Type>(&dictionary_array, |n| n + 1).unwrap(); - assert_eq!( - result - .as_any() - .downcast_ref::>() - .unwrap(), - &expected - ); } #[test]