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

Cleaned examples and docs from old API. #330

Merged
merged 1 commit into from
Aug 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 4 additions & 11 deletions arrow-pyarrow-integration-testing/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,8 @@ fn double(array: PyObject, py: Python) -> PyResult<PyObject> {
#[pyfunction]
fn double_py(lambda: PyObject, py: Python) -> PyResult<bool> {
// create
let array =
Arc::new(PrimitiveArray::<i64>::from(vec![Some(1), None, Some(3)]).to(DataType::Int64));
let expected =
Arc::new(PrimitiveArray::<i64>::from(vec![Some(2), None, Some(6)]).to(DataType::Int64))
as ArrayRef;
let array = Arc::new(PrimitiveArray::<i64>::from(vec![Some(1), None, Some(3)]));
let expected = Arc::new(PrimitiveArray::<i64>::from(vec![Some(2), None, Some(6)])) as ArrayRef;

// to py
let array = to_py(array, py)?;
Expand Down Expand Up @@ -184,19 +181,15 @@ fn round_trip(array: PyObject, py: Python) -> PyResult<PyObject> {
#[pyfunction]
fn import_primitive(array: PyObject, py: Python) -> PyResult<bool> {
let array = to_rust(array, py)?;
let expected =
Arc::new(PrimitiveArray::<i64>::from(vec![Some(2), None, Some(6)]).to(DataType::Int64))
as ArrayRef;
let expected = Arc::new(PrimitiveArray::<i64>::from(vec![Some(2), None, Some(6)])) as ArrayRef;

Ok(array == expected)
}

/// Converts to rust and back to python
#[pyfunction]
fn export_primitive(py: Python) -> PyResult<PyObject> {
let array =
Arc::new(PrimitiveArray::<i64>::from(vec![Some(2), None, Some(6)]).to(DataType::Int64))
as ArrayRef;
let array = Arc::new(PrimitiveArray::<i64>::from(vec![Some(2), None, Some(6)])) as ArrayRef;

let array = to_py(array, py)?;

Expand Down
1 change: 0 additions & 1 deletion benches/take_kernels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ fn create_random_index(size: usize, null_density: f32) -> PrimitiveArray<i32> {
}
})
.collect::<PrimitiveArray<i32>>()
.to(DataType::Int32)
}

fn bench_take(values: &dyn Array, indices: &PrimitiveArray<i32>) {
Expand Down
3 changes: 1 addition & 2 deletions guide/src/ffi.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ use arrow2::ffi::ArrowArray;
// Example of an array:
let array = [Some(1), None, Some(123)]
.iter()
.collect::<PrimitiveArray<i32>>()
.to(DataType::Int32);
.collect::<PrimitiveArray<i32>>();

// export the array.
let ffi_array = ffi::export_to_c(Arc::new(array))?;
Expand Down
4 changes: 2 additions & 2 deletions guide/src/high_level.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ The first difference allows interoperability with Arrow's ecosystem and efficien
# use arrow2::array::PrimitiveArray;
# use arrow2::datatypes::DataType;
# fn main() {
let ints = PrimitiveArray::<i32>::from(&[Some(1), None]).to(DataType::Int32);
let dates = PrimitiveArray::<i32>::from(&[Some(1), None]).to(DataType::Date32);
let ints = PrimitiveArray::<i32>::from([Some(1), None]);
let dates = PrimitiveArray::<i32>::from([Some(1), None]);
# }
```

Expand Down
5 changes: 2 additions & 3 deletions src/array/ord.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,10 @@ macro_rules! dyn_dict {
/// # Example
/// ```
/// use arrow2::array::{ord::build_compare, PrimitiveArray};
/// use arrow2::datatypes::DataType;
///
/// # fn main() -> arrow2::error::Result<()> {
/// let array1 = PrimitiveArray::from_slice(&[1, 2]).to(DataType::Int32);
/// let array2 = PrimitiveArray::from_slice(&[3, 4]).to(DataType::Int32);
/// let array1 = PrimitiveArray::from_slice([1, 2]);
/// let array2 = PrimitiveArray::from_slice([3, 4]);
///
/// let cmp = build_compare(&array1, &array2)?;
///
Expand Down
43 changes: 18 additions & 25 deletions src/compute/arithmetics/basic/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,11 @@ use crate::{
/// ```
/// use arrow2::compute::arithmetics::basic::add::add;
/// use arrow2::array::PrimitiveArray;
/// use arrow2::datatypes::DataType;
///
/// let a = PrimitiveArray::from(&vec![None, Some(6), None, Some(6)]).to(DataType::Int32);
/// let b = PrimitiveArray::from(&vec![Some(5), None, None, Some(6)]).to(DataType::Int32);
/// let a = PrimitiveArray::from([None, Some(6), None, Some(6)]);
/// let b = PrimitiveArray::from([Some(5), None, None, Some(6)]);
/// let result = add(&a, &b).unwrap();
/// let expected = PrimitiveArray::from(&vec![None, None, None, Some(12)]).to(DataType::Int32);
/// let expected = PrimitiveArray::from([None, None, None, Some(12)]);
/// assert_eq!(result, expected)
/// ```
pub fn add<T>(lhs: &PrimitiveArray<T>, rhs: &PrimitiveArray<T>) -> Result<PrimitiveArray<T>>
Expand All @@ -56,12 +55,11 @@ where
/// ```
/// use arrow2::compute::arithmetics::basic::add::checked_add;
/// use arrow2::array::PrimitiveArray;
/// use arrow2::datatypes::DataType;
///
/// let a = PrimitiveArray::from(&vec![Some(100i8), Some(100i8), Some(100i8)]).to(DataType::Int8);
/// let b = PrimitiveArray::from(&vec![Some(0i8), Some(100i8), Some(0i8)]).to(DataType::Int8);
/// let a = PrimitiveArray::from([Some(100i8), Some(100i8), Some(100i8)]);
/// let b = PrimitiveArray::from([Some(0i8), Some(100i8), Some(0i8)]);
/// let result = checked_add(&a, &b).unwrap();
/// let expected = PrimitiveArray::from(&vec![Some(100i8), None, Some(100i8)]).to(DataType::Int8);
/// let expected = PrimitiveArray::from([Some(100i8), None, Some(100i8)]);
/// assert_eq!(result, expected);
/// ```
pub fn checked_add<T>(lhs: &PrimitiveArray<T>, rhs: &PrimitiveArray<T>) -> Result<PrimitiveArray<T>>
Expand All @@ -87,12 +85,11 @@ where
/// ```
/// use arrow2::compute::arithmetics::basic::add::saturating_add;
/// use arrow2::array::PrimitiveArray;
/// use arrow2::datatypes::DataType;
///
/// let a = PrimitiveArray::from(&vec![Some(100i8)]).to(DataType::Int8);
/// let b = PrimitiveArray::from(&vec![Some(100i8)]).to(DataType::Int8);
/// let a = PrimitiveArray::from([Some(100i8)]);
/// let b = PrimitiveArray::from([Some(100i8)]);
/// let result = saturating_add(&a, &b).unwrap();
/// let expected = PrimitiveArray::from(&vec![Some(127)]).to(DataType::Int8);
/// let expected = PrimitiveArray::from([Some(127)]);
/// assert_eq!(result, expected);
/// ```
pub fn saturating_add<T>(
Expand Down Expand Up @@ -122,12 +119,11 @@ where
/// ```
/// use arrow2::compute::arithmetics::basic::add::overflowing_add;
/// use arrow2::array::PrimitiveArray;
/// use arrow2::datatypes::DataType;
///
/// let a = PrimitiveArray::from(&vec![Some(1i8), Some(100i8)]).to(DataType::Int8);
/// let b = PrimitiveArray::from(&vec![Some(1i8), Some(100i8)]).to(DataType::Int8);
/// let a = PrimitiveArray::from([Some(1i8), Some(100i8)]);
/// let b = PrimitiveArray::from([Some(1i8), Some(100i8)]);
/// let (result, overflow) = overflowing_add(&a, &b).unwrap();
/// let expected = PrimitiveArray::from(&vec![Some(2i8), Some(-56i8)]).to(DataType::Int8);
/// let expected = PrimitiveArray::from([Some(2i8), Some(-56i8)]);
/// assert_eq!(result, expected);
/// ```
pub fn overflowing_add<T>(
Expand Down Expand Up @@ -203,11 +199,10 @@ where
/// ```
/// use arrow2::compute::arithmetics::basic::add::add_scalar;
/// use arrow2::array::PrimitiveArray;
/// use arrow2::datatypes::DataType;
///
/// let a = PrimitiveArray::from(&vec![None, Some(6), None, Some(6)]).to(DataType::Int32);
/// let a = PrimitiveArray::from([None, Some(6), None, Some(6)]);
/// let result = add_scalar(&a, &1i32);
/// let expected = PrimitiveArray::from(&vec![None, Some(7), None, Some(7)]).to(DataType::Int32);
/// let expected = PrimitiveArray::from([None, Some(7), None, Some(7)]);
/// assert_eq!(result, expected)
/// ```
pub fn add_scalar<T>(lhs: &PrimitiveArray<T>, rhs: &T) -> PrimitiveArray<T>
Expand Down Expand Up @@ -250,11 +245,10 @@ where
/// ```
/// use arrow2::compute::arithmetics::basic::add::saturating_add_scalar;
/// use arrow2::array::PrimitiveArray;
/// use arrow2::datatypes::DataType;
///
/// let a = PrimitiveArray::from(&vec![Some(100i8)]).to(DataType::Int8);
/// let a = PrimitiveArray::from([Some(100i8)]);
/// let result = saturating_add_scalar(&a, &100i8);
/// let expected = PrimitiveArray::from(&vec![Some(127)]).to(DataType::Int8);
/// let expected = PrimitiveArray::from([Some(127)]);
/// assert_eq!(result, expected);
/// ```
pub fn saturating_add_scalar<T>(lhs: &PrimitiveArray<T>, rhs: &T) -> PrimitiveArray<T>
Expand All @@ -276,11 +270,10 @@ where
/// ```
/// use arrow2::compute::arithmetics::basic::add::overflowing_add_scalar;
/// use arrow2::array::PrimitiveArray;
/// use arrow2::datatypes::DataType;
///
/// let a = PrimitiveArray::from(&vec![Some(1i8), Some(100i8)]).to(DataType::Int8);
/// let a = PrimitiveArray::from([Some(1i8), Some(100i8)]);
/// let (result, overflow) = overflowing_add_scalar(&a, &100i8);
/// let expected = PrimitiveArray::from(&vec![Some(101i8), Some(-56i8)]).to(DataType::Int8);
/// let expected = PrimitiveArray::from([Some(101i8), Some(-56i8)]);
/// assert_eq!(result, expected);
/// ```
pub fn overflowing_add_scalar<T>(lhs: &PrimitiveArray<T>, rhs: &T) -> (PrimitiveArray<T>, Bitmap)
Expand Down
Loading