Skip to content

Commit

Permalink
refactor[rust]: Enable grouped imports for rustfmt (#4409)
Browse files Browse the repository at this point in the history
  • Loading branch information
stinodego committed Aug 14, 2022
1 parent afc211c commit 9991a0d
Show file tree
Hide file tree
Showing 364 changed files with 1,541 additions and 1,124 deletions.
3 changes: 2 additions & 1 deletion polars/benches/bench.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#![feature(test)]
extern crate test;
use polars::prelude::*;
use std::iter;

use polars::prelude::*;
use test::Bencher;

#[bench]
Expand Down
3 changes: 2 additions & 1 deletion polars/benches/csv.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::fs::File;

use criterion::{criterion_group, criterion_main, Criterion};
use polars::prelude::*;
use std::fs::File;

fn prepare_reader() -> Result<CsvReader<'static, File>> {
let path =
Expand Down
1 change: 0 additions & 1 deletion polars/benches/sort.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#[macro_use]
extern crate criterion;
use criterion::Criterion;

use polars::prelude::*;

fn bench_sort(s: &Int32Chunked) {
Expand Down
3 changes: 2 additions & 1 deletion polars/polars-arrow/src/array/get.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use crate::is_valid::IsValid;
use arrow::{
array::{Array, BooleanArray, ListArray, PrimitiveArray, Utf8Array},
types::NativeType,
};

use crate::is_valid::IsValid;

pub trait ArrowGetItem {
type Item;

Expand Down
3 changes: 2 additions & 1 deletion polars/polars-arrow/src/array/list.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use crate::prelude::*;
use arrow::array::{Array, ListArray};
use arrow::bitmap::MutableBitmap;
use arrow::compute::concatenate;
use arrow::datatypes::DataType;
use arrow::error::Result;

use crate::prelude::*;

pub struct AnonymousBuilder<'a> {
arrays: Vec<&'a dyn Array>,
offsets: Vec<i64>,
Expand Down
2 changes: 1 addition & 1 deletion polars/polars-arrow/src/array/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::prelude::*;
use arrow::array::{Array, BooleanArray, ListArray, PrimitiveArray, Utf8Array};
use arrow::bitmap::MutableBitmap;
use arrow::datatypes::DataType;
use arrow::types::NativeType;

use crate::prelude::*;
use crate::utils::CustomIterTools;

pub mod default_arrays;
Expand Down
3 changes: 2 additions & 1 deletion polars/polars-arrow/src/compute/take/boolean.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use crate::index::IdxSize;
use arrow::{
array::{Array, BooleanArray, PrimitiveArray},
bitmap::{Bitmap, MutableBitmap},
};

use crate::index::IdxSize;

unsafe fn take_values(values: &Bitmap, indices: &[IdxSize]) -> Bitmap {
let values = indices.iter().map(|&index| {
debug_assert!((index as usize) < values.len());
Expand Down
7 changes: 4 additions & 3 deletions polars/polars-arrow/src/compute/take/mod.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
mod boolean;

use crate::trusted_len::{PushUnchecked, TrustedLen};
use crate::utils::with_match_primitive_type;
use crate::{bit_util::unset_bit_raw, prelude::*, utils::CustomIterTools};
use arrow::array::*;
use arrow::bitmap::MutableBitmap;
use arrow::buffer::Buffer;
use arrow::datatypes::{DataType, PhysicalType};
use arrow::types::NativeType;

use crate::trusted_len::{PushUnchecked, TrustedLen};
use crate::utils::with_match_primitive_type;
use crate::{bit_util::unset_bit_raw, prelude::*, utils::CustomIterTools};

/// # Safety
/// Does not do bounds checks
pub unsafe fn take_unchecked(arr: &dyn Array, idx: &IdxArr) -> ArrayRef {
Expand Down
3 changes: 2 additions & 1 deletion polars/polars-arrow/src/conversion.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use crate::prelude::*;
use arrow::array::StructArray;
use arrow::chunk::Chunk;
use arrow::datatypes::{DataType, Field};

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)
Expand Down
1 change: 1 addition & 0 deletions polars/polars-arrow/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::borrow::Cow;

use thiserror::Error as ThisError;

type ErrString = Cow<'static, str>;
Expand Down
3 changes: 2 additions & 1 deletion polars/polars-arrow/src/kernels/concatenate.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use crate::prelude::*;
use arrow::array::growable::make_growable;
use arrow::error::{Error as ArrowError, Result};

use crate::prelude::*;

/// Concatenate multiple [Array] of the same type into a single [`Array`].
/// This does not check the arrays types.
pub fn concatenate_owned_unchecked(arrays: &[ArrayRef]) -> Result<ArrayRef> {
Expand Down
6 changes: 4 additions & 2 deletions polars/polars-arrow/src/kernels/ewm/average.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use crate::trusted_len::{PushUnchecked, TrustedLen};
use num::Float;
use std::fmt::Debug;
use std::ops::AddAssign;

use num::Float;

use crate::trusted_len::{PushUnchecked, TrustedLen};
// See:
// https://github.com/pola-rs/polars/issues/2148
// https://stackoverflow.com/a/51392341/6717054
Expand Down
5 changes: 3 additions & 2 deletions polars/polars-arrow/src/kernels/float.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use crate::array::default_arrays::FromData;
use crate::prelude::*;
use arrow::array::{BooleanArray, PrimitiveArray};
use arrow::bitmap::Bitmap;
use arrow::types::NativeType;
use num::Float;

use crate::array::default_arrays::FromData;
use crate::prelude::*;

pub fn is_nan<T>(arr: &PrimitiveArray<T>) -> ArrayRef
where
T: NativeType + Float,
Expand Down
8 changes: 5 additions & 3 deletions polars/polars-arrow/src/kernels/list.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use arrow::array::ListArray;
use arrow::buffer::Buffer;

use crate::compute::take::take_unchecked;
use crate::prelude::*;
use crate::trusted_len::PushUnchecked;
use crate::utils::CustomIterTools;
use arrow::array::ListArray;
use arrow::buffer::Buffer;

/// Get the indices that would result in a get operation on the lists values.
/// for example, consider this list:
Expand Down Expand Up @@ -93,11 +94,12 @@ pub fn array_to_unit_list(array: ArrayRef) -> ListArray<i64> {

#[cfg(test)]
mod test {
use super::*;
use arrow::array::{Array, Int32Array, PrimitiveArray};
use arrow::buffer::Buffer;
use arrow::datatypes::DataType;

use super::*;

fn get_array() -> ListArray<i64> {
let values = Int32Array::from_slice(&[1, 2, 3, 4, 5, 6]);
let offsets = Buffer::from(vec![0i64, 3, 5, 6]);
Expand Down
3 changes: 2 additions & 1 deletion polars/polars-arrow/src/kernels/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::iter::Enumerate;

use arrow::array::BooleanArray;
use arrow::bitmap::utils::BitChunks;
use std::iter::Enumerate;
pub mod concatenate;
pub mod ewm;
pub mod float;
Expand Down
12 changes: 7 additions & 5 deletions polars/polars-arrow/src/kernels/rolling/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@ pub mod no_nulls;
pub mod nulls;
mod window;

use crate::data_types::IsFloat;
use crate::prelude::*;
use crate::utils::CustomIterTools;
use std::cmp::Ordering;
use std::ops::{Add, AddAssign, Div, Mul, Sub, SubAssign};

use arrow::array::PrimitiveArray;
use arrow::bitmap::{Bitmap, MutableBitmap};
use arrow::types::NativeType;
use num::ToPrimitive;
use num::{Bounded, Float, NumCast, One, Zero};
use std::cmp::Ordering;
use std::ops::{Add, AddAssign, Div, Mul, Sub, SubAssign};
use window::*;

use crate::data_types::IsFloat;
use crate::prelude::*;
use crate::utils::CustomIterTools;

type Start = usize;
type End = usize;
type Idx = usize;
Expand Down
3 changes: 2 additions & 1 deletion polars/polars-arrow/src/kernels/rolling/no_nulls/mean.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use no_nulls::{rolling_apply_agg_window, RollingAggWindowNoNulls};

use super::sum::SumWindow;
use super::*;
use no_nulls::{rolling_apply_agg_window, RollingAggWindowNoNulls};

pub struct MeanWindow<'a, T> {
sum: SumWindow<'a, T>,
Expand Down
3 changes: 2 additions & 1 deletion polars/polars-arrow/src/kernels/rolling/no_nulls/min_max.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use super::*;
use no_nulls;
use no_nulls::{rolling_apply_agg_window, RollingAggWindowNoNulls};

use super::*;

pub struct SortedMinMax<'a, T: NativeType> {
slice: &'a [T],
}
Expand Down
15 changes: 8 additions & 7 deletions polars/polars-arrow/src/kernels/rolling/no_nulls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,23 @@ mod quantile;
mod sum;
mod variance;

use super::*;
use crate::utils::CustomIterTools;
use std::fmt::Debug;

use arrow::array::PrimitiveArray;
use arrow::datatypes::DataType;
use arrow::types::NativeType;
use num::{Float, NumCast};
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
use std::fmt::Debug;

pub use mean::*;
pub use min_max::*;
use num::{Float, NumCast};
pub use quantile::*;
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
pub use sum::*;
pub use variance::*;

use super::*;
use crate::utils::CustomIterTools;

pub trait RollingAggWindowNoNulls<'a, T: NativeType> {
fn new(slice: &'a [T], start: usize, end: usize) -> Self;

Expand Down
3 changes: 2 additions & 1 deletion polars/polars-arrow/src/kernels/rolling/no_nulls/quantile.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use std::fmt::Debug;

use super::*;
use crate::index::IdxSize;
use crate::trusted_len::TrustedLen;
use std::fmt::Debug;

// used by agg_quantile
pub fn rolling_quantile_by_iter<T, O>(
Expand Down
3 changes: 2 additions & 1 deletion polars/polars-arrow/src/kernels/rolling/no_nulls/sum.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use super::*;
use no_nulls;
use no_nulls::{rolling_apply_agg_window, RollingAggWindowNoNulls};

use super::*;

pub struct SumWindow<'a, T> {
slice: &'a [T],
sum: T,
Expand Down
5 changes: 3 additions & 2 deletions polars/polars-arrow/src/kernels/rolling/no_nulls/variance.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use super::mean::MeanWindow;
use super::*;
use no_nulls::{rolling_apply_agg_window, RollingAggWindowNoNulls};
use num::pow::Pow;

use super::mean::MeanWindow;
use super::*;

pub(super) struct SumSquaredWindow<'a, T> {
slice: &'a [T],
sum_of_squares: T,
Expand Down
3 changes: 2 additions & 1 deletion polars/polars-arrow/src/kernels/rolling/nulls/min_max.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use super::*;
use arrow::bitmap::utils::{count_zeros, zip_validity};
use nulls;
use nulls::{rolling_apply_agg_window, RollingAggWindowNulls};

use super::*;

pub fn is_reverse_sorted_max_nulls<T: NativeType + PartialOrd + IsFloat>(
values: &[T],
validity: &Bitmap,
Expand Down
8 changes: 5 additions & 3 deletions polars/polars-arrow/src/kernels/rolling/nulls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ mod quantile;
mod sum;
mod variance;

use super::*;
pub use mean::*;
pub use min_max::*;
pub use quantile::*;
pub use sum::*;
pub use variance::*;

use super::*;

pub trait RollingAggWindowNulls<'a, T: NativeType> {
/// # Safety
/// `start` and `end` must be in bounds for `slice` and `validity`
Expand Down Expand Up @@ -85,11 +86,12 @@ where

#[cfg(test)]
mod test {
use super::*;
use crate::kernels::rolling::nulls::mean::rolling_mean;
use arrow::buffer::Buffer;
use arrow::datatypes::DataType;

use super::*;
use crate::kernels::rolling::nulls::mean::rolling_mean;

fn get_null_arr() -> PrimitiveArray<f64> {
// 1, None, -1, 4
let buf = Buffer::from(vec![1.0, 0.0, -1.0, 4.0]);
Expand Down
5 changes: 3 additions & 2 deletions polars/polars-arrow/src/kernels/rolling/nulls/quantile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,11 +294,12 @@ where

#[cfg(test)]
mod test {
use super::*;
use crate::kernels::rolling::nulls::{rolling_max, rolling_min};
use arrow::buffer::Buffer;
use arrow::datatypes::DataType;

use super::*;
use crate::kernels::rolling::nulls::{rolling_max, rolling_min};

#[test]
fn test_rolling_median_nulls() {
let buf = Buffer::from(vec![1.0, 2.0, 3.0, 4.0]);
Expand Down
3 changes: 2 additions & 1 deletion polars/polars-arrow/src/kernels/rolling/nulls/sum.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use super::*;
use nulls;
use nulls::{rolling_apply_agg_window, RollingAggWindowNulls};

use super::*;

pub struct SumWindow<'a, T> {
slice: &'a [T],
validity: &'a Bitmap,
Expand Down
3 changes: 2 additions & 1 deletion polars/polars-arrow/src/kernels/rolling/nulls/variance.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use super::*;
use mean::MeanWindow;
use nulls;
use nulls::{rolling_apply_agg_window, RollingAggWindowNulls};
use num::pow::Pow;

use super::*;

pub(super) struct SumSquaredWindow<'a, T> {
slice: &'a [T],
validity: &'a Bitmap,
Expand Down

0 comments on commit 9991a0d

Please sign in to comment.