Skip to content

Commit

Permalink
chore(rust): update arrow (#5862)
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Dec 20, 2022
1 parent 7f50b55 commit 0fd735b
Show file tree
Hide file tree
Showing 28 changed files with 68 additions and 105 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ bitflags = "1.3"
[workspace.dependencies.arrow]
package = "arrow2"
# git = "https://github.com/jorgecarleitao/arrow2"
git = "https://github.com/ritchie46/arrow2"
# git = "https://github.com/ritchie46/arrow2"
# rev = "368aacc173a27e2a763d2c6396682a688e5a2707"
# path = "../arrow2"
branch = "polars_2022-12-13"
version = "0.14.1"
# branch = "polars_2022-12-13"
version = "0.15"
default-features = false
features = [
"compute_aggregate",
Expand Down
8 changes: 4 additions & 4 deletions polars/polars-arrow/src/array/default_arrays.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ pub trait FromData<T> {

impl FromData<Bitmap> for BooleanArray {
fn from_data_default(values: Bitmap, validity: Option<Bitmap>) -> BooleanArray {
BooleanArray::from_data(DataType::Boolean, values, validity)
BooleanArray::new(DataType::Boolean, values, validity)
}
}

impl<T: NativeType> FromData<Buffer<T>> for PrimitiveArray<T> {
fn from_data_default(values: Buffer<T>, validity: Option<Bitmap>) -> Self {
let dt = T::PRIMITIVE;
PrimitiveArray::from_data(dt.into(), values, validity)
PrimitiveArray::new(dt.into(), values, validity)
}
}

Expand All @@ -39,7 +39,7 @@ impl FromDataUtf8 for Utf8Array<i64> {
validity: Option<Bitmap>,
) -> Self {
let offsets = OffsetsBuffer::new_unchecked(offsets);
Utf8Array::from_data_unchecked(DataType::LargeUtf8, offsets, values, validity)
Utf8Array::new_unchecked(DataType::LargeUtf8, offsets, values, validity)
}
}

Expand All @@ -60,6 +60,6 @@ impl FromDataBinary for BinaryArray<i64> {
validity: Option<Bitmap>,
) -> Self {
let offsets = OffsetsBuffer::new_unchecked(offsets);
BinaryArray::from_data(DataType::LargeBinary, offsets, values, validity)
BinaryArray::new(DataType::LargeBinary, offsets, values, validity)
}
}
16 changes: 4 additions & 12 deletions polars/polars-arrow/src/compute/take/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ pub unsafe fn take_primitive_unchecked<T: NativeType>(
}
});
};
let arr = PrimitiveArray::from_data(T::PRIMITIVE.into(), values.into(), Some(validity.into()));
let arr = PrimitiveArray::new(T::PRIMITIVE.into(), values.into(), Some(validity.into()));

Box::new(arr)
}
Expand All @@ -114,11 +114,7 @@ pub unsafe fn take_no_null_primitive_unchecked<T: NativeType>(

let values: Buffer<_> = Vec::from_trusted_len_iter(iter).into();
let validity = indices.validity().cloned();
Box::new(PrimitiveArray::from_data(
T::PRIMITIVE.into(),
values,
validity,
))
Box::new(PrimitiveArray::new(T::PRIMITIVE.into(), values, validity))
}

/// Take kernel for single chunk without nulls and an iterator as index.
Expand All @@ -140,7 +136,7 @@ pub unsafe fn take_no_null_primitive_iter_unchecked<T: NativeType, I: TrustedLen
});

let values: Buffer<_> = Vec::from_trusted_len_iter(iter).into();
Box::new(PrimitiveArray::from_data(T::PRIMITIVE.into(), values, None))
Box::new(PrimitiveArray::new(T::PRIMITIVE.into(), values, None))
}

/// Take kernel for a single chunk with null values and an iterator as index.
Expand Down Expand Up @@ -245,11 +241,7 @@ pub unsafe fn take_no_null_bool_iter_unchecked<I: IntoIterator<Item = usize>>(
values.get_bit_unchecked(idx)
});
let mutable = MutableBitmap::from_trusted_len_iter_unchecked(iter);
Box::new(BooleanArray::from_data(
DataType::Boolean,
mutable.into(),
None,
))
Box::new(BooleanArray::new(DataType::Boolean, mutable.into(), None))
}

/// Take kernel for single chunk and an iterator as index.
Expand Down
2 changes: 1 addition & 1 deletion polars/polars-arrow/src/conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::prelude::*;

