Skip to content

Commit

Permalink
More changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgecarleitao authored and ritchie46 committed Jun 15, 2021
1 parent 50df546 commit 5085d11
Show file tree
Hide file tree
Showing 21 changed files with 127 additions and 139 deletions.
4 changes: 2 additions & 2 deletions polars/polars-core/src/chunked_array/arithmetic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ where

fn div(self, rhs: N) -> Self::Output {
let rhs: T::Native = NumCast::from(rhs).expect("could not cast");
self.apply_kernel(|arr| Arc::new(basic::div::div_scalar(arr, rhs).unwrap()))
self.apply_kernel(|arr| Arc::new(basic::div::div_scalar(arr, &rhs)))
}
}

Expand Down Expand Up @@ -354,7 +354,7 @@ where

fn rem(self, rhs: N) -> Self::Output {
let rhs: T::Native = NumCast::from(rhs).expect("could not cast");
self.apply_kernel(|arr| Arc::new(basic::rem::rem_scalar(arr, rhs).unwrap()))
self.apply_kernel(|arr| Arc::new(basic::rem::rem_scalar(arr, &rhs)))
}
}

Expand Down
6 changes: 3 additions & 3 deletions polars/polars-core/src/chunked_array/builder/categorical.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ impl RevMappingBuilder {
fn finish(self) -> RevMapping {
use RevMappingBuilder::*;
match self {
Local(mut b) => RevMapping::Local(b.into()),
Local(mut b) => RevMapping::Local(b.to()),
Global(mut map, mut b, uuid) => {
map.shrink_to_fit();
RevMapping::Global(map, b.into(), uuid)
RevMapping::Global(map, b.to(), uuid)
}
}
}
Expand Down Expand Up @@ -148,7 +148,7 @@ impl CategoricalChunkedBuilder {
}

pub fn finish(mut self) -> ChunkedArray<CategoricalType> {
let arr = Arc::new(self.array_builder.finish());
let arr = self.array_builder.into_arc();
ChunkedArray {
field: Arc::new(self.field),
chunks: vec![arr],
Expand Down
19 changes: 7 additions & 12 deletions polars/polars-core/src/chunked_array/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ where
let chunks = ca
.chunks
.iter()
.map(|arr| cast::cast(arr, &N::get_dtype().to_arrow()))
.map(|arr| cast::cast(arr.as_ref(), &N::get_dtype().to_arrow()))
.map(|arr| arr.map(|x| x.into()))
.collect::<arrow::error::Result<Vec<_>>>()?;

Expand All @@ -29,7 +29,7 @@ macro_rules! cast_from_dtype {
let chunks = $self
.downcast_iter()
.into_iter()
.map(|arr| $kernel(arr, $dtype))
.map(|arr| $kernel(arr, &$dtype))
.collect();

Ok(ChunkedArray::new_from_chunks($self.field.name(), chunks))
Expand Down Expand Up @@ -235,19 +235,14 @@ impl ChunkCast for BooleanChunked {
fn cast_inner_list_type(
list: &ListArray<i64>,
child_type: &arrow::datatypes::DataType,
) -> ArrayRef {
) -> Result<ArrayRef> {
let child = list.values();
let offsets = list.offsets();
let child = cast::cast(child, child_type)?;
let child = cast::cast(child.as_ref(), child_type)?.into();

let data_type = ListArray::<i64>::default_datatype(child_type.clone());
let list = ListArray::from_data(
data_type,
offsets.clone(),
Arc::new(*child),
list.validity().clone(),
);
Arc::new(list) as ArrayRef
let list = ListArray::from_data(data_type, offsets.clone(), child, list.validity().clone());
Ok(Arc::new(list) as ArrayRef)
}

/// We cannot cast anything to or from List/LargeList
Expand Down Expand Up @@ -278,7 +273,7 @@ impl ChunkCast for ListChunked {
DataType::List(child_type) => {
let chunks = self
.downcast_iter()
.map(|list| cast_inner_list_type(list, data_type))
.map(|list| cast_inner_list_type(list, &data_type.to_arrow()))
.collect::<Result<_>>()?;
let ca = ListChunked::new_from_chunks(self.name(), chunks);
Ok(ca.into_series())
Expand Down
6 changes: 2 additions & 4 deletions polars/polars-core/src/chunked_array/comparison.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,10 +411,8 @@ impl ChunkCompare<&Utf8Chunked> for Utf8Chunked {
}
// same length
else if self.chunk_id().zip(rhs.chunk_id()).all(|(l, r)| l == r) {
self.comparison(rhs, |x, y| {
comparison::compare(x, y, comparison::Operator::Lt)
})
.expect("should not fail")
self.comparison(rhs, comparison::Operator::Lt)
.expect("should not fail")
} else {
apply_operand_on_chunkedarray_by_iter!(self, rhs, <)
}
Expand Down
4 changes: 2 additions & 2 deletions polars/polars-core/src/chunked_array/float.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ where
T::Native: Float,
{
pub fn is_nan(&self) -> BooleanChunked {
self.apply_kernel_cast(is_nan)
self.apply_kernel_cast(is_nan::<T::Native>)
}
pub fn is_not_nan(&self) -> BooleanChunked {
self.apply_kernel_cast(is_not_nan)
self.apply_kernel_cast(is_not_nan::<T::Native>)
}
pub fn is_finite(&self) -> BooleanChunked {
self.apply_kernel_cast(is_finite)
Expand Down
2 changes: 1 addition & 1 deletion polars/polars-core/src/chunked_array/iterator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl<'a> Iterator for BoolIterNoNull<'a> {
} else {
let old = self.current;
self.current += 1;
unsafe { Some(self.array.value_unchecked(old)) }
unsafe { Some(self.array.value(old)) }
}
}

Expand Down
2 changes: 1 addition & 1 deletion polars/polars-core/src/chunked_array/kernels/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ where
S::Native: num::NumCast,
{
let array =
arrow::compute::cast::primitive_to_primitive::<_, T::Native>(arr, datatype.to_arrow());
arrow::compute::cast::primitive_to_primitive::<_, T::Native>(arr, &datatype.to_arrow());
Arc::new(array)
}

Expand Down
8 changes: 4 additions & 4 deletions polars/polars-core/src/chunked_array/kernels/take.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ pub(crate) unsafe fn take_no_null_primitive<T: NativeType>(
let array_values = arr.values();
let index_values = indices.values();

let mut values = MutableBuffer::<T::Native>::with_capacity_aligned(data_len);
let mut values = MutableBuffer::<T>::with_capacity(data_len);
let iter = index_values
.iter()
.map(|idx| *array_values.get_unchecked(*idx as usize));
values.extend(iter);

let nulls = indices.data_ref().null_buffer().cloned();
let nulls = indices.validity().clone();

let arr = values.into_primitive_array::<T>(nulls);
Arc::new(arr)
Expand Down Expand Up @@ -342,7 +342,7 @@ pub(crate) fn take_utf8_iter<I: IntoIterator<Item = usize>>(

pub(crate) unsafe fn take_utf8(
arr: &LargeStringArray,
indices: &UInt32Array,
indices: &Int32Array,
) -> Arc<LargeStringArray> {
let data_len = indices.len();

Expand All @@ -364,7 +364,7 @@ pub(crate) unsafe fn take_utf8(
};

// 16 bytes per string as default alloc
let mut values_buf = AlignedVec::<u8>::with_capacity_aligned(values_capacity);
let mut values_buf = AlignedVec::<u8>::with_capacity(values_capacity);

// both 0 nulls
if arr.null_count() == 0 && indices.null_count() == 0 {
Expand Down
29 changes: 13 additions & 16 deletions polars/polars-core/src/chunked_array/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,23 +157,20 @@ impl<T> ChunkedArray<T> {
Some(0)
} else {
let mut offset = 0;
for (idx, (null_count, null_bit_buffer)) in self.null_bits().enumerate() {
if null_count == 0 {
return Some(offset);
} else {
let arr = &self.chunks[idx];
let null_bit_buffer = null_bit_buffer.as_ref().unwrap();
let bit_end = arr.offset() + arr.len();

let byte_start = std::cmp::min(round_upto_power_of_2(arr.offset(), 8), bit_end);
let data = null_bit_buffer.as_slice();

for i in arr.offset()..byte_start {
if get_bit(data, i) {
return Some(offset + i);
for (idx, validity) in self.null_bits().enumerate() {
if let Some(validity) = validity {
if validity.null_count() == 0 {
return Some(offset);
} else {
for (i, is_valid) in validity.iter().enumerate() {
if is_valid {
return Some(offset + i);
}
}
offset += validity.len()
}
offset += arr.len()
} else {
return Some(offset);
}
}
None
Expand Down Expand Up @@ -512,7 +509,7 @@ where
macro_rules! downcast_and_pack {
($casttype:ident, $variant:ident) => {{
let arr = &*(arr as *const dyn Array as *const $casttype);
let v = arr.value_unchecked(idx);
let v = arr.value(idx);
AnyValue::$variant(v)
}};
}
Expand Down

0 comments on commit 5085d11

Please sign in to comment.