Skip to content

Commit

Permalink
Cargo fmt (#1899)
Browse files Browse the repository at this point in the history
  • Loading branch information
ghuls committed Nov 26, 2021
1 parent fcaa6f3 commit ac94b30
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ jobs:
pip install -r py-polars/build.requirements.txt
- name: Run formatting checks
run: |
cd py-polars && black --check . && isort --check . && cd ..
cd py-polars && black --check . && isort --check . && rustup override set nightly-2021-10-21 && cargo fmt --all -- --check && cd ..
- name: Run linting
run: |
cd py-polars && flake8 && cd ..
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/create-py-release-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install maturin==0.11.0
pip install maturin==0.12.1
- name: Publish wheel
shell: bash
env:
Expand Down
1 change: 1 addition & 0 deletions py-polars/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pre-commit:
mypy
flake8 .
make -C .. fmt_toml
cargo fmt --all

pip:
pip install --force-reinstall -U wheels/polars-*.whl
Expand Down
22 changes: 11 additions & 11 deletions py-polars/src/lazy/dataframe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ impl PyLazyFrame {
quote_char: Option<&str>,
null_values: Option<Wrap<NullValues>>,
infer_schema_length: Option<usize>,
with_schema_modify: Option<PyObject>
with_schema_modify: Option<PyObject>,
) -> PyResult<Self> {
let null_values = null_values.map(|w| w.0);
let comment_char = comment_char.map(|s| s.as_bytes()[0]);
Expand Down Expand Up @@ -166,31 +166,31 @@ impl PyLazyFrame {
.with_null_values(null_values);

if let Some(lambda) = with_schema_modify {
let f = | mut schema: Schema| {
let f = |mut schema: Schema| {
let gil = Python::acquire_gil();
let py = gil.python();

let iter = schema.fields().iter().map(|fld| fld.name().as_str());
let names = PyList::new(py, iter);

let out = lambda.call1(py, (names,)).expect("python function failed");
let new_names = out.extract::<Vec<String>>(py).expect("python function should return List[str]");
let new_names = out
.extract::<Vec<String>>(py)
.expect("python function should return List[str]");
assert_eq!(new_names.len(), schema.fields().len(), "The length of the new names list should be equal to the original column length");

schema.fields_mut().iter_mut().zip(new_names).for_each(|(fld, new_name)| {
fld.set_name(new_name)
});
schema
.fields_mut()
.iter_mut()
.zip(new_names)
.for_each(|(fld, new_name)| fld.set_name(new_name));

Ok(schema)
};
r = r.with_schema_modify(f).map_err(PyPolarsEr::from)?
}

Ok(
r
.finish()
.map_err(PyPolarsEr::from)?
.into())
Ok(r.finish().map_err(PyPolarsEr::from)?.into())
}

#[staticmethod]
Expand Down
22 changes: 14 additions & 8 deletions py-polars/src/lazy/dsl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ use crate::lazy::utils::py_exprs_to_exprs;
use crate::prelude::{parse_strategy, str_to_rankmethod};
use crate::series::PySeries;
use crate::utils::{reinterpret, str_to_polarstype};
use polars::chunked_array::temporal::timedelta::TimeDeltaBuilder;
use polars::lazy::dsl;
use polars::lazy::dsl::Operator;
use polars::prelude::*;
use pyo3::prelude::*;
use pyo3::types::{PyBool, PyFloat, PyInt, PyString};
use pyo3::{class::basic::CompareOp, PyNumberProtocol, PyObjectProtocol};
use polars::chunked_array::temporal::timedelta::{TimeDeltaBuilder};

#[pyclass]
#[repr(transparent)]
Expand Down Expand Up @@ -939,13 +939,19 @@ impl PyExpr {
.microseconds(microseconds)
.finish();

self.inner.clone().apply(move |s| {
match s.dtype() {
DataType::Datetime => Ok(s.datetime().unwrap().buckets(td).into_series()),
DataType::Date => Ok(s.date().unwrap().buckets(td).into_series()),
dt => Err(PolarsError::ComputeError(format!("expected date/datetime got {:?}", dt).into()))
}
}, GetOutput::same_type()).into()
self.inner
.clone()
.apply(
move |s| match s.dtype() {
DataType::Datetime => Ok(s.datetime().unwrap().buckets(td).into_series()),
DataType::Date => Ok(s.date().unwrap().buckets(td).into_series()),
dt => Err(PolarsError::ComputeError(
format!("expected date/datetime got {:?}", dt).into(),
)),
},
GetOutput::same_type(),
)
.into()
}

pub fn reshape(&self, dims: Vec<i64>) -> Self {
Expand Down

0 comments on commit ac94b30

Please sign in to comment.