pub fn chunk_to_struct(chunk: Chunk<ArrayRef>, fields: Vec<Field>) -> StructArray {
let dtype = DataType::Struct(fields);
StructArray::from_data(dtype, chunk.into_arrays(), None)
StructArray::new(dtype, chunk.into_arrays(), None)
}

/// Returns its underlying [`Vec`], if possible.
Expand Down
4 changes: 2 additions & 2 deletions polars/polars-arrow/src/kernels/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ mod test {
let offsets = OffsetsBuffer::try_from(vec![0i64, 3, 5, 6]).unwrap();

let dtype = ListArray::<i64>::default_datatype(DataType::Int32);
ListArray::<i64>::from_data(dtype, offsets, Box::new(values), None)
ListArray::<i64>::new(dtype, offsets, Box::new(values), None)
}

#[test]
Expand Down Expand Up @@ -137,7 +137,7 @@ mod test {
let offsets = OffsetsBuffer::try_from(vec![0i64, 1, 2, 3, 6, 9, 11]).unwrap();

let dtype = ListArray::<i64>::default_datatype(DataType::Int32);
let arr = ListArray::<i64>::from_data(dtype, offsets, Box::new(values), None);
let arr = ListArray::<i64>::new(dtype, offsets, Box::new(values), None);

let out = sublist_get_indexes(&arr, 1);
assert_eq!(
Expand Down
4 changes: 2 additions & 2 deletions polars/polars-arrow/src/kernels/rolling/no_nulls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ where
.collect_trusted::<Vec<_>>();

let validity = create_validity(min_periods, len, window_size, det_offsets_fn);
Box::new(PrimitiveArray::from_data(
Box::new(PrimitiveArray::new(
T::PRIMITIVE.into(),
out.into(),
validity.map(|b| b.into()),
Expand Down Expand Up @@ -104,7 +104,7 @@ where
.collect_trusted::<Vec<T>>();

let validity = create_validity(min_periods, len, window_size, det_offsets_fn);
Box::new(PrimitiveArray::from_data(
Box::new(PrimitiveArray::new(
DataType::from(T::PRIMITIVE),
out.into(),
validity.map(|b| b.into()),
Expand Down
10 changes: 3 additions & 7 deletions polars/polars-arrow/src/kernels/rolling/no_nulls/quantile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,7 @@ where
{
if values.is_empty() {
let out: Vec<T> = vec![];
return Box::new(PrimitiveArray::from_data(
T::PRIMITIVE.into(),
out.into(),
None,
));
return Box::new(PrimitiveArray::new(T::PRIMITIVE.into(), out.into(), None));
}

let mut sorted_window = SortedBuf::new(values, 0, 1);
Expand Down Expand Up @@ -245,7 +241,7 @@ where
.collect_trusted::<Vec<T>>();

let validity = create_validity(min_periods, len, window_size, det_offsets_fn);
Box::new(PrimitiveArray::from_data(
Box::new(PrimitiveArray::new(
T::PRIMITIVE.into(),
out.into(),
validity.map(|b| b.into()),
Expand Down Expand Up @@ -285,7 +281,7 @@ where
.collect_trusted::<Vec<T>>();

let validity = create_validity(min_periods, len, window_size, det_offsets_fn);
Box::new(PrimitiveArray::from_data(
Box::new(PrimitiveArray::new(
T::PRIMITIVE.into(),
out.into(),
validity.map(|b| b.into()),
Expand Down
10 changes: 5 additions & 5 deletions polars/polars-arrow/src/kernels/rolling/nulls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ where
})
.collect_trusted::<Vec<_>>();

Box::new(PrimitiveArray::from_data(
Box::new(PrimitiveArray::new(
T::PRIMITIVE.into(),
out.into(),
Some(validity.into()),
Expand All @@ -95,7 +95,7 @@ mod test {
fn get_null_arr() -> PrimitiveArray<f64> {
// 1, None, -1, 4
let buf = Buffer::from(vec![1.0, 0.0, -1.0, 4.0]);
PrimitiveArray::from_data(
PrimitiveArray::new(
DataType::Float64,
buf,
Some(Bitmap::from(&[true, false, true, true])),
Expand All @@ -105,7 +105,7 @@ mod test {
#[test]
fn test_rolling_sum_nulls() {
let buf = Buffer::from(vec![1.0, 2.0, 3.0, 4.0]);
let arr = &PrimitiveArray::from_data(
let arr = &PrimitiveArray::new(
DataType::Float64,
buf,
Some(Bitmap::from(&[true, false, true, true])),
Expand Down Expand Up @@ -184,7 +184,7 @@ mod test {
#[test]
fn test_rolling_max_no_nulls() {
let buf = Buffer::from(vec![1.0, 2.0, 3.0, 4.0]);
let arr = &PrimitiveArray::from_data(
let arr = &PrimitiveArray::new(
DataType::Float64,
buf,
Some(Bitmap::from(&[true, true, true, true])),
Expand All @@ -205,7 +205,7 @@ mod test {
assert_eq!(out, &[None, None, None, Some(4.0)]);

let buf = Buffer::from(vec![4.0, 3.0, 2.0, 1.0]);
let arr = &PrimitiveArray::from_data(
let arr = &PrimitiveArray::new(
DataType::Float64,
buf,
Some(Bitmap::from(&[true, true, true, true])),
Expand Down
14 changes: 5 additions & 9 deletions polars/polars-arrow/src/kernels/rolling/nulls/quantile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,7 @@ where
{
if values.is_empty() {
let out: Vec<T> = vec![];
return Box::new(PrimitiveArray::from_data(
T::PRIMITIVE.into(),
out.into(),
None,
));
return Box::new(PrimitiveArray::new(T::PRIMITIVE.into(), out.into(), None));
}

let len = values.len();
Expand Down Expand Up @@ -70,7 +66,7 @@ where
})
.collect_trusted::<Vec<T>>();

Box::new(PrimitiveArray::from_data(
Box::new(PrimitiveArray::new(
T::PRIMITIVE.into(),
out.into(),
Some(validity.into()),
Expand Down Expand Up @@ -133,7 +129,7 @@ where
})
.collect_trusted::<Vec<T>>();

Box::new(PrimitiveArray::from_data(
Box::new(PrimitiveArray::new(
T::PRIMITIVE.into(),
out.into(),
Some(validity.into()),
Expand Down Expand Up @@ -302,7 +298,7 @@ mod test {
#[test]
fn test_rolling_median_nulls() {
let buf = Buffer::from(vec![1.0, 2.0, 3.0, 4.0]);
let arr = &PrimitiveArray::from_data(
let arr = &PrimitiveArray::new(
DataType::Float64,
buf,
Some(Bitmap::from(&[true, false, true, true])),
Expand Down Expand Up @@ -338,7 +334,7 @@ mod test {
fn test_rolling_quantile_nulls_limits() {
// compare quantiles to corresponding min/max/median values
let buf = Buffer::<f64>::from(vec![1.0, 2.0, 3.0, 4.0, 5.0]);
let values = &PrimitiveArray::from_data(
let values = &PrimitiveArray::new(
DataType::Float64,
buf,
Some(Bitmap::from(&[true, false, false, true, true])),
Expand Down
6 changes: 3 additions & 3 deletions polars/polars-arrow/src/kernels/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ where
}
});

PrimitiveArray::from_data(array.data_type().clone(), av.into(), None)
PrimitiveArray::new(array.data_type().clone(), av.into(), None)
}

/// Set values in a primitive array based on a mask array. This is fast when large chunks of bits are set or unset.
Expand Down Expand Up @@ -64,7 +64,7 @@ pub fn set_with_mask<T: NativeType>(
valid.bitor(mask_bitmap)
});

PrimitiveArray::from_data(data_type, buf.into(), validity)
PrimitiveArray::new(data_type, buf.into(), validity)
}

/// Efficiently sets value at the indices from the iterator to `set_value`.
Expand All @@ -91,7 +91,7 @@ where
Ok(())
})?;

Ok(PrimitiveArray::from_data(
Ok(PrimitiveArray::new(
data_type,
buf.into(),
array.validity().cloned(),
Expand Down
4 changes: 2 additions & 2 deletions polars/polars-arrow/src/kernels/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ pub fn string_lengths(array: &Utf8Array<i64>) -> ArrayRef {
.windows(2)
.map(|x| (x[1] - x[0]) as u32);
let values: Buffer<_> = Vec::from_trusted_len_iter(values).into();
let array = UInt32Array::from_data(DataType::UInt32, values, array.validity().cloned());
let array = UInt32Array::new(DataType::UInt32, values, array.validity().cloned());
Box::new(array)
}

pub fn string_nchars(array: &Utf8Array<i64>) -> ArrayRef {
let values = array.values_iter().map(|x| x.chars().count() as u32);
let values: Buffer<_> = Vec::from_trusted_len_iter(values).into();
let array = UInt32Array::from_data(DataType::UInt32, values, array.validity().cloned());
let array = UInt32Array::new(DataType::UInt32, values, array.validity().cloned());
Box::new(array)
}
6 changes: 3 additions & 3 deletions polars/polars-core/src/chunked_array/bitwise.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ where
.map(|(l, r)| *l & *r)
.collect_trusted::<Vec<_>>();

let arr = PrimitiveArray::from_data(T::get_dtype().to_arrow(), av.into(), validity);
let arr = PrimitiveArray::new(T::get_dtype().to_arrow(), av.into(), validity);
Box::new(arr) as ArrayRef
})
.collect::<Vec<_>>();
Expand Down Expand Up @@ -60,7 +60,7 @@ where
.map(|(l, r)| *l | *r)
.collect_trusted::<Vec<_>>();

let arr = PrimitiveArray::from_data(T::get_dtype().to_arrow(), av.into(), validity);
let arr = PrimitiveArray::new(T::get_dtype().to_arrow(), av.into(), validity);
Box::new(arr) as ArrayRef
})
.collect::<Vec<_>>();
Expand Down Expand Up @@ -92,7 +92,7 @@ where
.map(|(l, r)| l.bitxor(*r))
.collect_trusted::<Vec<_>>();

let arr = PrimitiveArray::from_data(T::get_dtype().to_arrow(), av.into(), validity);
let arr = PrimitiveArray::new(T::get_dtype().to_arrow(), av.into(), validity);
Box::new(arr) as ArrayRef
})
.collect::<Vec<_>>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub(crate) fn merge_categorical_map(
// Safety
// all offsets are valid and the u8 data is valid utf8
let mut new_slots = unsafe {
MutableUtf8Array::from_data_unchecked(
MutableUtf8Array::new_unchecked(
DataType::Utf8.to_arrow(),
offset_buf,
values_buf,
Expand Down
2 changes: 1 addition & 1 deletion polars/polars-core/src/chunked_array/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ pub(crate) fn to_primitive<T: PolarsNumericType>(
values: Vec<T::Native>,
validity: Option<Bitmap>,
) -> PrimitiveArray<T::Native> {
PrimitiveArray::from_data(T::get_dtype().to_arrow(), values.into(), validity)
PrimitiveArray::new(T::get_dtype().to_arrow(), values.into(), validity)
}

pub(crate) fn to_array<T: PolarsNumericType>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ pub(crate) fn create_extension<
None
};

let array = FixedSizeBinaryArray::from_data(extension_type, buf, validity);
let array = FixedSizeBinaryArray::new(extension_type, buf, validity);

// Safety:
// we just heap allocated the ExtensionSentinel, so its alive.
Expand Down
8 changes: 4 additions & 4 deletions polars/polars-core/src/chunked_array/ops/bit_repr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ where
assert_eq!(reinterpreted_buf.len(), len);
assert_eq!(reinterpreted_buf.offset(), offset);
assert_eq!(reinterpreted_buf.as_slice().as_ptr() as usize, ptr);
Box::new(PrimitiveArray::from_data(
Box::new(PrimitiveArray::new(
ArrowDataType::UInt64,
reinterpreted_buf,
array.validity().cloned(),
Expand Down Expand Up @@ -129,7 +129,7 @@ where
assert_eq!(reinterpreted_buf.len(), len);
assert_eq!(reinterpreted_buf.offset(), offset);
assert_eq!(reinterpreted_buf.as_slice().as_ptr() as usize, ptr);
Box::new(PrimitiveArray::from_data(
Box::new(PrimitiveArray::new(
ArrowDataType::UInt32,
reinterpreted_buf,
array.validity().cloned(),
Expand Down Expand Up @@ -210,7 +210,7 @@ impl UInt64Chunked {
assert_eq!(reinterpreted_buf.len(), len);
assert_eq!(reinterpreted_buf.offset(), offset);
assert_eq!(reinterpreted_buf.as_slice().as_ptr() as usize, ptr);
Box::new(PrimitiveArray::from_data(
Box::new(PrimitiveArray::new(
ArrowDataType::Float64,
reinterpreted_buf,
array.validity().cloned(),
Expand Down Expand Up @@ -239,7 +239,7 @@ impl UInt32Chunked {
assert_eq!(reinterpreted_buf.len(), len);
assert_eq!(reinterpreted_buf.offset(), offset);
assert_eq!(reinterpreted_buf.as_slice().as_ptr() as usize, ptr);
Box::new(PrimitiveArray::from_data(
Box::new(PrimitiveArray::new(
ArrowDataType::Float32,
reinterpreted_buf,
array.validity().cloned(),
Expand Down

0 comments on commit 0fd735b

Please sign in to comment.