Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Commit

Permalink
Reduced dependencies.
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgecarleitao committed Aug 28, 2021
1 parent 87aa617 commit 7a366b6
Show file tree
Hide file tree
Showing 23 changed files with 52 additions and 63 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ name = "arrow2"
bench = false

[dependencies]
num = "^0.4"
num-traits = "0.2"
chrono = "^0.4"
# To efficiently cast numbers to strings
lexical-core = { version = "0.7", optional = true }
Expand Down
2 changes: 1 addition & 1 deletion benches/arithmetic_kernels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use arrow2::util::bench_util::*;
use arrow2::{
compute::arithmetics::basic::div::div_scalar, datatypes::DataType, types::NativeType,
};
use num::NumCast;
use num_traits::NumCast;
use std::ops::Div;

fn bench_div_scalar<T>(lhs: &PrimitiveArray<T>, rhs: &T)
Expand Down
5 changes: 4 additions & 1 deletion src/array/dictionary/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ pub use mutable::*;
use super::{new_empty_array, primitive::PrimitiveArray, Array};

/// Trait denoting [`NativeType`]s that can be used as keys of a dictionary.
pub trait DictionaryKey: NativeType + NaturalDataType + num::NumCast + num::FromPrimitive {}
pub trait DictionaryKey:
NativeType + NaturalDataType + num_traits::NumCast + num_traits::FromPrimitive
{
}

impl DictionaryKey for i8 {}
impl DictionaryKey for i16 {}
Expand Down
4 changes: 2 additions & 2 deletions src/array/specification.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use std::convert::TryFrom;

use num::Num;
use num_traits::Num;

use crate::types::Index;

