Skip to content

Commit

Permalink
Updated magnus
Browse files Browse the repository at this point in the history
  • Loading branch information
ankane committed Jun 30, 2024
1 parent 1f08604 commit 830b729
Show file tree
Hide file tree
Showing 14 changed files with 53 additions and 58 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ext/polars/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ crate-type = ["cdylib"]
ahash = "0.8"
chrono = "0.4"
either = "1.8"
magnus = "0.6"
magnus = "0.7"
polars-core = "=0.41.2"
polars-parquet = "=0.41.2"
polars-utils = "=0.41.2"
Expand Down
6 changes: 3 additions & 3 deletions ext/polars/src/conversion/any_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,10 @@ impl<'s> TryConvert for Wrap<AnyValue<'s>> {
let list = v;

let mut avs = Vec::with_capacity(25);
let mut iter = list.each();
let mut iter = list.into_iter();

for item in (&mut iter).take(25) {
avs.push(Wrap::<AnyValue>::try_convert(item?)?.0)
avs.push(Wrap::<AnyValue>::try_convert(item)?.0)
}

let (dtype, _n_types) =
Expand All @@ -126,7 +126,7 @@ impl<'s> TryConvert for Wrap<AnyValue<'s>> {
// push the rest
avs.reserve(list.len());
for item in iter {
avs.push(Wrap::<AnyValue>::try_convert(item?)?.0)
avs.push(Wrap::<AnyValue>::try_convert(item)?.0)
}

let s = Series::from_any_values_and_dtype("", &avs, &dtype, true)
Expand Down
8 changes: 4 additions & 4 deletions ext/polars/src/conversion/chunked_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ impl TryConvert for Wrap<StringChunked> {
let (seq, len) = get_rbseq(obj)?;
let mut builder = StringChunkedBuilder::new("", len);

for res in seq.each() {
let item = res?;
for res in seq.into_iter() {
let item = res;
match String::try_convert(item) {
Ok(val) => builder.append_value(&val),
Err(_) => builder.append_null(),
Expand All @@ -27,8 +27,8 @@ impl TryConvert for Wrap<BinaryChunked> {
let (seq, len) = get_rbseq(obj)?;
let mut builder = BinaryChunkedBuilder::new("", len);

for res in seq.each() {
let item = res?;
for res in seq.into_iter() {
let item = res;
match RString::try_convert(item) {
Ok(val) => builder.append_value(unsafe { val.as_slice() }),
Err(_) => builder.append_null(),
Expand Down
8 changes: 4 additions & 4 deletions ext/polars/src/conversion/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,8 +379,8 @@ impl TryConvert for Wrap<DataType> {
"Polars::Struct" => {
let arr: RArray = ob.funcall("fields", ())?;
let mut fields = Vec::with_capacity(arr.len());
for v in arr.each() {
fields.push(Wrap::<Field>::try_convert(v?)?.0);
for v in arr.into_iter() {
fields.push(Wrap::<Field>::try_convert(v)?.0);
}
DataType::Struct(fields)
}
Expand Down Expand Up @@ -455,8 +455,8 @@ impl TryConvert for Wrap<StatisticsOptions> {
impl<'s> TryConvert for Wrap<Row<'s>> {
fn try_convert(ob: Value) -> RbResult<Self> {
let mut vals: Vec<Wrap<AnyValue<'s>>> = Vec::new();
for item in RArray::try_convert(ob)?.each() {
vals.push(Wrap::<AnyValue<'s>>::try_convert(item?)?);
for item in RArray::try_convert(ob)?.into_iter() {
vals.push(Wrap::<AnyValue<'s>>::try_convert(item)?);
}
let vals: Vec<AnyValue> = unsafe { std::mem::transmute(vals) };
Ok(Wrap(Row(vals)))
Expand Down
14 changes: 6 additions & 8 deletions ext/polars/src/dataframe/construction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ impl RbDataFrame {
schema: Option<Wrap<Schema>>,
) -> RbResult<Self> {
let mut data = Vec::with_capacity(rb_rows.len());
for v in rb_rows.each() {
let rb_row = RArray::try_convert(v?)?;
for v in rb_rows.into_iter() {
let rb_row = RArray::try_convert(v)?;
let mut row = Vec::with_capacity(rb_row.len());
for val in rb_row.each() {
row.push(Wrap::<AnyValue>::try_convert(val?)?.0);
for val in rb_row.into_iter() {
row.push(Wrap::<AnyValue>::try_convert(val)?.0);
}
data.push(Row(row));
}
Expand Down Expand Up @@ -130,8 +130,7 @@ where
fn dicts_to_rows<'a>(data: &Value, names: &'a [String], _strict: bool) -> RbResult<Vec<Row<'a>>> {
let (data, len) = get_rbseq(*data)?;
let mut rows = Vec::with_capacity(len);
for d in data.each() {
let d = d?;
for d in data.into_iter() {
let d = RHash::try_convert(d)?;

let mut row = Vec::with_capacity(names.len());
Expand Down Expand Up @@ -170,8 +169,7 @@ fn infer_schema_names_from_data(
.unwrap_or(data_len);

let mut names = PlIndexSet::new();
for d in data.each().take(infer_schema_length) {
let d = d?;
for d in data.into_iter().take(infer_schema_length) {
let d = RHash::try_convert(d)?;
d.foreach(|name: Value, _value: Value| {
if let Some(v) = Symbol::from_value(name) {
Expand Down
4 changes: 2 additions & 2 deletions ext/polars/src/dataframe/general.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ use crate::{RbDataFrame, RbExpr, RbLazyFrame, RbPolarsErr, RbResult, RbSeries};
impl RbDataFrame {
pub fn init(columns: RArray) -> RbResult<Self> {
let mut cols = Vec::new();
for i in columns.each() {
cols.push(<&RbSeries>::try_convert(i?)?.series.borrow().clone());
for i in columns.into_iter() {
cols.push(<&RbSeries>::try_convert(i)?.series.borrow().clone());
}
let df = DataFrame::new(cols).map_err(RbPolarsErr::from)?;
Ok(RbDataFrame::new(df))
Expand Down
4 changes: 2 additions & 2 deletions ext/polars/src/expr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ impl From<Expr> for RbExpr {

pub fn rb_exprs_to_exprs(rb_exprs: RArray) -> RbResult<Vec<Expr>> {
let mut exprs = Vec::new();
for item in rb_exprs.each() {
exprs.push(<&RbExpr>::try_convert(item?)?.inner.clone());
for item in rb_exprs.into_iter() {
exprs.push(<&RbExpr>::try_convert(item)?.inner.clone());
}
Ok(exprs)
}
20 changes: 10 additions & 10 deletions ext/polars/src/functions/eager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ use crate::{RbDataFrame, RbResult, RbSeries};
pub fn concat_df(seq: RArray) -> RbResult<RbDataFrame> {
use polars_core::error::PolarsResult;

let mut iter = seq.each();
let first = iter.next().unwrap()?;
let mut iter = seq.into_iter();
let first = iter.next().unwrap();

let first_rdf = get_df(first)?;
let identity_df = first_rdf.slice(0, 0);

let mut rdfs: Vec<PolarsResult<DataFrame>> = vec![Ok(first_rdf)];

for item in iter {
let rdf = get_df(item?)?;
let rdf = get_df(item)?;
rdfs.push(Ok(rdf));
}

Expand All @@ -37,13 +37,13 @@ pub fn concat_df(seq: RArray) -> RbResult<RbDataFrame> {
}

pub fn concat_series(seq: RArray) -> RbResult<RbSeries> {
let mut iter = seq.each();
let first = iter.next().unwrap()?;
let mut iter = seq.into_iter();
let first = iter.next().unwrap();

let mut s = get_series(first)?;

for res in iter {
let item = res?;
let item = res;
let item = get_series(item)?;
s.append(&item).map_err(RbPolarsErr::from)?;
}
Expand All @@ -52,17 +52,17 @@ pub fn concat_series(seq: RArray) -> RbResult<RbSeries> {

pub fn concat_df_diagonal(seq: RArray) -> RbResult<RbDataFrame> {
let mut dfs = Vec::new();
for item in seq.each() {
dfs.push(get_df(item?)?);
for item in seq.into_iter() {
dfs.push(get_df(item)?);
}
let df = functions::concat_df_diagonal(&dfs).map_err(RbPolarsErr::from)?;
Ok(df.into())
}

pub fn concat_df_horizontal(seq: RArray) -> RbResult<RbDataFrame> {
let mut dfs = Vec::new();
for item in seq.each() {
dfs.push(get_df(item?)?);
for item in seq.into_iter() {
dfs.push(get_df(item)?);
}
let df = functions::concat_df_horizontal(&dfs).map_err(RbPolarsErr::from)?;
Ok(df.into())
Expand Down
19 changes: 8 additions & 11 deletions ext/polars/src/functions/lazy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ pub fn col(name: String) -> RbExpr {

pub fn collect_all(lfs: RArray) -> RbResult<RArray> {
let lfs = lfs
.each()
.map(|v| <&RbLazyFrame>::try_convert(v?))
.into_iter()
.map(|v| <&RbLazyFrame>::try_convert(v))
.collect::<RbResult<Vec<&RbLazyFrame>>>()?;

Ok(RArray::from_iter(lfs.iter().map(|lf| {
Expand All @@ -118,8 +118,8 @@ pub fn concat_lf(
let (seq, len) = get_rbseq(lfs)?;
let mut lfs = Vec::with_capacity(len);

for res in seq.each() {
let item = res?;
for res in seq.into_iter() {
let item = res;
let lf = get_lf(item)?;
lfs.push(lf);
}
Expand Down Expand Up @@ -184,13 +184,10 @@ pub fn concat_lf_diagonal(
parallel: bool,
to_supertypes: bool,
) -> RbResult<RbLazyFrame> {
let iter = lfs.each();
let iter = lfs.into_iter();

let lfs = iter
.map(|item| {
let item = item?;
get_lf(item)
})
.map(|item| get_lf(item))
.collect::<RbResult<Vec<_>>>()?;

let lf = dsl::functions::concat_lf_diagonal(
Expand All @@ -212,8 +209,8 @@ pub fn dtype_cols(dtypes: Vec<DataType>) -> RbExpr {

pub fn dtype_cols2(dtypes: RArray) -> RbResult<RbExpr> {
let dtypes = dtypes
.each()
.map(|v| Wrap::<DataType>::try_convert(v?))
.into_iter()
.map(|v| Wrap::<DataType>::try_convert(v))
.collect::<RbResult<Vec<Wrap<DataType>>>>()?;
let dtypes = vec_extract_wrapped(dtypes);
Ok(crate::functions::lazy::dtype_cols(dtypes))
Expand Down
4 changes: 2 additions & 2 deletions ext/polars/src/lazyframe/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -535,8 +535,8 @@ impl RbLazyFrame {

pub fn with_context(&self, contexts: RArray) -> RbResult<Self> {
let contexts = contexts
.each()
.map(|v| TryConvert::try_convert(v.unwrap()))
.into_iter()
.map(|v| TryConvert::try_convert(v))
.collect::<RbResult<Vec<&RbLazyFrame>>>()?;
let contexts = contexts
.into_iter()
Expand Down
4 changes: 2 additions & 2 deletions ext/polars/src/map/dataframe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,8 @@ pub fn apply_lambda_with_rows_output<'a>(
match RArray::try_convert(val).ok() {
Some(tuple) => {
row_buf.0.clear();
for v in tuple.each() {
let v = Wrap::<AnyValue>::try_convert(v.unwrap()).unwrap().0;
for v in tuple.into_iter() {
let v = Wrap::<AnyValue>::try_convert(v).unwrap().0;
row_buf.0.push(v);
}
let ptr = &row_buf as *const Row;
Expand Down
10 changes: 5 additions & 5 deletions ext/polars/src/series/construction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ init_method_opt!(new_opt_f64, Float64Type, f64);

fn vec_wrap_any_value<'s>(arr: RArray) -> RbResult<Vec<Wrap<AnyValue<'s>>>> {
let mut val = Vec::with_capacity(arr.len());
for v in arr.each() {
val.push(Wrap::<AnyValue<'s>>::try_convert(v?)?);
for v in arr.into_iter() {
val.push(Wrap::<AnyValue<'s>>::try_convert(v)?);
}
Ok(val)
}
Expand Down Expand Up @@ -138,9 +138,9 @@ impl RbSeries {

pub fn new_object(name: String, val: RArray, _strict: bool) -> RbResult<Self> {
let val = val
.each()
.map(|v| v.map(ObjectValue::from))
.collect::<RbResult<Vec<ObjectValue>>>()?;
.into_iter()
.map(ObjectValue::from)
.collect::<Vec<ObjectValue>>();
let s = ObjectChunked::<ObjectValue>::new_from_vec(&name, val).into_series();
Ok(s.into())
}
Expand Down
4 changes: 2 additions & 2 deletions ext/polars/src/series/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ impl RbSeries {

pub fn to_series_collection(rs: RArray) -> RbResult<Vec<Series>> {
let mut series = Vec::new();
for item in rs.each() {
series.push(<&RbSeries>::try_convert(item?)?.series.borrow().clone());
for item in rs.into_iter() {
series.push(<&RbSeries>::try_convert(item)?.series.borrow().clone());
}
Ok(series)
}
Expand Down

0 comments on commit 830b729

Please sign in to comment.