Repository: jorgecarleitao/arrow2
Pull request #355 (2021-08-28 12:57:42)

Improved API docs.


Patch:
diff --git a/Cargo.toml b/Cargo.toml
index ad96f42e54..94a058e790 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -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 }
diff --git a/benches/arithmetic_kernels.rs b/benches/arithmetic_kernels.rs
index f2ef5a9450..0faa06ff38 100644
--- a/benches/arithmetic_kernels.rs
+++ b/benches/arithmetic_kernels.rs
@@ -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)
diff --git a/src/array/dictionary/mod.rs b/src/array/dictionary/mod.rs
index 1d911a440b..beb4960fff 100644
--- a/src/array/dictionary/mod.rs
+++ b/src/array/dictionary/mod.rs
@@ -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 {}
diff --git a/src/array/specification.rs b/src/array/specification.rs
index e0a09757a5..00c69cbd97 100644
--- a/src/array/specification.rs
+++ b/src/array/specification.rs
@@ -1,6 +1,6 @@
 use std::convert::TryFrom;
 
-use num::Num;
+use num_traits::Num;
 
 use crate::types::Index;
 
@@ -8,7 +8,7 @@ use crate::types::Index;
 /// 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;
diff --git a/src/buffer/immutable.rs b/src/buffer/immutable.rs
index 9805703120..5989e30491 100644
--- a/src/buffer/immutable.rs
+++ b/src/buffer/immutable.rs
@@ -5,8 +5,14 @@ use crate::{trusted_len::TrustedLen, types::NativeType};
 use super::bytes::Bytes;
 use super::mutable::MutableBuffer;
 
