Skip to content

Commit

Permalink
Adding DataType option
Browse files Browse the repository at this point in the history
  • Loading branch information
Darek committed Jul 18, 2023
1 parent 20574a4 commit c1aeb71
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 15 deletions.
5 changes: 2 additions & 3 deletions polars/lazy/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ export function intRange<T>(opts: {
low: any;
high: any;
step: number;
eager: boolean;
eager?: boolean;
});
export function intRange(
low: any,
Expand All @@ -177,8 +177,7 @@ export function intRange(opts: any, high?, step = 1, eager?): Series | Expr {
.select(intRange(low, high, step).alias("intRange") as any)
.getColumn("intRange") as any;
}

return _Expr(pli.intRange(low, high, step));
return _Expr(pli.intRange(low, high, step, eager));
}
}
/** Alias for `pl.col("*")` */
Expand Down
5 changes: 1 addition & 4 deletions src/conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -624,11 +624,8 @@ impl FromNapiValue for Wrap<DataType> {
};

Ok(Wrap(dtype))
// Ok(Wrap(Schema::from(fields)))
}
_ => {
todo!()
}
_ => Err(Error::new(Status::InvalidArg, "not a valid conversion to 'DataType'".to_owned()))
}
}
}
Expand Down
16 changes: 8 additions & 8 deletions src/lazy/dsl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1525,27 +1525,27 @@ pub fn dtype_cols(dtypes: Vec<Wrap<DataType>>) -> crate::lazy::dsl::JsExpr {

#[cfg(feature = "range")]
#[napi(catch_unwind)]
pub fn int_range(start: Wrap<Expr>, end: Wrap<Expr>, step: i64, dtype: Wrap<DataType>) -> JsExpr {
let dtype = dtype.0;
pub fn int_range(start: Wrap<Expr>, end: Wrap<Expr>, step: i64, dtype: Option<Wrap<DataType>>) -> JsExpr {
let dtype = dtype.map(|d| d.0 as DataType);

let mut result = dsl::int_range(start.0, end.0, step);

if dtype != DataType::Int64 {
result = result.cast(dtype)
if dtype.is_some() && dtype.clone().unwrap() != DataType::Int64 {
result = result.cast(dtype.clone().unwrap());
}

result.into()
}

#[cfg(feature = "range")]
#[napi(catch_unwind)]
pub fn int_ranges(start: Wrap<Expr>, end: Wrap<Expr>, step: i64, dtype: Wrap<DataType>) -> JsExpr {
let dtype = dtype.0;
pub fn int_ranges(start: Wrap<Expr>, end: Wrap<Expr>, step: i64, dtype: Option<Wrap<DataType>>) -> JsExpr {
let dtype = dtype.map(|d| d.0 as DataType);

let mut result = dsl::int_ranges(start.0, end.0, step);

if dtype != DataType::Int64 {
result = result.cast(DataType::List(Box::new(dtype)))
if dtype.is_some() && dtype.clone().unwrap() != DataType::Int64 {
result = result.cast(DataType::List(Box::new(dtype.clone().unwrap())));
}

result.into()
Expand Down

0 comments on commit c1aeb71

Please sign in to comment.