From 603280903aa740ea827cb087938d0fde37a2f1c8 Mon Sep 17 00:00:00 2001 From: Stijn de Gooijer Date: Sun, 29 Sep 2024 13:25:36 +0200 Subject: [PATCH 1/7] Bump toolchain --- rust-toolchain.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-toolchain.toml b/rust-toolchain.toml index ef33a7d39711..179cd9e58d86 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,2 +1,2 @@ [toolchain] -channel = "nightly-2024-08-26" +channel = "nightly-2024-09-29" From e12093f04ad2a212c75261d0584dcf7dd6f572d8 Mon Sep 17 00:00:00 2001 From: Stijn de Gooijer Date: Sun, 29 Sep 2024 13:48:53 +0200 Subject: [PATCH 2/7] Named lifetime --- crates/polars-arrow/src/legacy/kernels/take_agg/mod.rs | 4 ++-- crates/polars-core/src/chunked_array/binary.rs | 2 +- crates/polars-io/src/csv/write/write_impl/serializer.rs | 2 +- crates/polars-time/src/windows/window.rs | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/crates/polars-arrow/src/legacy/kernels/take_agg/mod.rs b/crates/polars-arrow/src/legacy/kernels/take_agg/mod.rs index 9daf37389837..47aace63ae75 100644 --- a/crates/polars-arrow/src/legacy/kernels/take_agg/mod.rs +++ b/crates/polars-arrow/src/legacy/kernels/take_agg/mod.rs @@ -107,7 +107,7 @@ pub unsafe fn take_agg_bin_iter_unchecked< indices: I, f: F, len: IdxSize, -) -> Option<&[u8]> { +) -> Option<&'a [u8]> { let mut null_count = 0 as IdxSize; let validity = arr.validity().unwrap(); @@ -147,7 +147,7 @@ pub unsafe fn take_agg_bin_iter_unchecked_no_null< arr: &'a BinaryViewArray, indices: I, f: F, -) -> Option<&[u8]> { +) -> Option<&'a [u8]> { indices .into_iter() .map(|idx| arr.value_unchecked(idx)) diff --git a/crates/polars-core/src/chunked_array/binary.rs b/crates/polars-core/src/chunked_array/binary.rs index 27ab78d137a5..93277c2f5e1c 100644 --- a/crates/polars-core/src/chunked_array/binary.rs +++ b/crates/polars-core/src/chunked_array/binary.rs @@ -12,7 +12,7 @@ fn fill_bytes_hashes<'a, T>( ca: &'a ChunkedArray, null_h: u64, hb: PlRandomState, -) -> Vec +) -> Vec> where T: PolarsDataType, <::Array as StaticArray>::ValueT<'a>: AsRef<[u8]>, diff --git a/crates/polars-io/src/csv/write/write_impl/serializer.rs b/crates/polars-io/src/csv/write/write_impl/serializer.rs index 06c5b9abc8cc..e9a3e055278a 100644 --- a/crates/polars-io/src/csv/write/write_impl/serializer.rs +++ b/crates/polars-io/src/csv/write/write_impl/serializer.rs @@ -264,7 +264,7 @@ fn decimal_serializer(array: &PrimitiveArray, scale: usize) -> impl Serial fn callback_serializer<'a, T: NativeType, const QUOTE_NON_NULL: bool>( array: &'a PrimitiveArray, mut callback: impl FnMut(T, &mut Vec) + 'a, -) -> impl Serializer + 'a { +) -> impl Serializer<'a> { let f = move |&item, buf: &mut Vec, _options: &SerializeOptions| { callback(item, buf); }; diff --git a/crates/polars-time/src/windows/window.rs b/crates/polars-time/src/windows/window.rs index 7aa3242b1228..90afe791e4d2 100644 --- a/crates/polars-time/src/windows/window.rs +++ b/crates/polars-time/src/windows/window.rs @@ -177,7 +177,7 @@ impl Window { tu: TimeUnit, tz: Option<&'a Tz>, start_by: StartBy, - ) -> PolarsResult { + ) -> PolarsResult> { BoundsIter::new(*self, closed_window, boundary, tu, tz, start_by) } } From 8371bf1ea7abaf0ef0ab17775017ab52084d7c00 Mon Sep 17 00:00:00 2001 From: Stijn de Gooijer Date: Sun, 29 Sep 2024 13:51:07 +0200 Subject: [PATCH 3/7] Manual power of two --- crates/polars-compute/src/arithmetic/signed.rs | 2 +- crates/polars-compute/src/arithmetic/unsigned.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/polars-compute/src/arithmetic/signed.rs b/crates/polars-compute/src/arithmetic/signed.rs index c77057b78a47..968c82ef96e2 100644 --- a/crates/polars-compute/src/arithmetic/signed.rs +++ b/crates/polars-compute/src/arithmetic/signed.rs @@ -91,7 +91,7 @@ macro_rules! impl_signed_arith_kernel { lhs.fill_with(0) } else if rhs == 1 { lhs - } else if scalar_u & (scalar_u - 1) == 0 { + } else if scalar_u.is_power_of_two() { // Power of two. let shift = scalar_u.trailing_zeros(); if rhs > 0 { diff --git a/crates/polars-compute/src/arithmetic/unsigned.rs b/crates/polars-compute/src/arithmetic/unsigned.rs index db71590989bd..82406a2f94c9 100644 --- a/crates/polars-compute/src/arithmetic/unsigned.rs +++ b/crates/polars-compute/src/arithmetic/unsigned.rs @@ -74,7 +74,7 @@ macro_rules! impl_unsigned_arith_kernel { lhs.fill_with(0) } else if rhs == 1 { lhs - } else if rhs & (rhs - 1) == 0 { + } else if rhs.is_power_of_two() { // Power of two. let shift = rhs.trailing_zeros(); prim_unary_values(lhs, |x| x << shift) From 90f3a787c013b176a1c5f93358b533c606a1eb41 Mon Sep 17 00:00:00 2001 From: Stijn de Gooijer Date: Sun, 29 Sep 2024 13:56:29 +0200 Subject: [PATCH 4/7] Unneeded return --- crates/polars-expr/src/expressions/apply.rs | 2 +- crates/polars-io/src/cloud/glob.rs | 2 +- .../polars-ops/src/chunked_array/list/dispersion.rs | 12 ++++++------ crates/polars-ops/src/chunked_array/list/sum_mean.rs | 4 ++-- .../src/chunked_array/strings/namespace.rs | 4 ++-- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/crates/polars-expr/src/expressions/apply.rs b/crates/polars-expr/src/expressions/apply.rs index 803e0801e636..a52cff4ca2f5 100644 --- a/crates/polars-expr/src/expressions/apply.rs +++ b/crates/polars-expr/src/expressions/apply.rs @@ -426,7 +426,7 @@ impl PhysicalExpr for ApplyExpr { } } if has_agg_list || (has_agg_scalar && has_not_agg) { - return self.apply_multiple_group_aware(acs, df); + self.apply_multiple_group_aware(acs, df) } else { apply_multiple_elementwise( acs, diff --git a/crates/polars-io/src/cloud/glob.rs b/crates/polars-io/src/cloud/glob.rs index 12ac8081a3b8..83b21a9b2b73 100644 --- a/crates/polars-io/src/cloud/glob.rs +++ b/crates/polars-io/src/cloud/glob.rs @@ -163,7 +163,7 @@ impl Matcher { return true; } let last = &key[self.prefix.len()..]; - return self.re.as_ref().unwrap().is_match(last.as_ref()); + self.re.as_ref().unwrap().is_match(last.as_ref()) } } diff --git a/crates/polars-ops/src/chunked_array/list/dispersion.rs b/crates/polars-ops/src/chunked_array/list/dispersion.rs index 2796ebb1de9e..a4521c71c9d0 100644 --- a/crates/polars-ops/src/chunked_array/list/dispersion.rs +++ b/crates/polars-ops/src/chunked_array/list/dispersion.rs @@ -1,7 +1,7 @@ use super::*; pub(super) fn median_with_nulls(ca: &ListChunked) -> Series { - return match ca.inner_dtype() { + match ca.inner_dtype() { DataType::Float32 => { let out: Float32Chunked = ca .apply_amortized_generic(|s| s.and_then(|s| s.as_ref().median().map(|v| v as f32))) @@ -21,11 +21,11 @@ pub(super) fn median_with_nulls(ca: &ListChunked) -> Series { .with_name(ca.name().clone()); out.into_series() }, - }; + } } pub(super) fn std_with_nulls(ca: &ListChunked, ddof: u8) -> Series { - return match ca.inner_dtype() { + match ca.inner_dtype() { DataType::Float32 => { let out: Float32Chunked = ca .apply_amortized_generic(|s| s.and_then(|s| s.as_ref().std(ddof).map(|v| v as f32))) @@ -45,11 +45,11 @@ pub(super) fn std_with_nulls(ca: &ListChunked, ddof: u8) -> Series { .with_name(ca.name().clone()); out.into_series() }, - }; + } } pub(super) fn var_with_nulls(ca: &ListChunked, ddof: u8) -> Series { - return match ca.inner_dtype() { + match ca.inner_dtype() { DataType::Float32 => { let out: Float32Chunked = ca .apply_amortized_generic(|s| s.and_then(|s| s.as_ref().var(ddof).map(|v| v as f32))) @@ -82,5 +82,5 @@ pub(super) fn var_with_nulls(ca: &ListChunked, ddof: u8) -> Series { .with_name(ca.name().clone()); out.into_series() }, - }; + } } diff --git a/crates/polars-ops/src/chunked_array/list/sum_mean.rs b/crates/polars-ops/src/chunked_array/list/sum_mean.rs index 87dff648b9b2..fe16cb8f1114 100644 --- a/crates/polars-ops/src/chunked_array/list/sum_mean.rs +++ b/crates/polars-ops/src/chunked_array/list/sum_mean.rs @@ -175,7 +175,7 @@ pub(super) fn mean_list_numerical(ca: &ListChunked, inner_type: &DataType) -> Se } pub(super) fn mean_with_nulls(ca: &ListChunked) -> Series { - return match ca.inner_dtype() { + match ca.inner_dtype() { DataType::Float32 => { let out: Float32Chunked = ca .apply_amortized_generic(|s| s.and_then(|s| s.as_ref().mean().map(|v| v as f32))) @@ -188,5 +188,5 @@ pub(super) fn mean_with_nulls(ca: &ListChunked) -> Series { .with_name(ca.name().clone()); out.into_series() }, - }; + } } diff --git a/crates/polars-ops/src/chunked_array/strings/namespace.rs b/crates/polars-ops/src/chunked_array/strings/namespace.rs index 07c8fc600fbd..812dfbfcba91 100644 --- a/crates/polars-ops/src/chunked_array/strings/namespace.rs +++ b/crates/polars-ops/src/chunked_array/strings/namespace.rs @@ -430,7 +430,7 @@ pub trait StringNameSpaceImpl: AsString { fn strip_chars_start(&self, pat: &Column) -> PolarsResult { let ca = self.as_string(); if pat.dtype() == &DataType::Null { - return Ok(unary_elementwise(ca, |opt_s| opt_s.map(|s| s.trim_start()))); + Ok(unary_elementwise(ca, |opt_s| opt_s.map(|s| s.trim_start()))) } else { Ok(strip_chars_start(ca, pat.str()?)) } @@ -439,7 +439,7 @@ pub trait StringNameSpaceImpl: AsString { fn strip_chars_end(&self, pat: &Column) -> PolarsResult { let ca = self.as_string(); if pat.dtype() == &DataType::Null { - return Ok(unary_elementwise(ca, |opt_s| opt_s.map(|s| s.trim_end()))); + Ok(unary_elementwise(ca, |opt_s| opt_s.map(|s| s.trim_end()))) } else { Ok(strip_chars_end(ca, pat.str()?)) } From 90e957d4040fa7df2846a1ada35f30cc41c955d2 Mon Sep 17 00:00:00 2001 From: Stijn de Gooijer Date: Sun, 29 Sep 2024 14:01:57 +0200 Subject: [PATCH 5/7] Slice instead of Vec --- .../polars-pipe/src/executors/sinks/group_by/primitive/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/polars-pipe/src/executors/sinks/group_by/primitive/mod.rs b/crates/polars-pipe/src/executors/sinks/group_by/primitive/mod.rs index 8442b8a9cd7e..9bfddb7d3f1d 100644 --- a/crates/polars-pipe/src/executors/sinks/group_by/primitive/mod.rs +++ b/crates/polars-pipe/src/executors/sinks/group_by/primitive/mod.rs @@ -500,7 +500,7 @@ fn insert_and_get( h: u64, opt_v: Option, pre_agg_len: usize, - pre_agg_partitions: &mut Vec>, IdxSize>>, + pre_agg_partitions: &mut [PlIdHashMap>, IdxSize>], current_aggregators: &mut Vec, agg_fns: &Vec, ) -> IdxSize @@ -536,7 +536,7 @@ fn try_insert_and_get( h: u64, opt_v: Option, pre_agg_len: usize, - pre_agg_partitions: &mut Vec>, IdxSize>>, + pre_agg_partitions: &mut [PlIdHashMap>, IdxSize>], ) -> Option where T: NumericNative + Hash, From 5bde915f35d2481a11e23948a2a1d3012277c029 Mon Sep 17 00:00:00 2001 From: Stijn de Gooijer Date: Sun, 29 Sep 2024 13:42:18 +0200 Subject: [PATCH 6/7] Comment lints --- .../src/legacy/kernels/take_agg/var.rs | 1 - .../src/chunked_array/ops/sort/categorical.rs | 3 +-- crates/polars-lazy/src/frame/exitable.rs | 2 +- .../src/executors/sinks/group_by/ooc_state.rs | 5 ++--- crates/polars-plan/src/dsl/dt.rs | 4 ++-- crates/polars-python/src/conversion/mod.rs | 2 +- .../src/nodes/parquet_source/row_group_decode.rs | 4 +--- crates/polars-utils/src/pl_str.rs | 14 +++++++------- py-polars/build.rs | 2 +- 9 files changed, 16 insertions(+), 21 deletions(-) diff --git a/crates/polars-arrow/src/legacy/kernels/take_agg/var.rs b/crates/polars-arrow/src/legacy/kernels/take_agg/var.rs index 62e2ba1353f2..3a15062ab674 100644 --- a/crates/polars-arrow/src/legacy/kernels/take_agg/var.rs +++ b/crates/polars-arrow/src/legacy/kernels/take_agg/var.rs @@ -8,7 +8,6 @@ use super::*; /// and: /// Ling, Robert F. (1974). "Comparison of Several Algorithms for Computing Sample Means and Variances". /// Journal of the American Statistical Association. 69 (348): 859–866. doi:10.2307/2286154. JSTOR 2286154. - pub fn online_variance( // iterator producing values iter: I, diff --git a/crates/polars-core/src/chunked_array/ops/sort/categorical.rs b/crates/polars-core/src/chunked_array/ops/sort/categorical.rs index a984c92147b9..5dd71a7b1eb8 100644 --- a/crates/polars-core/src/chunked_array/ops/sort/categorical.rs +++ b/crates/polars-core/src/chunked_array/ops/sort/categorical.rs @@ -72,8 +72,7 @@ impl CategoricalChunked { } } - /// Retrieve the indexes need to sort this and the other arrays. - + /// Retrieve the indices needed to sort this and the other arrays. pub(crate) fn arg_sort_multiple( &self, by: &[Column], diff --git a/crates/polars-lazy/src/frame/exitable.rs b/crates/polars-lazy/src/frame/exitable.rs index ae4809a0022b..0e32f3b3cbee 100644 --- a/crates/polars-lazy/src/frame/exitable.rs +++ b/crates/polars-lazy/src/frame/exitable.rs @@ -37,7 +37,7 @@ impl InProcessQuery { } /// Fetch the result. - + /// /// If it is ready, a materialized DataFrame is returned. /// If it is not ready it will return `None`. pub fn fetch(&self) -> Option> { diff --git a/crates/polars-pipe/src/executors/sinks/group_by/ooc_state.rs b/crates/polars-pipe/src/executors/sinks/group_by/ooc_state.rs index c51af7e81b3e..1f79e20bcdab 100644 --- a/crates/polars-pipe/src/executors/sinks/group_by/ooc_state.rs +++ b/crates/polars-pipe/src/executors/sinks/group_by/ooc_state.rs @@ -7,9 +7,8 @@ use crate::executors::sinks::io::IOThread; use crate::executors::sinks::memory::MemTracker; use crate::pipeline::morsels_per_sink; -/// THIS CODE DOESN'T MAKE SENSE -/// it is a remnant of OOC, but will be rewritten to use the generic OOC -/// Table +// THIS CODE DOESN'T MAKE SENSE +// It is a remnant of OOC, but will be rewritten to use the generic OOC Table. pub(super) struct OocState { // OOC diff --git a/crates/polars-plan/src/dsl/dt.rs b/crates/polars-plan/src/dsl/dt.rs index 141cff847207..6ee60ed9774d 100644 --- a/crates/polars-plan/src/dsl/dt.rs +++ b/crates/polars-plan/src/dsl/dt.rs @@ -113,7 +113,7 @@ impl DateLikeNameSpace { /// Extract the week from the underlying Date representation. /// Can be performed on Date and Datetime - + /// /// Returns the ISO week number starting from 1. /// The return value ranges from 1 to 53. (The last week of year differs by years.) pub fn week(self) -> Expr { @@ -123,7 +123,7 @@ impl DateLikeNameSpace { /// Extract the ISO week day from the underlying Date representation. /// Can be performed on Date and Datetime. - + /// /// Returns the weekday number where monday = 1 and sunday = 7 pub fn weekday(self) -> Expr { self.0 diff --git a/crates/polars-python/src/conversion/mod.rs b/crates/polars-python/src/conversion/mod.rs index fd8e97cb7adc..02f8e5008b88 100644 --- a/crates/polars-python/src/conversion/mod.rs +++ b/crates/polars-python/src/conversion/mod.rs @@ -287,7 +287,7 @@ impl ToPyObject for Wrap { Series::from_arrow(PlSmallStr::from_static("category"), categories.to_boxed()) .unwrap(); let series = to_series(py, s.into()); - return class.call1((series,)).unwrap().into(); + class.call1((series,)).unwrap().into() }, DataType::Time => pl.getattr(intern!(py, "Time")).unwrap().into(), DataType::Struct(fields) => { diff --git a/crates/polars-stream/src/nodes/parquet_source/row_group_decode.rs b/crates/polars-stream/src/nodes/parquet_source/row_group_decode.rs index 057d9e15d1f6..a0f48b70f919 100644 --- a/crates/polars-stream/src/nodes/parquet_source/row_group_decode.rs +++ b/crates/polars-stream/src/nodes/parquet_source/row_group_decode.rs @@ -457,9 +457,7 @@ pub(super) struct SharedFileState { file_path_series: Option, } -/// -/// Pre-filtered -/// +// Pre-filtered impl RowGroupDecoder { async fn row_group_data_to_df_prefiltered( diff --git a/crates/polars-utils/src/pl_str.rs b/crates/polars-utils/src/pl_str.rs index 72beb122b233..7fc909da50d9 100644 --- a/crates/polars-utils/src/pl_str.rs +++ b/crates/polars-utils/src/pl_str.rs @@ -54,7 +54,7 @@ impl Default for PlSmallStr { } } -/// AsRef, Deref and Borrow impls to &str +// AsRef, Deref and Borrow impls to &str impl AsRef for PlSmallStr { #[inline(always)] @@ -79,7 +79,7 @@ impl core::borrow::Borrow for PlSmallStr { } } -/// AsRef impls for other types +// AsRef impls for other types impl AsRef for PlSmallStr { #[inline(always)] @@ -102,7 +102,7 @@ impl AsRef for PlSmallStr { } } -/// From impls +// From impls impl From<&str> for PlSmallStr { #[inline(always)] @@ -132,7 +132,7 @@ impl From for PlSmallStr { } } -/// FromIterator impls +// FromIterator impls impl FromIterator for PlSmallStr { #[inline(always)] @@ -190,7 +190,7 @@ impl<'a> FromIterator> for PlSmallStr { } } -/// PartialEq impls +// PartialEq impls impl PartialEq for PlSmallStr where @@ -216,7 +216,7 @@ impl PartialEq for String { } } -/// Write +// Write impl core::fmt::Write for PlSmallStr { #[inline(always)] @@ -235,7 +235,7 @@ impl core::fmt::Write for PlSmallStr { } } -/// Debug, Display +// Debug, Display impl core::fmt::Debug for PlSmallStr { #[inline(always)] diff --git a/py-polars/build.rs b/py-polars/build.rs index cdb6a0b7e117..30306b33c706 100644 --- a/py-polars/build.rs +++ b/py-polars/build.rs @@ -1,4 +1,4 @@ -/// Build script using 'built' crate to generate build info. +//! Build script using 'built' crate to generate build info. fn main() { println!("cargo::rustc-check-cfg=cfg(allocator, values(\"default\", \"mimalloc\"))"); From 360cfa2f1ea11549dc4fdcd036c6fd6f9a9904b8 Mon Sep 17 00:00:00 2001 From: Stijn de Gooijer Date: Sun, 29 Sep 2024 14:56:29 +0200 Subject: [PATCH 7/7] Needless return async issue ignores --- crates/polars/tests/it/io/avro/read_async.rs | 9 +++++++++ crates/polars/tests/it/io/avro/write_async.rs | 3 +++ docs/source/src/rust/user-guide/io/cloud-storage.rs | 4 ++++ 3 files changed, 16 insertions(+) diff --git a/crates/polars/tests/it/io/avro/read_async.rs b/crates/polars/tests/it/io/avro/read_async.rs index d50fd7595c58..049910c0ce28 100644 --- a/crates/polars/tests/it/io/avro/read_async.rs +++ b/crates/polars/tests/it/io/avro/read_async.rs @@ -26,16 +26,25 @@ async fn test(codec: Codec) -> PolarsResult<()> { Ok(()) } +// Issue with clippy interacting with tokio. See: +// https://github.com/rust-lang/rust-clippy/issues/13458 +#[allow(clippy::needless_return)] #[tokio::test] async fn read_without_codec() -> PolarsResult<()> { test(Codec::Null).await } +// Issue with clippy interacting with tokio. See: +// https://github.com/rust-lang/rust-clippy/issues/13458 +#[allow(clippy::needless_return)] #[tokio::test] async fn read_deflate() -> PolarsResult<()> { test(Codec::Deflate).await } +// Issue with clippy interacting with tokio. See: +// https://github.com/rust-lang/rust-clippy/issues/13458 +#[allow(clippy::needless_return)] #[tokio::test] async fn read_snappy() -> PolarsResult<()> { test(Codec::Snappy).await diff --git a/crates/polars/tests/it/io/avro/write_async.rs b/crates/polars/tests/it/io/avro/write_async.rs index 77cb212f89db..1be109e2733a 100644 --- a/crates/polars/tests/it/io/avro/write_async.rs +++ b/crates/polars/tests/it/io/avro/write_async.rs @@ -42,6 +42,9 @@ async fn roundtrip(compression: Option) -> PolarsResult<()> { Ok(()) } +// Issue with clippy interacting with tokio. See: +// https://github.com/rust-lang/rust-clippy/issues/13458 +#[allow(clippy::needless_return)] #[tokio::test] async fn no_compression() -> PolarsResult<()> { roundtrip(None).await diff --git a/docs/source/src/rust/user-guide/io/cloud-storage.rs b/docs/source/src/rust/user-guide/io/cloud-storage.rs index 0c34f86bb2be..5c297739eeee 100644 --- a/docs/source/src/rust/user-guide/io/cloud-storage.rs +++ b/docs/source/src/rust/user-guide/io/cloud-storage.rs @@ -1,3 +1,7 @@ +// Issue with clippy interacting with tokio. See: +// https://github.com/rust-lang/rust-clippy/issues/13458 +#![allow(clippy::needless_return)] + // --8<-- [start:read_parquet] use aws_config::BehaviorVersion; use polars::prelude::*;