-/// Buffer represents a contiguous memory region that can be shared with other buffers and across
-/// thread boundaries.
+/// [`Buffer`] is a contiguous memory region that can
+/// be shared across thread boundaries.
+/// The easiest way to think about `Buffer<T>` is being equivalent to
+/// an immutable `Vec<T>`, with the following differences:
+/// * `T` must be [`NativeType`]
+/// * clone is `O(1)`
+/// * memory is sharable across thread boundaries (it is under an `Arc`)
+/// * it supports external allocated memory (FFI)
 #[derive(Clone, PartialEq)]
 pub struct Buffer<T: NativeType> {
     /// the internal byte buffer.
diff --git a/src/buffer/mod.rs b/src/buffer/mod.rs
index 1969b5a982..a146c6fae6 100644
--- a/src/buffer/mod.rs
+++ b/src/buffer/mod.rs
@@ -1,11 +1,5 @@
-//! This module contains core functionality to handle memory in this crate.
-//!
-//! The core containers of this module are [`MutableBuffer`] and [`Buffer`].
-//! [`MutableBuffer`] is like [`Vec`], with the following main differences:
-//! * it only supports types that implement [`super::types::NativeType`]
-//! * it allocates memory along cache lines.
-//! * it is not clonable.
-//! [`Buffer`] is the immutable counterpart of [`MutableBuffer`].
+//! Contains containers for all Arrow sized types (e.g. `i32`),
+//! [`Buffer`] and [`MutableBuffer`].
 
 mod immutable;
 mod mutable;
diff --git a/src/buffer/mutable.rs b/src/buffer/mutable.rs
index 43439161bf..0c5544875e 100644
--- a/src/buffer/mutable.rs
+++ b/src/buffer/mutable.rs
@@ -18,7 +18,7 @@ fn capacity_multiple_of_64<T: NativeType>(capacity: usize) -> usize {
     util::round_upto_multiple_of_64(capacity * size_of::<T>()) / size_of::<T>()
 }
 
-/// A [`MutableBuffer`] is this crates' interface to store types that are byte-like, such as `i32`.
+/// A [`MutableBuffer`] is this crates' interface to store types that are byte-like such as `i32`.
 /// It behaves like a [`Vec`], with the following differences:
 /// * memory is allocated along cache lines and in multiple of 64 bytes.
 /// * it can only hold types supported by the arrow format (`u8-u64`, `i8-i128`, `f32,f64` and [`crate::types::days_ms`])
@@ -29,6 +29,7 @@ fn capacity_multiple_of_64<T: NativeType>(capacity: usize) -> usize {
 /// let mut buffer = MutableBuffer::<u32>::new();
 /// buffer.push(256);
 /// buffer.extend_from_slice(&[1]);
+/// assert_eq!(buffer.as_slice(), &[256, 1]);
 /// let buffer: Buffer<u32> = buffer.into();
 /// assert_eq!(buffer.as_slice(), &[256, 1])
 /// ```
@@ -76,8 +77,8 @@ impl<T: NativeType> MutableBuffer<T> {
         }
     }
 
-    /// Allocates a new [MutableBuffer] with `len` and capacity to be at least `len` where
-    /// all bytes are guaranteed to be `0u8`.
+    /// Allocates a new [MutableBuffer] with `len` and capacity to be at least `len`
+    /// where data is zeroed.
     /// # Example
     /// ```
     /// # use arrow2::buffer::{Buffer, MutableBuffer};
@@ -165,13 +166,13 @@ impl<T: NativeType> MutableBuffer<T> {
         self.len = new_len;
     }
 
-    /// Returns whether this buffer is empty or not.
+    /// Returns whether this buffer is empty.
     #[inline]
     pub fn is_empty(&self) -> bool {
         self.len == 0
     }
 
-    /// Returns the length (the number of bytes written) in this buffer.
+    /// Returns the length (the number of items) in this buffer.
     /// The invariant `buffer.len() <= buffer.capacity()` is always upheld.
     #[inline]
     pub fn len(&self) -> usize {
@@ -226,7 +227,7 @@ impl<T: NativeType> MutableBuffer<T> {
         self.ptr.as_ptr()
     }
 
-    /// Extends this buffer from a slice of items that can be represented in bytes, increasing its capacity if needed.
+    /// Extends this buffer from a slice of items, increasing its capacity if needed.
     /// # Example
     /// ```
     /// # use arrow2::buffer::MutableBuffer;
@@ -246,7 +247,7 @@ impl<T: NativeType> MutableBuffer<T> {
         self.len += additional;
     }
 
-    /// Extends the buffer with a new item, increasing its capacity if needed.
+    /// Pushes a new item to the buffer, increasing its capacity if needed.
     /// # Example
     /// ```
     /// # use arrow2::buffer::MutableBuffer;
@@ -264,9 +265,9 @@ impl<T: NativeType> MutableBuffer<T> {
         self.len += 1;
     }
 
-    /// Extends the buffer with a new item, without checking for sufficient capacity
+    /// Extends the buffer with a new item without checking for sufficient capacity
     /// Safety
-    /// Caller must ensure that the capacity()-len()>=size_of<T>()
+    /// Caller must ensure that `self.capacity() - self.len() >= 1`
     #[inline]
     pub(crate) unsafe fn push_unchecked(&mut self, item: T) {
         let dst = self.ptr.as_ptr().add(self.len);
@@ -274,14 +275,19 @@ impl<T: NativeType> MutableBuffer<T> {
         self.len += 1;
     }
 
+    /// Sets the length of this buffer.
+    /// # Panic
+    /// Panics iff `len > capacity`.
     /// # Safety
-    /// The caller must ensure that the buffer was properly initialized up to `len`.
+    /// The caller must ensure no reads are performed on any
+    /// item within `[len, capacity - len]`
     #[inline]
     pub unsafe fn set_len(&mut self, len: usize) {
         assert!(len <= self.capacity());
         self.len = len;
     }
 
+    /// Extends this buffer by `additional` items of value `value`.
     #[inline]
     pub fn extend_constant(&mut self, additional: usize, value: T) {
         self.resize(self.len() + additional, value)
@@ -334,21 +340,14 @@ unsafe fn reallocate<T: NativeType>(
 
 impl<A: NativeType> Extend<A> for MutableBuffer<A> {
     fn extend<T: IntoIterator<Item = A>>(&mut self, iter: T) {
-        let iterator = iter.into_iter();
-        self.extend_from_iter(iterator)
-    }
-}
-
-impl<T: NativeType> MutableBuffer<T> {
-    #[inline]
-    fn extend_from_iter<I: Iterator<Item = T>>(&mut self, mut iterator: I) {
+        let mut iterator = iter.into_iter();
         let (lower, _) = iterator.size_hint();
         let additional = lower;
         self.reserve(additional);
 
         // this is necessary because of https://github.com/rust-lang/rust/issues/32155
         let mut len = SetLenOnDrop::new(&mut self.len);
-        let mut dst = unsafe { self.ptr.as_ptr().add(len.local_len) as *mut T };
+        let mut dst = unsafe { self.ptr.as_ptr().add(len.local_len) as *mut A };
         let capacity = self.capacity;
 
         while len.local_len < capacity {
@@ -366,7 +365,9 @@ impl<T: NativeType> MutableBuffer<T> {
 
         iterator.for_each(|item| self.push(item));
     }
+}
 
+impl<T: NativeType> MutableBuffer<T> {
     /// Extends `self` from a [`TrustedLen`] iterator.
     #[inline]
     pub fn extend_from_trusted_len_iter<I: TrustedLen<Item = T>>(&mut self, iterator: I) {
@@ -409,7 +410,7 @@ impl<T: NativeType> MutableBuffer<T> {
     /// # use arrow2::buffer::MutableBuffer;
     /// let v = vec![1u32];
     /// let iter = v.iter().map(|x| x * 2);
-    /// let buffer = unsafe { MutableBuffer::from_trusted_len_iter(iter) };
+    /// let buffer = MutableBuffer::from_trusted_len_iter(iter);
     /// assert_eq!(buffer.len(), 1)
     /// ```
     /// # Safety
@@ -428,14 +429,6 @@ impl<T: NativeType> MutableBuffer<T> {
 
     /// Creates a [`MutableBuffer`] from an [`Iterator`] with a trusted (upper) length.
     /// Prefer this to `collect` whenever possible, as it is faster ~60% faster.
-    /// # Example
-    /// ```
-    /// # use arrow2::buffer::MutableBuffer;
-    /// let v = vec![1u32];
-    /// let iter = v.iter().map(|x| x * 2);
-    /// let buffer = unsafe { MutableBuffer::from_trusted_len_iter(iter) };
-    /// assert_eq!(buffer.len(), 1)
-    /// ```
     /// # Safety
     /// This method assumes that the iterator's size is correct and is undefined behavior
     /// to use it on an iterator that reports an incorrect length.
@@ -450,8 +443,7 @@ impl<T: NativeType> MutableBuffer<T> {
         buffer
     }
 
-    /// Creates a [`MutableBuffer`] from an [`Iterator`] with a [`TrustedLen`] iterator, or errors
-    /// if any of the items of the iterator is an error.
+    /// Creates a [`MutableBuffer`] from a fallible [`TrustedLen`] iterator.
     #[inline]
     pub fn try_from_trusted_len_iter<E, I: TrustedLen<Item = std::result::Result<T, E>>>(
         iterator: I,
@@ -515,7 +507,7 @@ impl<T: NativeType> FromIterator<T> for MutableBuffer<T> {
             }
         };
 
-        buffer.extend_from_iter(iterator);
+        buffer.extend(iterator);
         buffer
     }
 }
diff --git a/src/compute/arithmetics/basic/add.rs b/src/compute/arithmetics/basic/add.rs
index f6b89fd889..e2e0d8ebb5 100644
--- a/src/compute/arithmetics/basic/add.rs
+++ b/src/compute/arithmetics/basic/add.rs
@@ -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},
diff --git a/src/compute/arithmetics/basic/div.rs b/src/compute/arithmetics/basic/div.rs
index 8e83bb1953..e39fd65011 100644
--- a/src/compute/arithmetics/basic/div.rs
+++ b/src/compute/arithmetics/basic/div.rs
@@ -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::{
diff --git a/src/compute/arithmetics/basic/mul.rs b/src/compute/arithmetics/basic/mul.rs
index 6038bc6f82..f804345c84 100644
--- a/src/compute/arithmetics/basic/mul.rs
+++ b/src/compute/arithmetics/basic/mul.rs
@@ -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},
diff --git a/src/compute/arithmetics/basic/pow.rs b/src/compute/arithmetics/basic/pow.rs
index 017f4515ab..78157ef81e 100644
--- a/src/compute/arithmetics/basic/pow.rs
+++ b/src/compute/arithmetics/basic/pow.rs
@@ -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},
diff --git a/src/compute/arithmetics/basic/rem.rs b/src/compute/arithmetics/basic/rem.rs
index 68f2088a75..af696de496 100644
--- a/src/compute/arithmetics/basic/rem.rs
+++ b/src/compute/arithmetics/basic/rem.rs
@@ -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::{
diff --git a/src/compute/arithmetics/basic/sub.rs b/src/compute/arithmetics/basic/sub.rs
index fd812c9cb9..ffd0b79015 100644
--- a/src/compute/arithmetics/basic/sub.rs
+++ b/src/compute/arithmetics/basic/sub.rs
@@ -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},
diff --git a/src/compute/arithmetics/mod.rs b/src/compute/arithmetics/mod.rs
index c22ff7428d..3414634dfc 100644
--- a/src/compute/arithmetics/mod.rs
+++ b/src/compute/arithmetics/mod.rs
@@ -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};
diff --git a/src/compute/arithmetics/time.rs b/src/compute/arithmetics/time.rs
index cc6a0579c8..07e979eaf7 100644
--- a/src/compute/arithmetics/time.rs
+++ b/src/compute/arithmetics/time.rs
@@ -11,7 +11,7 @@
 
 use std::ops::{Add, Sub};
 
-use num::cast::AsPrimitive;
+use num_traits::AsPrimitive;
 
 use crate::{
     array::{Array, PrimitiveArray},
diff --git a/src/compute/arity.rs b/src/compute/arity.rs
index e69d8162a2..c48058c81e 100644
--- a/src/compute/arity.rs
+++ b/src/compute/arity.rs
@@ -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
@@ -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());
@@ -109,7 +104,7 @@ where
         }
         None => {
             mut_bitmap.push(false);
-            O::zero()
+            O::default()
         }
     });
 
@@ -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>,
 {
@@ -270,7 +265,7 @@ where
             }
             None => {
                 mut_bitmap.push(false);
-                T::zero()
+                T::default()
             }
         });
 
diff --git a/src/compute/cast/boolean_to.rs b/src/compute/cast/boolean_to.rs
index 47a34dc0c0..2d6c243705 100644
--- a/src/compute/cast/boolean_to.rs
+++ b/src/compute/cast/boolean_to.rs
@@ -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)))
@@ -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()
diff --git a/src/compute/cast/dictionary_to.rs b/src/compute/cast/dictionary_to.rs
index eb90610cc7..7b149a3906 100644
--- a/src/compute/cast/dictionary_to.rs
+++ b/src/compute/cast/dictionary_to.rs
@@ -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();
diff --git a/src/compute/cast/primitive_to.rs b/src/compute/cast/primitive_to.rs
index 6b6bb90f3f..dcab568330 100644
--- a/src/compute/cast/primitive_to.rs
+++ b/src/compute/cast/primitive_to.rs
@@ -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 {
@@ -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())
 }
 
