nodejs-polars
Advanced tools
Comparing version 0.8.0 to 0.8.1
@@ -929,4 +929,4 @@ /// <reference types="node" /> | ||
nullCount(): DataFrame; | ||
partitionBy(cols: string | string[], stable?: boolean): DataFrame[]; | ||
partitionBy<T>(cols: string | string[], stable: boolean, mapFn: (df: DataFrame) => T): T[]; | ||
partitionBy(cols: string | string[], stable?: boolean, includeKey?: boolean): DataFrame[]; | ||
partitionBy<T>(cols: string | string[], stable: boolean, includeKey: boolean, mapFn: (df: DataFrame) => T): T[]; | ||
/** | ||
@@ -1242,6 +1242,7 @@ * | ||
*/ | ||
sort(by: ColumnsOrExpr, reverse?: boolean): DataFrame; | ||
sort({ by, reverse }: { | ||
sort(by: ColumnsOrExpr, descending?: boolean, maintain_order?: boolean): DataFrame; | ||
sort({ by, descending, maintain_order, }: { | ||
by: ColumnsOrExpr; | ||
reverse?: boolean; | ||
descending?: boolean; | ||
maintain_order?: boolean; | ||
}): DataFrame; | ||
@@ -1248,0 +1249,0 @@ /** |
@@ -181,3 +181,3 @@ "use strict"; | ||
groupByRolling(opts) { | ||
return (0, groupby_1.RollingGroupBy)((0, exports._DataFrame)(_df), opts.indexColumn, opts.period, opts.offset, opts.closed, opts.by); | ||
return (0, groupby_1.RollingGroupBy)((0, exports._DataFrame)(_df), opts.indexColumn, opts.period, opts.offset, opts.closed, opts.by, opts.check_sorted); | ||
}, | ||
@@ -273,5 +273,7 @@ groupByDynamic({ indexColumn, every, period, offset, truncate, includeBoundaries, closed, by, }) { | ||
}, | ||
partitionBy(by, strict = false, mapFn = (df) => df) { | ||
partitionBy(by, strict = false, includeKey, mapFn = (df) => df) { | ||
by = Array.isArray(by) ? by : [by]; | ||
return _df.partitionBy(by, strict).map((d) => mapFn((0, exports._DataFrame)(d))); | ||
return _df | ||
.partitionBy(by, strict, includeKey) | ||
.map((d) => mapFn((0, exports._DataFrame)(d))); | ||
}, | ||
@@ -380,5 +382,5 @@ pivot(values, options) { | ||
}, | ||
sort(arg, reverse = false) { | ||
sort(arg, descending = false, maintain_order = false) { | ||
if (arg?.by !== undefined) { | ||
return this.sort(arg.by, arg.reverse); | ||
return this.sort(arg.by, arg.descending); | ||
} | ||
@@ -388,6 +390,6 @@ if (Array.isArray(arg) || expr_1.Expr.isExpr(arg)) { | ||
.lazy() | ||
.sort(arg, reverse) | ||
.sort(arg, descending, maintain_order) | ||
.collectSync({ noOptimization: true, stringCache: false }); | ||
} | ||
return wrap("sort", arg, reverse, true, false); | ||
return wrap("sort", arg, descending, maintain_order, true, false); | ||
}, | ||
@@ -515,19 +517,28 @@ std() { | ||
transpose(options) { | ||
const df = wrap("transpose", options?.includeHeader ?? false, options?.headerName ?? ""); | ||
const includeHeader = options?.includeHeader ?? false; | ||
const headeName = options?.headerName ?? "column"; | ||
const keep_names_as = includeHeader ? headeName : undefined; | ||
if (options?.columnNames) { | ||
function* namesIter() { | ||
if (options?.includeHeader) { | ||
yield options.headerName; | ||
function takeNItems(iterable, n) { | ||
const result = []; | ||
let i = 0; | ||
for (const item of iterable) { | ||
if (i >= n) { | ||
break; | ||
} | ||
result.push(item); | ||
i++; | ||
} | ||
const gen = options.columnNames[Symbol.iterator](); | ||
let next; | ||
// rome-ignore lint: no-cond-assign | ||
while ((next = gen.next())) { | ||
yield next.value; | ||
} | ||
return result; | ||
} | ||
const newColumns = Array.from({ length: df.width }, ((i) => () => i.next().value)(namesIter())); | ||
df.columns = newColumns; | ||
options.columnNames = Array.isArray(options.columnNames) | ||
? options.columnNames.slice(this.height) | ||
: takeNItems(options.columnNames, this.height); | ||
} | ||
return df; | ||
if (!options?.columnNames) { | ||
return wrap("transpose", keep_names_as, undefined); | ||
} | ||
else { | ||
return wrap("transpose", keep_names_as, options.columnNames); | ||
} | ||
}, | ||
@@ -534,0 +545,0 @@ unnest(names) { |
@@ -164,3 +164,3 @@ import { DataFrame } from "./dataframe"; | ||
/** @ignore */ | ||
export declare function RollingGroupBy(df: any, indexColumn: string, period: string, offset?: string, closed?: any, by?: ColumnsOrExpr): RollingGroupBy; | ||
export declare function RollingGroupBy(df: any, indexColumn: ColumnsOrExpr, period: string, offset?: string, closed?: any, by?: ColumnsOrExpr, check_sorted?: boolean): RollingGroupBy; | ||
/** | ||
@@ -167,0 +167,0 @@ * intermediate state of a dynamic groupby |
@@ -111,3 +111,3 @@ "use strict"; | ||
/** @ignore */ | ||
function RollingGroupBy(df, indexColumn, period, offset, closed, by) { | ||
function RollingGroupBy(df, indexColumn, period, offset, closed, by, check_sorted) { | ||
return { | ||
@@ -117,3 +117,10 @@ agg(column, ...columns) { | ||
.lazy() | ||
.groupByRolling({ indexColumn, period, offset, closed, by }) | ||
.groupByRolling({ | ||
indexColumn, | ||
period, | ||
offset, | ||
closed, | ||
by, | ||
check_sorted, | ||
}) | ||
.agg(column, ...columns) | ||
@@ -120,0 +127,0 @@ .collectSync(); |
@@ -27,4 +27,5 @@ import * as series from "./series"; | ||
type When = lazy.When; | ||
type WhenThen = lazy.WhenThen; | ||
type WhenThenThen = lazy.WhenThenThen; | ||
type Then = lazy.Then; | ||
type ChainedWhen = lazy.ChainedWhen; | ||
type ChainedThen = lazy.ChainedThen; | ||
export import Config = cfg.Config; | ||
@@ -69,3 +70,4 @@ export import Int8 = DataType.Int8; | ||
export import lit = lazy.lit; | ||
export import arange = lazy.arange; | ||
export import intRange = lazy.intRange; | ||
export import intRanges = lazy.intRanges; | ||
export import argSortBy = lazy.argSortBy; | ||
@@ -72,0 +74,0 @@ export import avg = lazy.avg; |
@@ -105,3 +105,4 @@ "use strict"; | ||
pl.lit = lazy.lit; | ||
pl.arange = lazy.arange; | ||
pl.intRange = lazy.intRange; | ||
pl.intRanges = lazy.intRanges; | ||
pl.argSortBy = lazy.argSortBy; | ||
@@ -108,0 +109,0 @@ pl.avg = lazy.avg; |
@@ -375,6 +375,7 @@ import { DataFrame } from "../dataframe"; | ||
*/ | ||
sort(by: ColumnsOrExpr, reverse?: ValueOrArray<boolean>): LazyDataFrame; | ||
sort(by: ColumnsOrExpr, descending?: ValueOrArray<boolean>, maintain_order?: boolean): LazyDataFrame; | ||
sort(opts: { | ||
by: ColumnsOrExpr; | ||
reverse?: ValueOrArray<boolean>; | ||
descending?: ValueOrArray<boolean>; | ||
maintain_order?: boolean; | ||
}): LazyDataFrame; | ||
@@ -381,0 +382,0 @@ /** |
@@ -144,10 +144,11 @@ "use strict"; | ||
}, | ||
groupByRolling({ indexColumn, by, period, offset, closed }) { | ||
groupByRolling({ indexColumn, by, period, offset, closed, check_sorted }) { | ||
offset = offset ?? `-${period}`; | ||
closed = closed ?? "right"; | ||
by = prepareGroupbyInputs(by); | ||
const lgb = _ldf.groupbyRolling(indexColumn, period, offset, closed, by); | ||
check_sorted = check_sorted ?? false; | ||
const lgb = _ldf.groupbyRolling(polars_internal_1.default.col(indexColumn), period, offset, closed, by, check_sorted); | ||
return (0, groupby_1._LazyGroupBy)(lgb); | ||
}, | ||
groupByDynamic({ indexColumn, every, period, offset, truncate, includeBoundaries, closed, by, start_by, }) { | ||
groupByDynamic({ indexColumn, every, period, offset, truncate, includeBoundaries, closed, by, start_by, check_sorted, }) { | ||
period = period ?? every; | ||
@@ -160,3 +161,4 @@ offset = offset ?? `-${period}`; | ||
start_by = start_by ?? "monday"; | ||
const lgb = _ldf.groupbyDynamic(indexColumn, every, period, offset, truncate, includeBoundaries, closed, by, start_by); | ||
check_sorted = check_sorted ?? false; | ||
const lgb = _ldf.groupbyDynamic(polars_internal_1.default.col(indexColumn), every, period, offset, truncate, includeBoundaries, closed, by, start_by, check_sorted); | ||
return (0, groupby_1._LazyGroupBy)(lgb); | ||
@@ -309,13 +311,13 @@ }, | ||
}, | ||
sort(arg, reverse = false) { | ||
sort(arg, descending = false, maintain_order = false) { | ||
if (arg?.by !== undefined) { | ||
return this.sort(arg.by, arg.reverse); | ||
return this.sort(arg.by, arg.descending, arg.maintain_order); | ||
} | ||
if (typeof arg === "string") { | ||
return wrap("sort", arg, reverse, true, false); | ||
return wrap("sort", arg, descending, maintain_order, true, false); | ||
} | ||
else { | ||
reverse = [reverse].flat(3); | ||
descending = [descending].flat(3); | ||
const by = (0, utils_1.selectionToExprList)(arg, false); | ||
return wrap("sortByExprs", by, reverse, true); | ||
return wrap("sortByExprs", by, descending, maintain_order, true); | ||
} | ||
@@ -322,0 +324,0 @@ }, |
@@ -98,5 +98,6 @@ import * as dt from "./datetime"; | ||
*/ | ||
argSort(reverse?: boolean): Expr; | ||
argSort({ reverse }: { | ||
reverse: boolean; | ||
argSort(reverse?: boolean, maintain_order?: boolean): Expr; | ||
argSort({ reverse, maintain_order, }: { | ||
reverse?: boolean; | ||
maintain_order?: boolean; | ||
}): Expr; | ||
@@ -103,0 +104,0 @@ /** Get index of first unique value. */ |
@@ -117,5 +117,6 @@ "use strict"; | ||
}, | ||
argSort(reverse = false) { | ||
argSort(reverse = false, maintain_order) { | ||
reverse = reverse?.reverse ?? reverse; | ||
return (0, exports._Expr)(_expr.argSort(reverse, false)); | ||
maintain_order = reverse?.maintain_order ?? maintain_order; | ||
return (0, exports._Expr)(_expr.argSort(reverse, false, false, maintain_order)); | ||
}, | ||
@@ -359,5 +360,5 @@ argUnique() { | ||
rollingMedian: rolling("rollingMedian"), | ||
rollingQuantile(val, interpolation, windowSize, weights, minPeriods, center) { | ||
rollingQuantile(val, interpolation, windowSize, weights, minPeriods, center, by, closedWindow) { | ||
if (typeof val === "number") { | ||
return wrap("rollingQuantile", val, interpolation ?? "nearest", { | ||
return wrap("rollingQuantile", { | ||
windowSize: `${windowSize}i`, | ||
@@ -374,9 +375,3 @@ weights, | ||
} | ||
const options = { | ||
windowSize: `${windowSize}i`, | ||
weights: val?.["weights"] ?? weights, | ||
minPeriods: val?.["minPeriods"] ?? minPeriods ?? windowSize, | ||
center: val?.["center"] ?? center ?? false, | ||
}; | ||
return wrap("rollingQuantile", val.quantile, val.interpolation ?? "nearest", options); | ||
return wrap("rollingQuantile", val.quantile, val.interpolation ?? "nearest", `${windowSize}i`, val?.["weights"] ?? weights ?? null, val?.["minPeriods"] ?? minPeriods ?? windowSize, val?.["center"] ?? center ?? false, val?.["by"] ?? by, val?.["closedWindow"] ?? closedWindow ?? "left"); | ||
}, | ||
@@ -429,7 +424,7 @@ rollingSkew(val, bias = true) { | ||
}, | ||
sort(reverse = false, nullsLast = false) { | ||
sort(reverse = false, nullsLast = false, maintain_order = false) { | ||
if (typeof reverse === "boolean") { | ||
return wrap("sortWith", reverse, nullsLast, false); | ||
return wrap("sortWith", reverse, nullsLast, false, maintain_order); | ||
} | ||
return wrap("sortWith", reverse?.reverse ?? false, reverse?.nullsLast ?? nullsLast, false); | ||
return wrap("sortWith", reverse?.reverse ?? false, reverse?.nullsLast ?? nullsLast, false, reverse?.maintain_order ?? maintain_order); | ||
}, | ||
@@ -436,0 +431,0 @@ sortBy(arg, reverse = false) { |
@@ -43,10 +43,10 @@ "use strict"; | ||
diff(n = 1, nullBehavior = "ignore") { | ||
return wrap("lstDiff", n, nullBehavior); | ||
return wrap("listDiff", n, nullBehavior); | ||
}, | ||
get(index) { | ||
if (expr_1.Expr.isExpr(index)) { | ||
return wrap("lstGet", index._expr); | ||
return wrap("listGet", index._expr); | ||
} | ||
else { | ||
return wrap("lstGet", polars_internal_1.default.lit(index)); | ||
return wrap("listGet", polars_internal_1.default.lit(index)); | ||
} | ||
@@ -62,6 +62,6 @@ }, | ||
if (expr_1.Expr.isExpr(expr)) { | ||
return wrap("lstEval", expr._expr, parallel); | ||
return wrap("listEval", expr._expr, parallel); | ||
} | ||
else { | ||
return wrap("lstEval", expr, parallel); | ||
return wrap("listEval", expr, parallel); | ||
} | ||
@@ -73,3 +73,3 @@ }, | ||
join(separator = ",") { | ||
return wrap("lstJoin", separator); | ||
return wrap("listJoin", separator); | ||
}, | ||
@@ -80,32 +80,32 @@ last() { | ||
lengths() { | ||
return wrap("lstLengths"); | ||
return wrap("listLengths"); | ||
}, | ||
max() { | ||
return wrap("lstMax"); | ||
return wrap("listMax"); | ||
}, | ||
mean() { | ||
return wrap("lstMean"); | ||
return wrap("listMean"); | ||
}, | ||
min() { | ||
return wrap("lstMin"); | ||
return wrap("listMin"); | ||
}, | ||
reverse() { | ||
return wrap("lstReverse"); | ||
return wrap("listReverse"); | ||
}, | ||
shift(n) { | ||
return wrap("lstShift", n); | ||
return wrap("listShift", n); | ||
}, | ||
slice(offset, length) { | ||
return wrap("lstSlice", offset, length); | ||
return wrap("listSlice", offset, length); | ||
}, | ||
sort(reverse = false) { | ||
return typeof reverse === "boolean" | ||
? wrap("lstSort", reverse) | ||
: wrap("lstSort", reverse.reverse); | ||
? wrap("listSort", reverse) | ||
: wrap("listSort", reverse.reverse); | ||
}, | ||
sum() { | ||
return wrap("lstSum"); | ||
return wrap("listSum"); | ||
}, | ||
unique() { | ||
return wrap("lstUnique"); | ||
return wrap("listUnique"); | ||
}, | ||
@@ -112,0 +112,0 @@ }; |
@@ -112,2 +112,26 @@ import { StringFunctions } from "../../shared_traits"; | ||
/** | ||
* Parse string values as JSON. | ||
* Throw errors if encounter invalid JSON strings. | ||
* @params Not implemented ATM | ||
* @returns DF with struct | ||
* @example | ||
* >>> df = pl.DataFrame( {json: ['{"a":1, "b": true}', null, '{"a":2, "b": false}']} ) | ||
* >>> df.select(pl.col("json").str.jsonExtract()) | ||
* shape: (3, 1) | ||
* ┌─────────────┐ | ||
* │ json │ | ||
* │ --- │ | ||
* │ struct[2] │ | ||
* ╞═════════════╡ | ||
* │ {1,true} │ | ||
* │ {null,null} │ | ||
* │ {2,false} │ | ||
* └─────────────┘ | ||
* See Also | ||
* ---------- | ||
* jsonPathMatch : Extract the first match of json string with provided JSONPath expression. | ||
*/ | ||
jsonExtract(dtype?: DataType, inferSchemaLength?: number): Expr; | ||
/** | ||
* Extract the first match of json string with provided JSONPath expression. | ||
@@ -118,2 +142,4 @@ * Throw errors if encounter invalid json strings. | ||
* @param jsonPath - A valid JSON path query string | ||
* @param dtype - The dtype to cast the extracted value to. If None, the dtype will be inferred from the JSON value. | ||
* @param inferSchemaLength - How many rows to parse to determine the schema. If ``None`` all rows are used. | ||
* @returns Utf8 array. Contain null if original value is null or the `jsonPath` return nothing. | ||
@@ -120,0 +146,0 @@ * @example |
@@ -47,2 +47,5 @@ "use strict"; | ||
}, | ||
jsonExtract(dtype, inferSchemaLength) { | ||
return wrap("strJsonExtract", dtype, inferSchemaLength); | ||
}, | ||
jsonPathMatch(pat) { | ||
@@ -85,8 +88,8 @@ return wrap("strJsonPathMatch", pat); | ||
}, | ||
strptime(dtype, fmt) { | ||
strptime(dtype, format) { | ||
if (dtype.equals(datatypes_1.DataType.Date)) { | ||
return wrap("strParseDate", fmt, false, false); | ||
return wrap("strToDate", format, false, false, false); | ||
} | ||
else if (dtype.equals(datatypes_1.DataType.Datetime("ms"))) { | ||
return wrap("strParseDatetime", fmt, false, false); | ||
return wrap("strToDatetime", format, undefined, undefined, false, false, false); | ||
} | ||
@@ -93,0 +96,0 @@ else { |
@@ -115,14 +115,29 @@ import { Expr } from "./expr"; | ||
* > df.lazy() | ||
* > .filter(pl.col("foo").lt(pl.arange(0, 100))) | ||
* > .filter(pl.col("foo").lt(pl.intRange(0, 100))) | ||
* > .collect() | ||
* ``` | ||
*/ | ||
export declare function arange<T>(opts: { | ||
export declare function intRange<T>(opts: { | ||
low: any; | ||
high: any; | ||
step: number; | ||
eager: boolean; | ||
eager?: boolean; | ||
}): any; | ||
export declare function arange(low: any, high?: any, step?: number, eager?: true): Series; | ||
export declare function arange(low: any, high?: any, step?: number, eager?: false): Expr; | ||
export declare function intRange(low: any, high?: any, step?: number, eager?: true): Series; | ||
export declare function intRange(low: any, high?: any, step?: number, eager?: false): Expr; | ||
/*** | ||
* Generate a range of integers for each row of the input columns. | ||
* @param start - Lower bound of the range (inclusive). | ||
* @param end - Upper bound of the range (exclusive). | ||
* @param step - Step size of the range. | ||
* @param eager - Evaluate immediately and return a ``Series``. If set to ``False`` (default), return an expression instead. | ||
* @return - Column of data type ``List(dtype)``. | ||
* * @example | ||
* ``` | ||
* const df = pl.DataFrame({"a": [1, 2], "b": [3, 4]}) | ||
* const result = df.select(pl.intRanges("a", "b")); | ||
* ``` | ||
*/ | ||
export declare function intRanges(start: any, end: any, step?: number, eager?: false): Expr; | ||
export declare function intRanges(start: any, end: any, step?: number, eager?: true): Series; | ||
/** Alias for `pl.col("*")` */ | ||
@@ -137,3 +152,3 @@ export declare function all(): Expr; | ||
*/ | ||
export declare function argSortBy(exprs: Expr[] | string[], reverse?: boolean | boolean[]): Expr; | ||
export declare function argSortBy(exprs: Expr[] | string[], descending?: boolean | boolean[]): Expr; | ||
/** Alias for mean. @see {@link mean} */ | ||
@@ -140,0 +155,0 @@ export declare function avg(column: string): Expr; |
@@ -6,3 +6,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.element = exports.struct = exports.list = exports.tail = exports.spearmanRankCorr = exports.select = exports.quantile = exports.pearsonCorr = exports.nUnique = exports.median = exports.mean = exports.last = exports.head = exports.groups = exports.format = exports.first = exports.exclude = exports.cov = exports.count = exports.concatString = exports.concatList = exports.avg = exports.argSortBy = exports.all = exports.arange = exports.lit = exports.cols = exports.col = void 0; | ||
exports.element = exports.struct = exports.list = exports.tail = exports.spearmanRankCorr = exports.select = exports.quantile = exports.pearsonCorr = exports.nUnique = exports.median = exports.mean = exports.last = exports.head = exports.groups = exports.format = exports.first = exports.exclude = exports.cov = exports.count = exports.concatString = exports.concatList = exports.avg = exports.argSortBy = exports.all = exports.intRanges = exports.intRange = exports.lit = exports.cols = exports.col = void 0; | ||
const expr_1 = require("./expr"); | ||
@@ -132,5 +132,5 @@ const series_1 = require("../series"); | ||
exports.lit = lit; | ||
function arange(opts, high, step, eager) { | ||
function intRange(opts, high, step = 1, eager) { | ||
if (typeof opts?.low === "number") { | ||
return arange(opts.low, opts.high, opts.step, opts.eager); | ||
return intRange(opts.low, opts.high, opts.step, opts.eager); | ||
} | ||
@@ -143,9 +143,21 @@ else { | ||
return df | ||
.select(arange(low, high, step).alias("arange")) | ||
.getColumn("arange"); | ||
.select(intRange(low, high, step).alias("intRange")) | ||
.getColumn("intRange"); | ||
} | ||
return (0, expr_1._Expr)(polars_internal_1.default.arange(low, high, step)); | ||
return (0, expr_1._Expr)(polars_internal_1.default.intRange(low, high, step, eager)); | ||
} | ||
} | ||
exports.arange = arange; | ||
exports.intRange = intRange; | ||
function intRanges(start, end, step = 1, eager) { | ||
start = (0, expr_1.exprToLitOrExpr)(start, false); | ||
end = (0, expr_1.exprToLitOrExpr)(end, false); | ||
if (eager) { | ||
const df = (0, dataframe_1.DataFrame)({ a: [1] }); | ||
return df | ||
.select(intRanges(start, end, step).alias("intRanges")) | ||
.getColumn("intRanges"); | ||
} | ||
return (0, expr_1._Expr)(polars_internal_1.default.intRanges(start, end, step, eager)); | ||
} | ||
exports.intRanges = intRanges; | ||
/** Alias for `pl.col("*")` */ | ||
@@ -163,8 +175,8 @@ function all() { | ||
*/ | ||
function argSortBy(exprs, reverse = false) { | ||
if (!Array.isArray(reverse)) { | ||
reverse = Array.from({ length: exprs.length }, () => reverse); | ||
function argSortBy(exprs, descending = false) { | ||
if (!Array.isArray(descending)) { | ||
descending = Array.from({ length: exprs.length }, () => descending); | ||
} | ||
const by = (0, utils_1.selectionToExprList)(exprs); | ||
return (0, expr_1._Expr)(polars_internal_1.default.argsortBy(by, reverse)); | ||
return (0, expr_1._Expr)(polars_internal_1.default.argSortBy(by, descending)); | ||
} | ||
@@ -171,0 +183,0 @@ exports.argSortBy = argSortBy; |
import { Expr } from "./expr"; | ||
export interface When { | ||
/** Values to return in case of the predicate being `true`.*/ | ||
then(expr: Expr): WhenThen; | ||
then(expr: Expr): Then; | ||
} | ||
export interface WhenThen { | ||
export interface Then { | ||
/** Start another when, then, otherwise layer. */ | ||
when(predicate: Expr): WhenThenThen; | ||
when(predicate: Expr): ChainedWhen; | ||
/** Values to return in case of the predicate being `false`. */ | ||
otherwise(expr: Expr): Expr; | ||
} | ||
export interface WhenThenThen { | ||
export interface ChainedWhen { | ||
/** Values to return in case of the predicate being `true`. */ | ||
then(expr: Expr): ChainedThen; | ||
} | ||
export interface ChainedThen { | ||
/** Start another when, then, otherwise layer. */ | ||
when(predicate: Expr): WhenThenThen; | ||
when(predicate: Expr): ChainedWhen; | ||
/** Values to return in case of the predicate being `true`. */ | ||
then(expr: Expr): WhenThenThen; | ||
then(expr: Expr): ChainedThen; | ||
/** Values to return in case of the predicate being `false`. */ | ||
@@ -18,0 +22,0 @@ otherwise(expr: Expr): Expr; |
@@ -9,15 +9,20 @@ "use strict"; | ||
const polars_internal_1 = __importDefault(require("../internals/polars_internal")); | ||
function WhenThenThen(_whenthenthen) { | ||
function ChainedWhen(_chainedwhen) { | ||
return { | ||
when: ({ _expr }) => WhenThenThen(_whenthenthen.when(_expr)), | ||
then: ({ _expr }) => WhenThenThen(_whenthenthen.then(_expr)), | ||
otherwise: ({ _expr }) => expr_1.Expr(_whenthenthen.otherwise(_expr)), | ||
then: ({ _expr }) => ChainedThen(_chainedwhen.then(_expr)), | ||
}; | ||
} | ||
function WhenThen(_whenthen) { | ||
function ChainedThen(_chainedthen) { | ||
return { | ||
when: ({ _expr }) => WhenThenThen(_whenthen.when(_expr)), | ||
otherwise: ({ _expr }) => expr_1.Expr(_whenthen.otherwise(_expr)), | ||
when: ({ _expr }) => ChainedWhen(_chainedthen.when(_expr)), | ||
then: ({ _expr }) => ChainedThen(_chainedthen.then(_expr)), | ||
otherwise: ({ _expr }) => expr_1.Expr(_chainedthen.otherwise(_expr)), | ||
}; | ||
} | ||
function Then(_then) { | ||
return { | ||
when: ({ _expr }) => ChainedWhen(_then.when(_expr)), | ||
otherwise: ({ _expr }) => expr_1.Expr(_then.otherwise(_expr)), | ||
}; | ||
} | ||
/** | ||
@@ -29,3 +34,3 @@ * Utility function. | ||
return { | ||
then: ({ _expr }) => WhenThen(_when.then(_expr)), | ||
then: ({ _expr }) => Then(_when.then(_expr)), | ||
}; | ||
@@ -32,0 +37,0 @@ } |
@@ -107,7 +107,7 @@ "use strict"; | ||
}, | ||
argSort(reverse = false, nullsLast = true) { | ||
argSort(reverse = false, nullsLast = true, maintain_order = false) { | ||
if (typeof reverse === "boolean") { | ||
return _Series(_s.argsort(reverse, nullsLast, false)); | ||
return _Series(_s.argsort(reverse, nullsLast, maintain_order, false)); | ||
} | ||
return _Series(_s.argsort(reverse.reverse, reverse.nullsLast ?? nullsLast)); | ||
return _Series(_s.argsort(reverse.reverse, reverse.nullsLast ?? nullsLast, reverse.maintain_order ?? maintain_order)); | ||
}, | ||
@@ -114,0 +114,0 @@ argTrue() { |
@@ -96,2 +96,17 @@ import { DataType } from "../datatypes"; | ||
extract(pattern: string | RegExp, groupIndex: number): Series; | ||
/*** | ||
* Parse string values as JSON. | ||
* @returns Utf8 array. Contain null if original value is null or the `jsonPath` return nothing. | ||
* @example | ||
* s = pl.Series("json", ['{"a":1, "b": true}', null, '{"a":2, "b": false}']); | ||
* s.str.json_extract().as("json"); | ||
* shape: (3,) | ||
* Series: 'json' [struct[2]] | ||
* [ | ||
* {1,true} | ||
* {null,null} | ||
* {2,false} | ||
* ] | ||
*/ | ||
jsonExtract(dtype?: DataType, inferSchemaLength?: number): Series; | ||
/** | ||
@@ -103,2 +118,4 @@ * Extract the first match of json string with provided JSONPath expression. | ||
* @param jsonPath - A valid JSON path query string | ||
* @param dtype - The dtype to cast the extracted value to. If None, the dtype will be inferred from the JSON value. | ||
* @param inferSchemaLength - How many rows to parse to determine the schema. If ``None`` all rows are used. | ||
* @returns Utf8 array. Contain null if original value is null or the `jsonPath` return nothing. | ||
@@ -105,0 +122,0 @@ * @example |
@@ -51,2 +51,5 @@ "use strict"; | ||
}, | ||
jsonExtract(dtype, inferSchemaLength) { | ||
return wrap("strJsonExtract", dtype, inferSchemaLength); | ||
}, | ||
jsonPathMatch(pat) { | ||
@@ -53,0 +56,0 @@ return wrap("strJsonPathMatch", pat); |
/// <reference types="node" /> | ||
import { ColumnsOrExpr, StartBy } from "./utils"; | ||
import { Expr } from "./lazy/expr"; | ||
import { InterpolationMethod, RollingOptions, RollingQuantileOptions, RollingSkewOptions } from "./types"; | ||
import { InterpolationMethod, RollingOptions, RollingQuantileOptions, RollingSkewOptions, ClosedWindow } from "./types"; | ||
import { DataType } from "./datatypes"; | ||
@@ -354,3 +354,3 @@ /** | ||
rollingQuantile(options: RollingQuantileOptions): T; | ||
rollingQuantile(quantile: number, interpolation?: InterpolationMethod, windowSize?: number, weights?: Array<number>, minPeriods?: Array<number>, center?: boolean): T; | ||
rollingQuantile(quantile: number, interpolation?: InterpolationMethod, windowSize?: number, weights?: Array<number>, minPeriods?: Array<number>, center?: boolean, by?: String, closed?: ClosedWindow): T; | ||
/** | ||
@@ -1004,2 +1004,8 @@ * Compute a rolling skew | ||
@param closed Defines if the window interval is closed or not. | ||
@param check_sorted | ||
When the ``by`` argument is given, polars can not check sortedness | ||
by the metadata and has to do a full scan on the index column to | ||
verify data is sorted. This is expensive. If you are sure the | ||
data within the by groups is sorted, you can set this to ``False``. | ||
Doing so incorrectly will lead to incorrect output | ||
@@ -1055,3 +1061,3 @@ Any of `{"left", "right", "both" "none"}` | ||
groupByRolling(opts: { | ||
indexColumn: string; | ||
indexColumn: ColumnsOrExpr; | ||
by?: ColumnsOrExpr; | ||
@@ -1061,2 +1067,3 @@ period: string; | ||
closed?: "left" | "right" | "both" | "none"; | ||
check_sorted?: boolean; | ||
}): T; | ||
@@ -1112,2 +1119,8 @@ /** | ||
Any of {"left", "right", "both" "none"} | ||
@param check_sorted | ||
When the ``by`` argument is given, polars can not check sortedness | ||
by the metadata and has to do a full scan on the index column to | ||
verify data is sorted. This is expensive. If you are sure the | ||
data within the by groups is sorted, you can set this to ``False``. | ||
Doing so incorrectly will lead to incorrect output | ||
@param by Also group by this column/these columns | ||
@@ -1125,3 +1138,4 @@ */ | ||
start_by: StartBy; | ||
check_sorted?: boolean; | ||
}): T; | ||
} |
@@ -169,1 +169,5 @@ /** | ||
} | ||
/** | ||
* ClosedWindow types | ||
*/ | ||
export type ClosedWindow = "None" | "Both" | "Left" | "Right"; |
{ | ||
"name": "nodejs-polars", | ||
"version": "0.8.0", | ||
"version": "0.8.1", | ||
"repository": "https://github.com/pola-rs/nodejs-polars.git", | ||
@@ -58,16 +58,16 @@ "license": "SEE LICENSE IN LICENSE", | ||
"devDependencies": { | ||
"@napi-rs/cli": "^2.16.1", | ||
"@napi-rs/cli": "^2.16.2", | ||
"@types/chance": "^1.1.3", | ||
"@types/jest": "^29.5.2", | ||
"@types/node": "^20.2.5", | ||
"@types/jest": "^29.5.3", | ||
"@types/node": "^20.4.2", | ||
"chance": "^1.1.11", | ||
"jest": "^29.5.0", | ||
"jest": "^29.6.1", | ||
"rome": "^12.1.3", | ||
"source-map-support": "^0.5.21", | ||
"ts-jest": "^29.1.0", | ||
"ts-jest": "^29.1.1", | ||
"ts-node": "^10.9.1", | ||
"typedoc": "^0.24.7", | ||
"typescript": "5.1.3" | ||
"typedoc": "^0.24.8", | ||
"typescript": "5.1.6" | ||
}, | ||
"packageManager": "yarn@3.3.1", | ||
"packageManager": "yarn@3.6.1", | ||
"workspaces": [ | ||
@@ -77,12 +77,12 @@ "benches" | ||
"optionalDependencies": { | ||
"nodejs-polars-win32-x64-msvc": "0.8.0", | ||
"nodejs-polars-darwin-x64": "0.8.0", | ||
"nodejs-polars-linux-x64-gnu": "0.8.0", | ||
"nodejs-polars-darwin-arm64": "0.8.0", | ||
"nodejs-polars-linux-arm64-gnu": "0.8.0", | ||
"nodejs-polars-linux-arm64-musl": "0.8.0", | ||
"nodejs-polars-android-arm64": "0.8.0", | ||
"nodejs-polars-win32-ia32-msvc": "0.8.0", | ||
"nodejs-polars-linux-x64-musl": "0.8.0" | ||
"nodejs-polars-win32-x64-msvc": "0.8.1", | ||
"nodejs-polars-darwin-x64": "0.8.1", | ||
"nodejs-polars-linux-x64-gnu": "0.8.1", | ||
"nodejs-polars-darwin-arm64": "0.8.1", | ||
"nodejs-polars-linux-arm64-gnu": "0.8.1", | ||
"nodejs-polars-linux-arm64-musl": "0.8.1", | ||
"nodejs-polars-android-arm64": "0.8.1", | ||
"nodejs-polars-win32-ia32-msvc": "0.8.1", | ||
"nodejs-polars-linux-x64-musl": "0.8.1" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
439826
12068