Skip to content

Commit

Permalink
style[python]: Clean up imports in PyO3 bindings (#4630)
Browse files Browse the repository at this point in the history
  • Loading branch information
stinodego committed Aug 31, 2022
1 parent e047dc6 commit 355a847
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 52 deletions.
3 changes: 2 additions & 1 deletion py-polars/src/apply/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ pub mod series;

use polars::chunked_array::builder::get_list_builder;
use polars::prelude::*;
use polars_core::export::rayon::prelude::*;
use polars_core::utils::CustomIterTools;
use polars_core::{export::rayon::prelude::*, POOL};
use polars_core::POOL;
use pyo3::types::PyDict;
use pyo3::{PyAny, PyResult};

Expand Down
3 changes: 2 additions & 1 deletion py-polars/src/conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ use std::hash::{Hash, Hasher};

#[cfg(feature = "object")]
use polars::chunked_array::object::PolarsObjectSafe;
use polars::frame::groupby::PivotAgg;
use polars::frame::row::Row;
use polars::frame::{groupby::PivotAgg, NullStrategy};
use polars::frame::NullStrategy;
#[cfg(feature = "avro")]
use polars::io::avro::AvroCompression;
#[cfg(feature = "ipc")]
Expand Down
16 changes: 6 additions & 10 deletions py-polars/src/dataframe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ use polars_core::prelude::QuantileInterpolOptions;
use polars_core::utils::arrow::compute::cast::CastOptions;
use polars_core::utils::get_supertype;
use polars_lazy::frame::pivot::{pivot, pivot_stable};
use pyo3::exceptions::PyRuntimeError;
use pyo3::prelude::*;
use pyo3::types::{PyDict, PyList, PyTuple};
use pyo3::{exceptions::PyRuntimeError, prelude::*};

use crate::apply::dataframe::{
apply_lambda_unknown, apply_lambda_with_bool_out_type, apply_lambda_with_primitive_out_type,
Expand All @@ -29,17 +30,12 @@ use crate::apply::dataframe::{
#[cfg(feature = "parquet")]
use crate::conversion::parse_parquet_compression;
use crate::conversion::{ObjectValue, Wrap};
use crate::file::get_mmap_bytes_reader;
use crate::error::PyPolarsErr;
use crate::file::{get_either_file, get_file_like, get_mmap_bytes_reader, EitherRustPythonFile};
use crate::lazy::dataframe::PyLazyFrame;
use crate::prelude::dicts_to_rows;
use crate::{
arrow_interop,
error::PyPolarsErr,
file::{get_either_file, get_file_like, EitherRustPythonFile},
py_modules,
series::{to_pyseries_collection, to_series_collection, PySeries},
PyExpr,
};
use crate::series::{to_pyseries_collection, to_series_collection, PySeries};
use crate::{arrow_interop, py_modules, PyExpr};

#[pyclass]
#[repr(transparent)]
Expand Down
9 changes: 3 additions & 6 deletions py-polars/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@ use std::fmt::{Debug, Formatter};

use polars::prelude::PolarsError;
use polars_core::error::ArrowError;
use pyo3::exceptions::{PyIOError, PyValueError};
use pyo3::{
create_exception,
exceptions::{PyException, PyRuntimeError},
prelude::*,
};
use pyo3::create_exception;
use pyo3::exceptions::{PyException, PyIOError, PyRuntimeError, PyValueError};
use pyo3::prelude::*;
use thiserror::Error;

#[derive(Error)]
Expand Down
3 changes: 1 addition & 2 deletions py-polars/src/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ use std::io;
use std::io::{BufReader, Cursor, Read, Seek, SeekFrom, Write};

use polars::io::mmap::MmapBytesReader;
use pyo3::exceptions::PyFileNotFoundError;
use pyo3::exceptions::PyTypeError;
use pyo3::exceptions::{PyFileNotFoundError, PyTypeError};
use pyo3::prelude::*;
use pyo3::types::{PyBytes, PyString};

Expand Down
3 changes: 2 additions & 1 deletion py-polars/src/lazy/dataframe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ use crate::conversion::Wrap;
use crate::dataframe::PyDataFrame;
use crate::error::PyPolarsErr;
use crate::file::get_file_like;
use crate::lazy::{dsl::PyExpr, utils::py_exprs_to_exprs};
use crate::lazy::dsl::PyExpr;
use crate::lazy::utils::py_exprs_to_exprs;
use crate::prelude::*;
use crate::py_modules::POLARS;

Expand Down
3 changes: 1 addition & 2 deletions py-polars/src/lazy/dsl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ use pyo3::prelude::*;
use pyo3::types::{PyBool, PyBytes, PyFloat, PyInt, PyString};

use super::apply::*;
use crate::conversion::parse_fill_null_strategy;
use crate::conversion::Wrap;
use crate::conversion::{parse_fill_null_strategy, Wrap};
use crate::lazy::map_single;
use crate::lazy::utils::py_exprs_to_exprs;
use crate::series::PySeries;
Expand Down
1 change: 1 addition & 0 deletions py-polars/src/lazy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pub mod dsl;
#[cfg(feature = "meta")]
mod meta;
pub mod utils;

pub use apply::*;
use dsl::*;
use polars_lazy::prelude::*;
Expand Down
29 changes: 11 additions & 18 deletions py-polars/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,6 @@
extern crate core;
extern crate polars;

use pyo3::prelude::*;
use pyo3::wrap_pyfunction;

use crate::lazy::dsl::PyExpr;
use crate::{
dataframe::PyDataFrame,
file::EitherRustPythonFile,
lazy::{
dataframe::{PyLazyFrame, PyLazyGroupBy},
dsl,
},
series::PySeries,
};

pub mod apply;
pub mod arrow_interop;
pub mod conversion;
Expand All @@ -42,21 +28,27 @@ use mimalloc::MiMalloc;
use polars::functions::{diag_concat_df, hor_concat_df};
use polars::prelude::Null;
use polars_core::datatypes::TimeUnit;
use polars_core::prelude::IntoSeries;
use polars_core::prelude::{DataFrame, IDX_DTYPE};
use polars_core::prelude::{DataFrame, IntoSeries, IDX_DTYPE};
use polars_core::POOL;
use pyo3::panic::PanicException;
use pyo3::prelude::*;
use pyo3::types::{PyBool, PyDict, PyFloat, PyInt, PyString};
use pyo3::wrap_pyfunction;

use crate::conversion::{get_df, get_lf, get_pyseq, get_series, Wrap};
use crate::dataframe::PyDataFrame;
use crate::error::{
ArrowErrorException, ComputeError, DuplicateError, NoDataError, NotFoundError, PyPolarsErr,
SchemaError,
};
use crate::file::get_either_file;
use crate::file::{get_either_file, EitherRustPythonFile};
use crate::lazy::dataframe::{PyLazyFrame, PyLazyGroupBy};
use crate::lazy::dsl;
use crate::lazy::dsl::PyExpr;
use crate::prelude::{
vec_extract_wrapped, ClosedWindow, DataType, DatetimeArgs, Duration, DurationArgs,
};
use crate::series::PySeries;

#[global_allocator]
#[cfg(target_os = "linux")]
Expand Down Expand Up @@ -256,7 +248,8 @@ fn py_duration(

#[pyfunction]
fn concat_df(dfs: &PyAny, py: Python) -> PyResult<PyDataFrame> {
use polars_core::{error::Result, utils::rayon::prelude::*};
use polars_core::error::Result;
use polars_core::utils::rayon::prelude::*;

let (seq, _len) = get_pyseq(dfs)?;
let mut iter = seq.iter()?;
Expand Down
8 changes: 3 additions & 5 deletions py-polars/src/npy.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
use std::{mem, ptr};

use ndarray::IntoDimension;
use numpy::{
npyffi::{self, flags, types::npy_intp},
ToNpyDims, PY_ARRAY_API,
};
use numpy::{Element, PyArray1};
use numpy::npyffi::types::npy_intp;
use numpy::npyffi::{self, flags};
use numpy::{Element, PyArray1, ToNpyDims, PY_ARRAY_API};
use polars_core::utils::arrow::types::NativeType;
use pyo3::prelude::*;

Expand Down
12 changes: 6 additions & 6 deletions py-polars/src/series.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@ use numpy::PyArray1;
use polars_core::prelude::QuantileInterpolOptions;
use polars_core::series::IsSorted;
use polars_core::utils::CustomIterTools;
use pyo3::exceptions::PyRuntimeError;
use pyo3::prelude::*;
use pyo3::types::{PyBytes, PyList, PyTuple};
use pyo3::{exceptions::PyRuntimeError, prelude::*, Python};
use pyo3::Python;

use crate::apply::series::{call_lambda_and_extract, ApplyLambda};
use crate::arrow_interop::to_rust::array_to_rust;
use crate::dataframe::PyDataFrame;
use crate::error::PyPolarsErr;
use crate::list_construction::py_seq_to_list;
use crate::npy::{aligned_array, get_refcnt};
use crate::prelude::*;
use crate::set::set_at_idx;
use crate::{
apply_method_all_arrow_series2, arrow_interop,
npy::{aligned_array, get_refcnt},
prelude::*,
};
use crate::{apply_method_all_arrow_series2, arrow_interop};
#[pyclass]
#[repr(transparent)]
#[derive(Clone)]
Expand Down

0 comments on commit 355a847

Please sign in to comment.