@@ -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.
diff --git a/src/compute/window.rs b/src/compute/window.rs
index 27be63b3c7..9b8e47ef03 100644
--- a/src/compute/window.rs
+++ b/src/compute/window.rs
@@ -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},
diff --git a/src/io/json/read/deserialize.rs b/src/io/json/read/deserialize.rs
index f06b51b713..fb9e56ef1f 100644
--- a/src/io/json/read/deserialize.rs
+++ b/src/io/json/read/deserialize.rs
@@ -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;
@@ -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)
@@ -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)
diff --git a/src/io/json_integration/read.rs b/src/io/json_integration/read.rs
index cbdcefe7a1..188aa6f412 100644
--- a/src/io/json_integration/read.rs
+++ b/src/io/json_integration/read.rs
@@ -17,7 +17,7 @@
 
 use std::{collections::HashMap, sync::Arc};
 
-use num::NumCast;
+use num_traits::NumCast;
 use serde_json::Value;
 
 use crate::{
@@ -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
@@ -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!()
@@ -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(),
                             _ => {
@@ -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!(),
                             })
diff --git a/src/io/parquet/read/statistics/primitive.rs b/src/io/parquet/read/statistics/primitive.rs
index c1b0e8f7af..d669425e50 100644
--- a/src/io/parquet/read/statistics/primitive.rs
+++ b/src/io/parquet/read/statistics/primitive.rs
@@ -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 {
diff --git a/src/io/parquet/write/primitive/basic.rs b/src/io/parquet/write/primitive/basic.rs
index 796df77c08..a86f246c7b 100644
--- a/src/io/parquet/write/primitive/basic.rs
+++ b/src/io/parquet/write/primitive/basic.rs
@@ -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
@@ -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_());
 
