Skip to content

Commit

Permalink
chore(rust): update to rustc nightly-2023-07-27
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Jul 28, 2023
1 parent 3881d3d commit 6600d9c
Show file tree
Hide file tree
Showing 81 changed files with 387 additions and 289 deletions.
2 changes: 1 addition & 1 deletion .github/deploy_manylinux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ ls -la
rm py-polars/README.md
cp README.md py-polars/README.md
cd py-polars
rustup override set nightly-2023-06-23
rustup override set nightly-2023-07-27
export RUSTFLAGS='-C target-feature=+fxsr,+sse,+sse2,+sse3,+ssse3,+sse4.1,+sse4.2,+popcnt,+avx,+fma'

# first the default release
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
- py-*

env:
RUST_TOOLCHAIN: nightly-2023-06-23
RUST_TOOLCHAIN: nightly-2023-07-27
PYTHON_VERSION: '3.8'
MATURIN_VERSION: '1.1.0'
MATURIN_PYPI_TOKEN: ${{ secrets.PYPI_API_TOKEN }}
Expand Down
2 changes: 1 addition & 1 deletion examples/python_rust_compiled_function/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fn hamming_distance(series_a: &PyAny, series_b: &PyAny) -> PyResult<PyObject> {
fn hamming_distance_impl(a: &Series, b: &Series) -> PolarsResult<UInt32Chunked> {
Ok(a.utf8()?
.into_iter()
.zip(b.utf8()?.into_iter())
.zip(b.utf8()?)
.map(|(lhs, rhs)| hamming_distance_strs(lhs, rhs))
.collect())
}
Expand Down
4 changes: 3 additions & 1 deletion polars/polars-arrow/src/compute/take/fixed_size_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ pub unsafe fn take_unchecked(values: &FixedSizeListArray, indices: &IdxArr) -> F
) {
let idx = indices.values().as_slice();
let child_values = values.values();
let DataType::FixedSizeList(_, width) = values.data_type() else {unreachable!()};
let DataType::FixedSizeList(_, width) = values.data_type() else {
unreachable!()
};

with_match_primitive_type!(primitive, |$T| {
let arr: &PrimitiveArray<$T> = child_values.as_any().downcast_ref().unwrap();
Expand Down
1 change: 1 addition & 0 deletions polars/polars-arrow/src/floats/ord.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use crate::kernels::rolling::compare_fn_nan_max;
#[repr(transparent)]
pub struct OrdFloat<T>(T);

#[allow(clippy::incorrect_partial_ord_impl_on_ord_type)]
impl<T: IsFloat + PartialEq + PartialOrd> PartialOrd for OrdFloat<T> {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(compare_fn_nan_max(&self.0, &other.0))
Expand Down
44 changes: 41 additions & 3 deletions polars/polars-arrow/src/kernels/agg_mean.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use std::simd::{Mask, Simd, SimdCast, SimdElement, SimdFloat, StdFloat, ToBitMask};
use std::simd::{
LaneCount, Mask, Simd, SimdCast, SimdElement, SimdFloat, SimdInt, SimdUint, StdFloat,
SupportedLaneCount, ToBitMask,
};

use arrow::array::{Array, PrimitiveArray};
use arrow::bitmap::utils::{BitChunkIterExact, BitChunksExact};
Expand All @@ -11,18 +14,51 @@ use num_traits::ToPrimitive;
use crate::data_types::IsFloat;
use crate::utils::with_match_primitive_type;

// TODO! try to remove this if we can cast again directly
pub trait SimdCastPl<const N: usize>
where
LaneCount<N>: SupportedLaneCount,
{
fn cast_custom<U: SimdCast>(self) -> Simd<U, N>;
}

macro_rules! impl_cast_custom {
($_type:ty) => {
impl<const N: usize> SimdCastPl<N> for Simd<$_type, N>
where
LaneCount<N>: SupportedLaneCount,
{
fn cast_custom<U: SimdCast>(self) -> Simd<U, N> {
self.cast::<U>()
}
}
};
}

impl_cast_custom!(u8);
impl_cast_custom!(u16);
impl_cast_custom!(u32);
impl_cast_custom!(u64);
impl_cast_custom!(i8);
impl_cast_custom!(i16);
impl_cast_custom!(i32);
impl_cast_custom!(i64);
impl_cast_custom!(f32);
impl_cast_custom!(f64);

#[multiversion(targets = "simd")]
fn nonnull_sum_as_f64<T>(values: &[T]) -> f64
where
T: NativeType + SimdElement + ToPrimitive + SimdCast,
Simd<T, 8>: SimdCastPl<8>,
{
// we choose 8 as that the maximum size of f64x8 -> 512bit wide
const LANES: usize = 8;
let (head, simd_vals, tail) = unsafe { values.align_to::<Simd<T, LANES>>() };

let mut reduced: Simd<f64, LANES> = Simd::splat(0.0);
for chunk in simd_vals {
reduced += chunk.cast::<f64>();
reduced += chunk.cast_custom::<f64>();
}

unsafe {
Expand All @@ -43,6 +79,7 @@ fn null_sum_as_f64_impl<T, I>(values: &[T], mut validity_masks: I) -> f64
where
T: NativeType + SimdElement + ToPrimitive + IsFloat + SimdCast,
I: BitChunkIterExact<u8>,
Simd<T, 8>: SimdCastPl<8>,
{
const LANES: usize = 8;
let mut chunks = values.chunks_exact(LANES);
Expand All @@ -54,7 +91,7 @@ where
|acc, (chunk, validity_chunk)| {
// safety: exact size chunks
let chunk: [T; LANES] = unsafe { chunk.try_into().unwrap_unchecked() };
let chunk = Simd::from(chunk).cast::<f64>();
let chunk = Simd::from(chunk).cast_custom::<f64>();

// construct [bools]
let mask = Mask::<i8, LANES>::from_bitmask(validity_chunk);
Expand Down Expand Up @@ -107,6 +144,7 @@ where
fn null_sum_as_f64<T>(values: &[T], bitmap: &Bitmap) -> f64
where
T: NativeType + SimdElement + ToPrimitive + IsFloat + SimdCast,
Simd<T, 8>: SimdCastPl<8>,
{
let (slice, offset, length) = bitmap.as_slice();
if offset == 0 {
Expand Down
2 changes: 1 addition & 1 deletion polars/polars-arrow/src/kernels/ewm/variance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ where

let res = xs
.into_iter()
.zip(ys.into_iter())
.zip(ys)
.enumerate()
.map(|(i, (opt_x, opt_y))| {
let is_observation = opt_x.is_some() && opt_y.is_some();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ impl ListCategoricalChunkedBuilder {
) -> Self {
let inner =
ListPrimitiveChunkedBuilder::new(name, capacity, values_capacity, logical_type.clone());
let DataType::Categorical(Some(rev_map)) = logical_type else { panic!("expected categorical type") };
let DataType::Categorical(Some(rev_map)) = logical_type else {
panic!("expected categorical type")
};
Self {
inner,
inner_dtype: RevMapMerger::new(rev_map),
Expand All @@ -24,7 +26,9 @@ impl ListCategoricalChunkedBuilder {

impl ListBuilderTrait for ListCategoricalChunkedBuilder {
fn append_series(&mut self, s: &Series) -> PolarsResult<()> {
let DataType::Categorical(Some(rev_map)) = s.dtype() else { polars_bail!(ComputeError: "expected categorical type")};
let DataType::Categorical(Some(rev_map)) = s.dtype() else {
polars_bail!(ComputeError: "expected categorical type")
};
self.inner_dtype.merge_map(rev_map)?;
self.inner.append_series(s)
}
Expand Down
4 changes: 3 additions & 1 deletion polars/polars-core/src/chunked_array/builder/list/dtypes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ impl DtypeMerger {
match self {
#[cfg(feature = "dtype-categorical")]
DtypeMerger::Categorical(merger) => {
let DataType::Categorical(Some(rev_map)) = dtype else { polars_bail!(ComputeError: "expected categorical rev-map") };
let DataType::Categorical(Some(rev_map)) = dtype else {
polars_bail!(ComputeError: "expected categorical rev-map")
};
return merger.merge_map(rev_map);
}
DtypeMerger::Other(Some(set_dtype)) => {
Expand Down
1 change: 1 addition & 0 deletions polars/polars-core/src/chunked_array/from.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use super::*;

#[allow(clippy::ptr_arg)]
#[allow(clippy::needless_pass_by_ref_mut)]
fn from_chunks_list_dtype(chunks: &mut Vec<ArrayRef>, dtype: DataType) -> DataType {
// ensure we don't get List<null>
let dtype = if let Some(arr) = chunks.get(0) {
Expand Down
8 changes: 3 additions & 5 deletions polars/polars-core/src/chunked_array/list/iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,8 @@ mod test {
builder.append_series(&Series::new("", &[1, 1])).unwrap();
let ca = builder.finish();

ca.amortized_iter()
.zip(ca.into_iter())
.for_each(|(s1, s2)| {
assert!(s1.unwrap().as_ref().series_equal(&s2.unwrap()));
});
ca.amortized_iter().zip(&ca).for_each(|(s1, s2)| {
assert!(s1.unwrap().as_ref().series_equal(&s2.unwrap()));
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ impl<'a> CategoricalChunkedBuilder<'a> {
let cache = &mut crate::STRING_CACHE.lock_map();
id = cache.uuid;

for (s, h) in values.values_iter().zip(hashes.into_iter()) {
for (s, h) in values.values_iter().zip(hashes) {
let global_idx = cache.insert_from_hash(h, s);
// safety:
// we allocated enough
Expand Down Expand Up @@ -558,7 +558,7 @@ mod test {
let mut builder1 = CategoricalChunkedBuilder::new("foo", 10);
let mut builder2 = CategoricalChunkedBuilder::new("foo", 10);
builder1.drain_iter(vec![None, Some("hello"), Some("vietnam")]);
builder2.drain_iter(vec![Some("hello"), None, Some("world")].into_iter());
builder2.drain_iter(vec![Some("hello"), None, Some("world")]);

let s = builder1.finish().into_series();
assert_eq!(s.str_value(0).unwrap(), "null");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ pub(crate) struct RevMapMerger {

impl RevMapMerger {
pub(crate) fn new(rev_map: Arc<RevMapping>) -> Self {
let RevMapping::Global(_, _, id) = rev_map.as_ref() else { panic!("impl error") };
let RevMapping::Global(_, _, id) = rev_map.as_ref() else {
panic!("impl error")
};
RevMapMerger {
state: None,
id: *id,
Expand All @@ -57,7 +59,9 @@ impl RevMapMerger {
}

fn init_state(&mut self) {
let RevMapping::Global(map, slots, _) = self.original.as_ref() else { unreachable!() };
let RevMapping::Global(map, slots, _) = self.original.as_ref() else {
unreachable!()
};
self.state = Some(State {
map: (*map).clone(),
slots: slots_to_mut(slots),
Expand All @@ -70,7 +74,9 @@ impl RevMapMerger {
if Arc::ptr_eq(&self.original, rev_map) {
return Ok(());
}
let RevMapping::Global(map, slots, id) = rev_map.as_ref() else { polars_bail!(ComputeError: "expected global rev-map") };
let RevMapping::Global(map, slots, id) = rev_map.as_ref() else {
polars_bail!(ComputeError: "expected global rev-map")
};
polars_ensure!(*id == self.id, ComputeError: "categoricals don't originate from the same string cache\n\
try setting a global string cache or increase the scope of the local string cache");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::chunked_array::object::extension::PolarsExtension;
use crate::prelude::*;

/// This will dereference a raw ptr when dropping the PolarsExtension, make sure that it's valid.
pub(crate) unsafe fn drop_list(ca: &mut ListChunked) {
pub(crate) unsafe fn drop_list(ca: &ListChunked) {
let mut inner = ca.inner_dtype();
let mut nested_count = 0;

Expand Down
6 changes: 3 additions & 3 deletions polars/polars-core/src/chunked_array/ops/any_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ impl<'a> AnyValue<'a> {
// so we set the array pointer with values of the dictionary array.
#[cfg(feature = "dtype-categorical")]
{
use polars_arrow::is_valid::{IsValid as _};
use polars_arrow::is_valid::IsValid as _;
if let Some(arr) = arr.as_any().downcast_ref::<DictionaryArray<u32>>() {
let keys = arr.keys();
let values = arr.values();
Expand All @@ -144,14 +144,14 @@ impl<'a> AnyValue<'a> {

if arr.is_valid_unchecked(idx) {
let v = arr.value_unchecked(idx);
let DataType::Categorical(Some(rev_map)) = fld.data_type() else {
let DataType::Categorical(Some(rev_map)) = fld.data_type()
else {
unimplemented!()
};
AnyValue::Categorical(v, rev_map, SyncPtr::from_const(values))
} else {
AnyValue::Null
}

} else {
arr_to_any_value(&**arr, idx, fld.data_type())
}
Expand Down
8 changes: 4 additions & 4 deletions polars/polars-core/src/chunked_array/ops/repeat_by.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ where
}
let iter = self
.into_iter()
.zip(by.into_iter())
.zip(by)
.map(|(opt_v, opt_by)| opt_by.map(|by| std::iter::repeat(opt_v).take(by as usize)));

// Safety:
Expand Down Expand Up @@ -64,7 +64,7 @@ impl RepeatBy for BooleanChunked {

let iter = self
.into_iter()
.zip(by.into_iter())
.zip(by)
.map(|(opt_v, opt_by)| opt_by.map(|by| std::iter::repeat(opt_v).take(by as usize)));

// Safety:
Expand Down Expand Up @@ -93,7 +93,7 @@ impl RepeatBy for Utf8Chunked {

let iter = self
.into_iter()
.zip(by.into_iter())
.zip(by)
.map(|(opt_v, opt_by)| opt_by.map(|by| std::iter::repeat(opt_v).take(by as usize)));

// Safety:
Expand Down Expand Up @@ -124,7 +124,7 @@ impl RepeatBy for BinaryChunked {
}
let iter = self
.into_iter()
.zip(by.into_iter())
.zip(by)
.map(|(opt_v, opt_by)| opt_by.map(|by| std::iter::repeat(opt_v).take(by as usize)));

// Safety:
Expand Down
10 changes: 5 additions & 5 deletions polars/polars-core/src/chunked_array/ops/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ where
if self.chunks.len() == 1 {
let arr = set_at_idx_no_null(
self.downcast_iter().next().unwrap(),
idx.into_iter(),
idx,
value,
T::get_dtype().to_arrow(),
)?;
Expand Down Expand Up @@ -113,7 +113,7 @@ where
// slow path, could be optimized.
let ca = mask
.into_iter()
.zip(self.into_iter())
.zip(self)
.map(|(mask_val, opt_val)| match mask_val {
Some(true) => value,
_ => opt_val,
Expand Down Expand Up @@ -166,7 +166,7 @@ impl<'a> ChunkSet<'a, bool, bool> for BooleanChunked {
check_bounds!(self, mask);
let ca = mask
.into_iter()
.zip(self.into_iter())
.zip(self)
.map(|(mask_val, opt_val)| match mask_val {
Some(true) => value,
_ => opt_val,
Expand Down Expand Up @@ -229,7 +229,7 @@ impl<'a> ChunkSet<'a, &'a str, String> for Utf8Chunked {
check_bounds!(self, mask);
let ca = mask
.into_iter()
.zip(self.into_iter())
.zip(self)
.map(|(mask_val, opt_val)| match mask_val {
Some(true) => value,
_ => opt_val,
Expand Down Expand Up @@ -293,7 +293,7 @@ impl<'a> ChunkSet<'a, &'a [u8], Vec<u8>> for BinaryChunked {
check_bounds!(self, mask);
let ca = mask
.into_iter()
.zip(self.into_iter())
.zip(self)
.map(|(mask_val, opt_val)| match mask_val {
Some(true) => value,
_ => opt_val,
Expand Down
4 changes: 2 additions & 2 deletions polars/polars-core/src/chunked_array/ops/zip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@ impl<T: PolarsObject> ChunkZip<ObjectType<T>> for ObjectChunked<T> {
let mut ca: Self = left
.as_ref()
.into_iter()
.zip(right.into_iter())
.zip(mask.into_iter())
.zip(right.as_ref())
.zip(mask.as_ref())
.map(|((left_c, right_c), mask_c)| match mask_c {
Some(true) => left_c.cloned(),
Some(false) => right_c.cloned(),
Expand Down
9 changes: 3 additions & 6 deletions polars/polars-core/src/frame/arithmetic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,9 @@ use crate::utils::try_get_supertype;
/// Get the supertype that is valid for all columns in the DataFrame.
/// This reduces casting of the rhs in arithmetic.
fn get_supertype_all(df: &DataFrame, rhs: &Series) -> PolarsResult<DataType> {
df.columns
.iter()
.fold(Ok(rhs.dtype().clone()), |dt, s| match dt {
Ok(dt) => try_get_supertype(s.dtype(), &dt),
e => e,
})
df.columns.iter().try_fold(rhs.dtype().clone(), |dt, s| {
try_get_supertype(s.dtype(), &dt)
})
}

macro_rules! impl_arithmetic {
Expand Down
Loading

0 comments on commit 6600d9c

Please sign in to comment.