/// Trait describing types that can be used as offsets as per Arrow specification.
/// This trait is only implemented for `i32` and `i64`, the two sizes part of the specification.
/// # Safety
/// Do not implement.
pub unsafe trait Offset: Index + Num + Ord + num::CheckedAdd {
pub unsafe trait Offset: Index + Num + Ord + num_traits::CheckedAdd {
fn is_large() -> bool;

fn to_isize(&self) -> isize;
Expand Down
5 changes: 1 addition & 4 deletions src/compute/arithmetics/basic/add.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
//! Definition of basic add operations with primitive arrays
use std::ops::Add;

use num::{
traits::{ops::overflowing::OverflowingAdd, SaturatingAdd},
CheckedAdd, Zero,
};
use num_traits::{ops::overflowing::OverflowingAdd, CheckedAdd, SaturatingAdd, Zero};

use crate::{
array::{Array, PrimitiveArray},
Expand Down
2 changes: 1 addition & 1 deletion src/compute/arithmetics/basic/div.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Definition of basic div operations with primitive arrays
use std::ops::Div;

use num::{CheckedDiv, NumCast, Zero};
use num_traits::{CheckedDiv, NumCast, Zero};

use crate::datatypes::DataType;
use crate::{
Expand Down
5 changes: 1 addition & 4 deletions src/compute/arithmetics/basic/mul.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
//! Definition of basic mul operations with primitive arrays
use std::ops::Mul;

use num::{
traits::{ops::overflowing::OverflowingMul, SaturatingMul},
CheckedMul, Zero,
};
use num_traits::{ops::overflowing::OverflowingMul, CheckedMul, SaturatingMul, Zero};

use crate::{
array::{Array, PrimitiveArray},
Expand Down
2 changes: 1 addition & 1 deletion src/compute/arithmetics/basic/pow.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! Definition of basic pow operations with primitive arrays
use num::{checked_pow, traits::Pow, CheckedMul, One, Zero};
use num_traits::{checked_pow, CheckedMul, One, Pow, Zero};

use crate::{
array::{Array, PrimitiveArray},
Expand Down
2 changes: 1 addition & 1 deletion src/compute/arithmetics/basic/rem.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::ops::Rem;

use num::{traits::CheckedRem, NumCast, Zero};
use num_traits::{CheckedRem, NumCast, Zero};

use crate::datatypes::DataType;
use crate::{
Expand Down
5 changes: 1 addition & 4 deletions src/compute/arithmetics/basic/sub.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
//! Definition of basic sub operations with primitive arrays
use std::ops::Sub;

use num::{
traits::{ops::overflowing::OverflowingSub, SaturatingSub},
CheckedSub, Zero,
};
use num_traits::{ops::overflowing::OverflowingSub, CheckedSub, SaturatingSub, Zero};

use crate::{
array::{Array, PrimitiveArray},
Expand Down
2 changes: 1 addition & 1 deletion src/compute/arithmetics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pub mod time;

use std::ops::{Add, Div, Mul, Neg, Rem, Sub};

use num::{NumCast, Zero};
use num_traits::{NumCast, Zero};

use crate::datatypes::{DataType, TimeUnit};
use crate::error::{ArrowError, Result};
Expand Down
2 changes: 1 addition & 1 deletion src/compute/arithmetics/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

use std::ops::{Add, Sub};

use num::cast::AsPrimitive;
use num_traits::AsPrimitive;

use crate::{
array::{Array, PrimitiveArray},
Expand Down
21 changes: 8 additions & 13 deletions src/compute/arity.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
//! Defines kernels suitable to perform operations to primitive arrays.

use num::Zero;

use super::utils::combine_validities;
use crate::{
bitmap::{Bitmap, MutableBitmap},
error::{ArrowError, Result},
};

use crate::buffer::Buffer;
use crate::types::NativeType;
use crate::{
array::{Array, PrimitiveArray},
bitmap::{Bitmap, MutableBitmap},
buffer::Buffer,
datatypes::DataType,
error::{ArrowError, Result},
types::NativeType,
};

/// Applies an unary and infallible function to a primitive array. This is the
Expand Down Expand Up @@ -97,7 +92,7 @@ pub fn unary_checked<I, F, O>(
) -> PrimitiveArray<O>
where
I: NativeType,
O: NativeType + Zero,
O: NativeType,
F: Fn(I) -> Option<O>,
{
let mut mut_bitmap = MutableBitmap::with_capacity(array.len());
Expand All @@ -109,7 +104,7 @@ where
}
None => {
mut_bitmap.push(false);
O::zero()
O::default()
}
});

Expand Down Expand Up @@ -247,7 +242,7 @@ pub fn binary_checked<T, D, F>(
op: F,
) -> Result<PrimitiveArray<T>>
where
T: NativeType + Zero,
T: NativeType,
D: NativeType,
F: Fn(T, D) -> Option<T>,
{
Expand All @@ -270,7 +265,7 @@ where
}
None => {
mut_bitmap.push(false);
T::zero()
T::default()
}
});

Expand Down
4 changes: 2 additions & 2 deletions src/compute/cast/boolean_to.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::{

pub(super) fn boolean_to_primitive_dyn<T>(array: &dyn Array) -> Result<Box<dyn Array>>
where
T: NativeType + NaturalDataType + num::One,
T: NativeType + NaturalDataType + num_traits::One,
{
let array = array.as_any().downcast_ref().unwrap();
Ok(Box::new(boolean_to_primitive::<T>(array)))
Expand All @@ -19,7 +19,7 @@ where
/// Casts the [`BooleanArray`] to a [`PrimitiveArray`].
pub fn boolean_to_primitive<T>(from: &BooleanArray) -> PrimitiveArray<T>
where
T: NativeType + NaturalDataType + num::One,
T: NativeType + NaturalDataType + num_traits::One,
{
let iter = from
.values()
Expand Down
2 changes: 1 addition & 1 deletion src/compute/cast/dictionary_to.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ pub fn wrapping_dictionary_to_dictionary_keys<K1, K2>(
from: &DictionaryArray<K1>,
) -> Result<DictionaryArray<K2>>
where
K1: DictionaryKey + num::traits::AsPrimitive<K2>,
K1: DictionaryKey + num_traits::AsPrimitive<K2>,
K2: DictionaryKey,
{
let keys = from.keys();
Expand Down
14 changes: 7 additions & 7 deletions src/compute/cast/primitive_to.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ pub(super) fn primitive_to_primitive_dyn<I, O>(
options: CastOptions,
) -> Result<Box<dyn Array>>
where
I: NativeType + num::NumCast + num::traits::AsPrimitive<O>,
O: NativeType + num::NumCast,
I: NativeType + num_traits::NumCast + num_traits::AsPrimitive<O>,
O: NativeType + num_traits::NumCast,
{
let from = from.as_any().downcast_ref::<PrimitiveArray<I>>().unwrap();
if options.wrapped {
Expand All @@ -70,12 +70,12 @@ pub fn primitive_to_primitive<I, O>(
to_type: &DataType,
) -> PrimitiveArray<O>
where
I: NativeType + num::NumCast,
O: NativeType + num::NumCast,
I: NativeType + num_traits::NumCast,
O: NativeType + num_traits::NumCast,
{
let iter = from
.iter()
.map(|v| v.and_then(|x| num::cast::cast::<I, O>(*x)));
.map(|v| v.and_then(|x| num_traits::cast::cast::<I, O>(*x)));
PrimitiveArray::<O>::from_trusted_len_iter(iter).to(to_type.clone())
}

Expand All @@ -86,10 +86,10 @@ pub fn primitive_as_primitive<I, O>(
to_type: &DataType,
) -> PrimitiveArray<O>
where
I: NativeType + num::traits::AsPrimitive<O>,
I: NativeType + num_traits::AsPrimitive<O>,
O: NativeType,
{
unary(from, num::traits::AsPrimitive::<O>::as_, to_type.clone())
unary(from, num_traits::AsPrimitive::<O>::as_, to_type.clone())
}

/// Cast [`PrimitiveArray`] to a [`PrimitiveArray`] of the same physical type.
Expand Down
2 changes: 1 addition & 1 deletion src/compute/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
//! Defines windowing functions, like `shift`ing

use crate::compute::concat;
use num::{abs, clamp};
use num_traits::{abs, clamp};

use crate::{
array::{new_null_array, Array},
Expand Down
10 changes: 5 additions & 5 deletions src/io/json/read/deserialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use std::{collections::hash_map::DefaultHasher, sync::Arc};

use hash_hasher::HashedMap;
use indexmap::map::IndexMap as HashMap;
use num::NumCast;
use num_traits::NumCast;
use serde_json::Value;

use crate::types::NaturalDataType;
Expand Down Expand Up @@ -80,8 +80,8 @@ fn read_int<T: NativeType + NaturalDataType + NumCast>(
data_type: DataType,
) -> PrimitiveArray<T> {
let iter = rows.iter().map(|row| match row {
Value::Number(number) => number.as_i64().and_then(num::cast::cast::<i64, T>),
Value::Bool(number) => num::cast::cast::<i32, T>(*number as i32),
Value::Number(number) => number.as_i64().and_then(num_traits::cast::<i64, T>),
Value::Bool(number) => num_traits::cast::<i32, T>(*number as i32),
_ => None,
});
PrimitiveArray::from_trusted_len_iter(iter).to(data_type)
Expand All @@ -92,8 +92,8 @@ fn read_float<T: NativeType + NaturalDataType + NumCast>(
data_type: DataType,
) -> PrimitiveArray<T> {
let iter = rows.iter().map(|row| match row {
Value::Number(number) => number.as_f64().and_then(num::cast::cast::<f64, T>),
Value::Bool(number) => num::cast::cast::<i32, T>(*number as i32),
Value::Number(number) => number.as_f64().and_then(num_traits::cast::<f64, T>),
Value::Bool(number) => num_traits::cast::<i32, T>(*number as i32),
_ => None,
});
PrimitiveArray::from_trusted_len_iter(iter).to(data_type)
Expand Down
12 changes: 6 additions & 6 deletions src/io/json_integration/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

use std::{collections::HashMap, sync::Arc};

use num::NumCast;
use num_traits::NumCast;
use serde_json::Value;

use crate::{
Expand Down Expand Up @@ -119,7 +119,7 @@ fn to_primitive<T: NativeType + NumCast>(
.as_ref()
.unwrap()
.iter()
.map(|value| value.as_f64().and_then(num::cast::cast::<f64, T>).unwrap())
.map(|value| value.as_f64().and_then(num_traits::cast::<f64, T>).unwrap())
.collect()
} else {
json_col
Expand All @@ -128,11 +128,11 @@ fn to_primitive<T: NativeType + NumCast>(
.unwrap()
.iter()
.map(|value| match value {
Value::Number(x) => x.as_i64().and_then(num::cast::cast::<i64, T>).unwrap(),
Value::Number(x) => x.as_i64().and_then(num_traits::cast::<i64, T>).unwrap(),
Value::String(x) => x
.parse::<i64>()
.ok()
.and_then(num::cast::cast::<i64, T>)
.and_then(num_traits::cast::<i64, T>)
.unwrap(),
_ => {
panic!()
Expand Down Expand Up @@ -324,7 +324,7 @@ pub fn to_array(
x.iter()
.map(|value| match value {
Value::Number(x) => {
x.as_i64().and_then(num::cast::cast::<i64, i8>).unwrap()
x.as_i64().and_then(num_traits::cast::<i64, i8>).unwrap()
}
Value::String(x) => x.parse::<i8>().ok().unwrap(),
_ => {
Expand All @@ -343,7 +343,7 @@ pub fn to_array(
x.iter()
.map(|value| match value {
Value::Number(x) => {
x.as_i64().and_then(num::cast::cast::<i64, i32>).unwrap()
x.as_i64().and_then(num_traits::cast::<i64, i32>).unwrap()
}
_ => panic!(),
})
Expand Down
2 changes: 1 addition & 1 deletion src/io/parquet/read/statistics/primitive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl<T, R> From<(&ParquetPrimitiveStatistics<R>, DataType)> for PrimitiveStatist
where
T: NativeType,
R: ParquetNativeType,
R: num::cast::AsPrimitive<T>,
R: num_traits::AsPrimitive<T>,
{
fn from((stats, data_type): (&ParquetPrimitiveStatistics<R>, DataType)) -> Self {
Self {
Expand Down
6 changes: 3 additions & 3 deletions src/io/parquet/write/primitive/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub(crate) fn encode_plain<T, R>(array: &PrimitiveArray<T>, is_optional: bool, b
where
T: ArrowNativeType,
R: NativeType,
T: num::cast::AsPrimitive<R>,
T: num_traits::AsPrimitive<R>,
{
if is_optional {
// append the non-null values
Expand All @@ -46,7 +46,7 @@ pub fn array_to_page<T, R>(
where
T: ArrowNativeType,
R: NativeType,
T: num::cast::AsPrimitive<R>,
T: num_traits::AsPrimitive<R>,
{
let is_optional = is_type_nullable(descriptor.type_());

Expand Down Expand Up @@ -96,7 +96,7 @@ pub fn build_statistics<T, R>(
where
T: ArrowNativeType,
R: NativeType,
T: num::cast::AsPrimitive<R>,
T: num_traits::AsPrimitive<R>,
{
let statistics = &PrimitiveStatistics::<R> {
descriptor,
Expand Down
2 changes: 1 addition & 1 deletion src/io/parquet/write/primitive/nested.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub fn array_to_page<T, R, O>(
where
T: ArrowNativeType,
R: NativeType,
T: num::cast::AsPrimitive<R>,
T: num_traits::AsPrimitive<R>,
O: Offset,
{
let is_optional = is_type_nullable(descriptor.type_());
Expand Down
2 changes: 1 addition & 1 deletion src/types/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub trait Index:
+ NaturalDataType
+ std::ops::AddAssign
+ std::ops::Sub<Output = Self>
+ num::One
+ num_traits::One
+ PartialOrd
{
fn to_usize(&self) -> usize;
Expand Down

0 comments on commit 7a366b6

Please sign in to comment.