@@ -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,
diff --git a/src/io/parquet/write/primitive/nested.rs b/src/io/parquet/write/primitive/nested.rs
index 36ff01a723..43483a8149 100644
--- a/src/io/parquet/write/primitive/nested.rs
+++ b/src/io/parquet/write/primitive/nested.rs
@@ -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_());
diff --git a/src/types/index.rs b/src/types/index.rs
index 3a6103f002..110c000bc3 100644
--- a/src/types/index.rs
+++ b/src/types/index.rs
@@ -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;


Test patch:
diff --git a/tests/it/compute/cast.rs b/tests/it/compute/cast.rs
index 36ebfde4f9..fa6cf994fd 100644
--- a/tests/it/compute/cast.rs
+++ b/tests/it/compute/cast.rs
@@ -48,92 +48,6 @@ fn u16_as_u8_no_overflow() {
     assert_eq!(values, &[1, 2, 3, 4, 5])
 }
 
-#[test]
-fn float_range_max() {
-    //floats to integers
-    let u: Option<u32> = num::cast(f32::MAX);
-    assert_eq!(u, None);
-    let u: Option<u64> = num::cast(f32::MAX);
-    assert_eq!(u, None);
-
-    let u: Option<i32> = num::cast(f32::MAX);
-    assert_eq!(u, None);
-    let u: Option<i64> = num::cast(f32::MAX);
-    assert_eq!(u, None);
-
-    let u: Option<u32> = num::cast(f64::MAX);
-    assert_eq!(u, None);
-    let u: Option<u64> = num::cast(f64::MAX);
-    assert_eq!(u, None);
-
-    let u: Option<i32> = num::cast(f64::MAX);
-    assert_eq!(u, None);
-    let u: Option<i64> = num::cast(f64::MAX);
-    assert_eq!(u, None);
-
-    //integers to floats
-    let u: Option<f32> = num::cast(u32::MAX);
-    assert!(u.is_some());
-    let u: Option<f64> = num::cast(u32::MAX);
-    assert!(u.is_some());
-
-    let u: Option<f32> = num::cast(i32::MAX);
-    assert!(u.is_some());
-    let u: Option<f64> = num::cast(i32::MAX);
-    assert!(u.is_some());
-
-    let u: Option<f64> = num::cast(i64::MAX);
-    assert!(u.is_some());
-    let u: Option<f64> = num::cast(u64::MAX);
-    assert!(u.is_some());
-
-    let u: Option<f64> = num::cast(f32::MAX);
-    assert!(u.is_some());
-}
-
-#[test]
-fn float_range_min() {
-    //floats to integers
-    let u: Option<u32> = num::cast(f32::MIN);
-    assert_eq!(u, None);
-    let u: Option<u64> = num::cast(f32::MIN);
-    assert_eq!(u, None);
-
-    let u: Option<i32> = num::cast(f32::MIN);
-    assert_eq!(u, None);
-    let u: Option<i64> = num::cast(f32::MIN);
-    assert_eq!(u, None);
-
-    let u: Option<u32> = num::cast(f64::MIN);
-    assert_eq!(u, None);
-    let u: Option<u64> = num::cast(f64::MIN);
-    assert_eq!(u, None);
-
-    let u: Option<i32> = num::cast(f64::MIN);
-    assert_eq!(u, None);
-    let u: Option<i64> = num::cast(f64::MIN);
-    assert_eq!(u, None);
-
-    //integers to floats
-    let u: Option<f32> = num::cast(u32::MIN);
-    assert!(u.is_some());
-    let u: Option<f64> = num::cast(u32::MIN);
-    assert!(u.is_some());
-
-    let u: Option<f32> = num::cast(i32::MIN);
-    assert!(u.is_some());
-    let u: Option<f64> = num::cast(i32::MIN);
-    assert!(u.is_some());
-
-    let u: Option<f64> = num::cast(i64::MIN);
-    assert!(u.is_some());
-    let u: Option<f64> = num::cast(u64::MIN);
-    assert!(u.is_some());
-
-    let u: Option<f64> = num::cast(f32::MIN);
-    assert!(u.is_some());
-}
-
 #[test]
 fn f32_as_u8_overflow() {
     let array = Float32Array::from_slice(&[1.1, 5000.0]);