Skip to content

Commit

Permalink
update node rolling methods (#2271)
Browse files Browse the repository at this point in the history
* update node rolling methods
  • Loading branch information
universalmind303 committed Jan 5, 2022
1 parent 82a2c65 commit d75e606
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 26 deletions.
2 changes: 1 addition & 1 deletion nodejs-polars/polars/lazy/expr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@ const _Expr = (_expr: any): Expr => {
rollingSum: rolling("rollingSum"),
rollingStd: rolling("rollingStd"),
rollingVar: rolling("rollingVar"),
rollingMedian: wrapUnary("rollingMedian", "windowSize"),
rollingMedian: rolling("rollingMedian"),
rollingQuantile: wrapBinary("rollingQuantile", "windowSize", "quantile"),
rollingSkew(val, bias=true) {
if(typeof val === "number") {
Expand Down
7 changes: 1 addition & 6 deletions nodejs-polars/polars/series.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1401,12 +1401,7 @@ export const seriesWrapper = <T>(_s: JsSeries): Series<T> => {
rollingSum: rolling("rolling_sum"),
rollingStd: rolling("rolling_std"),
rollingVar: rolling("rolling_var"),
rollingMedian(windowSize) {
return this
.toFrame()
.select(col(this.name).rollingMedian(windowSize))
.getColumn(this.name);
},
rollingMedian: rolling("rollingMedian"),
rollingQuantile(windowSize, quantile?) {
return this
.toFrame()
Expand Down
8 changes: 2 additions & 6 deletions nodejs-polars/polars/shared_traits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ export interface Rolling<T> {
* @param minPeriods The number of values in the window that should be non-null before computing a result.
* If undefined, it will be set equal to window size.
* @param center - Set the labels at the center of the window
* @see {@link rollingMean}, {@link rollingMin}, {@link rollingSum}, {@link rollingVar}
*/
rollingMax(options: RollingOptions): T
rollingMax(windowSize: number, weights?: Array<number>, minPeriods?: Array<number>, center?: boolean): T
Expand All @@ -149,7 +148,6 @@ export interface Rolling<T> {
* @param minPeriods The number of values in the window that should be non-null before computing a result.
* If undefined, it will be set equal to window size.
* @param center - Set the labels at the center of the window
* @see {@link rollingMax}, {@link rollingMin}, {@link rollingSum}, {@link rollingVar}
*/
rollingMean(options: RollingOptions): T
rollingMean(windowSize: number, weights?: Array<number>, minPeriods?: Array<number>, center?: boolean): T
Expand All @@ -167,7 +165,6 @@ export interface Rolling<T> {
* @param minPeriods The number of values in the window that should be non-null before computing a result.
* If undefined, it will be set equal to window size.
* @param center - Set the labels at the center of the window
* @see {@link rollingMax}, {@link rollingMean}, {@link rollingSum}, {@link rollingVar}
*/
rollingMin(options: RollingOptions): T
rollingMin(windowSize: number, weights?: Array<number>, minPeriods?: Array<number>, center?: boolean): T
Expand Down Expand Up @@ -218,13 +215,12 @@ export interface Rolling<T> {
* @param minPeriods The number of values in the window that should be non-null before computing a result.
* If undefined, it will be set equal to window size.
* @param center - Set the labels at the center of the window
* @see {@link rollingMax}, {@link rollingMin}, {@link rollingMean}, {@link rollingSum}
*/
rollingVar(options: RollingOptions): T
rollingVar(windowSize: number, weights?: Array<number>, minPeriods?: Array<number>, center?: boolean): T
/** Compute a rolling median */
rollingMedian(windowSize: number): T
rollingMedian({windowSize}: {windowSize: number}): T
rollingMedian(options: RollingOptions): T
rollingMedian(windowSize: number, weights?: Array<number>, minPeriods?: Array<number>, center?: boolean): T
/**
* Compute a rolling quantile
* @param windowSize Size of the rolling window
Expand Down
12 changes: 1 addition & 11 deletions nodejs-polars/src/lazy/dsl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -804,17 +804,7 @@ impl_rolling_method!(rolling_mean);
impl_rolling_method!(rolling_std);
impl_rolling_method!(rolling_var);
impl_rolling_method!(rolling_sum);

#[js_function(1)]
pub fn rolling_median(cx: CallContext) -> JsResult<JsExternal> {
let params = get_params(&cx)?;
let expr = params.get_external::<Expr>(&cx, "_expr")?;
let window_size = params.get_as::<usize>("windowSize")?;

expr.clone()
.rolling_apply_float(window_size, |ca| ChunkAgg::median(ca))
.try_into_js(&cx)
}
impl_rolling_method!(rolling_median);

#[js_function(1)]
pub fn rolling_quantile(cx: CallContext) -> JsResult<JsExternal> {
Expand Down
4 changes: 2 additions & 2 deletions nodejs-polars/src/lazy/lazyframe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ pub fn slice(cx: CallContext) -> JsResult<JsExternal> {
let params = get_params(&cx)?;
let ldf = params.get_external::<LazyFrame>(&cx, "_ldf")?.clone();
let offset: i64 = params.get_as("offset")?;
let len: usize = params.get_as("len")?;
let len: u32 = params.get_as("len")?;

ldf.slice(offset, len).try_into_js(&cx)
}
Expand All @@ -413,7 +413,7 @@ pub fn melt(cx: CallContext) -> JsResult<JsExternal> {
pub fn tail(cx: CallContext) -> JsResult<JsExternal> {
let params = get_params(&cx)?;
let ldf = params.get_external::<LazyFrame>(&cx, "_ldf")?.clone();
let length: usize = params.get_as("length")?;
let length: u32 = params.get_as("length")?;

ldf.tail(length).try_into_js(&cx)
}
Expand Down
1 change: 1 addition & 0 deletions nodejs-polars/src/series.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1292,6 +1292,7 @@ impl_rolling_method!(rolling_max);
impl_rolling_method!(rolling_min);
impl_rolling_method!(rolling_var);
impl_rolling_method!(rolling_std);
impl_rolling_method!(rolling_median);

macro_rules! impl_set_with_mask {
($name:ident, $native:ty, $cast:ident, $variant:ident) => {
Expand Down
1 change: 1 addition & 0 deletions nodejs-polars/src/series_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ impl JsSeries {
napi::Property::new(env, "rolling_min")?.with_method(rolling_min),
napi::Property::new(env, "rolling_sum")?.with_method(rolling_sum),
napi::Property::new(env, "rolling_std")?.with_method(rolling_std),
napi::Property::new(env, "rolling_median")?.with_method(rolling_median),
napi::Property::new(env, "rolling_var")?.with_method(rolling_var),
napi::Property::new(env, "round")?.with_method(round),
napi::Property::new(env, "sample_frac")?.with_method(sample_frac),
Expand Down

0 comments on commit d75e606

Please sign in to comment.