Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

nodejs-polars

Package Overview
Dependencies
Maintainers
2
Versions
45
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nodejs-polars - npm Package Compare versions

Comparing version 0.4.1 to 0.5.1

bin/lazy/expr/struct.d.ts

6

bin/cfg.js
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Config = void 0;
const native_polars_1 = __importDefault(require("./native-polars"));
exports.Config = {

@@ -26,7 +30,9 @@ setUtf8Tables() {

setGlobalStringCache() {
native_polars_1.default.toggleStringCache(true);
return this;
},
unsetGlobalStringCache() {
native_polars_1.default.toggleStringCache(false);
return this;
}
};

142

bin/dataframe.d.ts

@@ -7,3 +7,3 @@ /// <reference types="node" />

import { Writable } from "stream";
import { DataType, JoinBaseOptions, JsDataFrame } from "./datatypes";
import { DataType, JoinBaseOptions } from "./datatypes";
import { ColumnSelection, FillNullStrategy, ColumnsOrExpr, ValueOrArray, ExprOrString } from "./utils";

@@ -69,4 +69,4 @@ import { Arithmetic, Sample } from "./shared_traits";

*/
writeCSV(): string;
writeCSV(options: WriteCsvOptions): string;
writeCSV(): Buffer;
writeCSV(options: WriteCsvOptions): Buffer;
writeCSV(dest: string | Writable, options?: WriteCsvOptions): void;

@@ -77,4 +77,3 @@ /**

* @param options
* @param options.orient - col|row|dataframe
* - col will write to a column oriented object
* @param options.format - json | lines
* @example

@@ -87,19 +86,7 @@ * ```

*
* // defaults to 'dataframe' orientation
* >>> df.writeJSON()
* `{"columns":[ {"name":"foo","datatype":"Float64","values":[1,2,3]}, {"name":"bar","datatype":"Utf8","values":["a","b","c"]}]}`
*
* // this will produce the same results as 'df.writeJSON()'
* >>> JSON.stringify(df)
*
* // row oriented
* >>> df.writeJSON({orient:"row"})
* >>> df.writeJSON({format:"json"})
* `[ {"foo":1.0,"bar":"a"}, {"foo":2.0,"bar":"b"}, {"foo":3.0,"bar":"c"}]`
*
* // column oriented
* >>> df.writeJSON({orient: "col"})
* `{"foo":[1,2,3],"bar":["a","b","c"]}`
*
* // multiline (will always be row oriented)
* >>> df.writeJSON({multiline: true})
* >>> df.writeJSON({format:"lines"})
* `{"foo":1.0,"bar":"a"}

@@ -110,7 +97,11 @@ * {"foo":2.0,"bar":"b"}

* // writing to a file
* >>> df.writeJSON("/path/to/file.json", {multiline:true})
* >>> df.writeJSON("/path/to/file.json", {format:'lines'})
* ```
*/
writeJSON(options?: WriteJsonOptions): string;
writeJSON(destination: string | Writable, options?: WriteJsonOptions): void;
writeJSON(options?: {
format: "lines" | "json";
}): Buffer;
writeJSON(destination: string | Writable, options?: {
format: "lines" | "json";
}): void;
/**

@@ -217,3 +208,3 @@ * Write to Arrow IPC binary stream, or a feather file.

/** @ignore */
_df: JsDataFrame;
_df: any;
dtypes: DataType[];

@@ -536,3 +527,3 @@ height: number;

*/
fold<T, U, V>(operation: (s1: Series<T>, s2: Series<U>) => Series<V>): Series<V>;
fold(operation: (s1: Series, s2: Series) => Series): Series;
/**

@@ -567,7 +558,7 @@ * Check if DataFrame is equal to other.

*/
getColumn(name: string): Series<any>;
getColumn(name: string): Series;
/**
* Get the DataFrame as an Array of Series.
*/
getColumns(): Array<Series<any>>;
getColumns(): Array<Series>;
/**

@@ -586,3 +577,3 @@ * Start a groupby operation.

*/
hashRows(k0?: number, k1?: number, k2?: number, k3?: number): Series<bigint>;
hashRows(k0?: number, k1?: number, k2?: number, k3?: number): Series;
hashRows(options: {

@@ -593,3 +584,3 @@ k0?: number;

k3?: number;
}): Series<bigint>;
}): Series;
/**

@@ -649,4 +640,4 @@ * Get first N rows as DataFrame.

*/
hstack(columns: Array<Series<any>> | DataFrame): DataFrame;
hstack(columns: Array<Series<any>> | DataFrame, inPlace?: boolean): void;
hstack(columns: Array<Series> | DataFrame): DataFrame;
hstack(columns: Array<Series> | DataFrame, inPlace?: boolean): void;
/**

@@ -657,3 +648,3 @@ * Insert a Series at a certain column index. This operation is in place.

*/
insertAtIdx(index: number, series: Series<any>): void;
insertAtIdx(index: number, series: Series): void;
/**

@@ -666,3 +657,3 @@ * Interpolate intermediate values. The interpolation method is linear.

*/
isDuplicated(): Series<boolean>;
isDuplicated(): Series;
/**

@@ -675,3 +666,3 @@ * Check if the dataframe is empty

*/
isUnique(): Series<boolean>;
isUnique(): Series;
/**

@@ -724,3 +715,3 @@ * __SQL like joins.__

limit(length?: number): DataFrame;
map<T>(func: (...args: any[]) => T): T[];
map(func: (...args: any[]) => any): any[];
/**

@@ -750,3 +741,3 @@ * Aggregate the columns of this DataFrame to their maximum value.

max(axis: 0): DataFrame;
max(axis: 1): Series<any>;
max(axis: 1): Series;
/**

@@ -761,4 +752,4 @@ * Aggregate the columns of this DataFrame to their mean value.

mean(axis: 0): DataFrame;
mean(axis: 1): Series<any>;
mean(axis: 1, nullStrategy?: "ignore" | "propagate"): Series<any>;
mean(axis: 1): Series;
mean(axis: 1, nullStrategy?: "ignore" | "propagate"): Series;
/**

@@ -818,3 +809,3 @@ * Aggregate the columns of this DataFrame to their median value.

min(axis: 0): DataFrame;
min(axis: 1): Series<any>;
min(axis: 1): Series;
/**

@@ -846,2 +837,4 @@ * Get number of chunks used by the ChunkedArrays of this DataFrame.

nullCount(): DataFrame;
partitionBy(cols: string | string[], stable?: boolean): DataFrame[];
partitionBy<T>(cols: string | string[], stable: boolean, mapFn: (df: DataFrame) => T): T[];
/**

@@ -929,3 +922,3 @@ * Aggregate the columns of this DataFrame to their quantile value.

*/
replaceAtIdx(index: number, newColumn: Series<any>): void;
replaceAtIdx(index: number, newColumn: Series): void;
/**

@@ -950,3 +943,3 @@ * Get a row as Array

rows(): Array<Array<any>>;
schema(): Record<string, string>;
get schema(): Record<string, DataType>;
/**

@@ -1138,4 +1131,4 @@ * Select columns from this DataFrame.

sum(axis: 0): DataFrame;
sum(axis: 1): Series<any>;
sum(axis: 1, nullStrategy?: "ignore" | "propagate"): Series<any>;
sum(axis: 1): Series;
sum(axis: 1, nullStrategy?: "ignore" | "propagate"): Series;
/**

@@ -1199,33 +1192,6 @@ *

/**
* Converts dataframe object into javascript object
* Same logic applies for `toJSON` except this will use js values instead of a json string
* @param options
* @param options.orient - col|row|dataframe
*
* Converts dataframe object into row oriented javascript objects
* @example
* ```
* >>> const df = pl.DataFrame({
* >>> foo: [1,2,3],
* >>> bar: ['a','b','c']
* >>> })
*
* // defaults to 'dataframe' orientation
* >>> df.toObject()
* {
* "columns":[
* {
* "name":"foo",
* "datatype":"Float64",
* "values":[1,2,3]
* },
* {
* "name":"bar",
* "datatype":"Utf8",
* "values":["a","b","c"]
* }
* ]
* }
*
* // row oriented
* >>> df.toObject({orient:"row"})
* >>> df.toRecords()
* [

@@ -1236,15 +1202,5 @@ * {"foo":1.0,"bar":"a"},

* ]
*
* // column oriented
* >>> df.toObject({orient: "col"})
* {
* "foo":[1,2,3],
* "bar":["a","b","c"]
* }
* ```
*/
toObject(): object;
toObject(options: {
orient: "row" | "col" | "dataframe";
}): object;
toRecords(): Record<string, any>[];
/**

@@ -1258,2 +1214,14 @@ * @deprecated

toJSON(destination: string | Writable, options?: WriteJsonOptions): void;
/**
* Converts dataframe object into column oriented javascript objects
* @example
* ```
* >>> df.toObject()
* {
* "foo": [1,2,3],
* "bar": ["a", "b", "c"]
* }
* ```
*/
toObject(): Record<string, any[]>;
/** @deprecated *since 0.4.0* use {@link writeIPC} */

@@ -1263,3 +1231,3 @@ toIPC(destination?: any, options?: any): any;

toParquet(destination?: any, options?: any): any;
toSeries(index: number): Series<any>;
toSeries(index?: number): Series;
toString(): string;

@@ -1414,5 +1382,5 @@ /**

*/
withColumn(column: Series<any> | Expr): DataFrame;
withColumn(column: Series<any> | Expr): DataFrame;
withColumns(column: Series<any> | Expr, ...columns: Expr[] | Series<any>[]): DataFrame;
withColumn(column: Series | Expr): DataFrame;
withColumn(column: Series | Expr): DataFrame;
withColumns(column: Series | Expr, ...columns: Expr[] | Series[]): DataFrame;
/**

@@ -1439,3 +1407,3 @@ * Return a new DataFrame with the column renamed.

*/
export declare const dfWrapper: (_df: JsDataFrame) => DataFrame;
export declare const _DataFrame: (_df: any) => DataFrame;
export interface DataFrameConstructor {

@@ -1442,0 +1410,0 @@ (): DataFrame;

@@ -6,3 +6,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.DataFrame = exports.dfWrapper = void 0;
exports.DataFrame = exports._DataFrame = void 0;
const polars_internal_1 = __importDefault(require("./internals/polars_internal"));

@@ -16,3 +16,2 @@ const construction_1 = require("./internals/construction");

const stream_1 = require("stream");
const types_1 = require("util/types");
const datatypes_1 = require("./datatypes");

@@ -36,53 +35,9 @@ const utils_1 = require("./utils");

*/
const dfWrapper = (_df) => {
const unwrap = (method, args, df = _df) => {
return polars_internal_1.default.df[method]({ _df: df, ...args });
const _DataFrame = (_df) => {
const unwrap = (method, ...args) => {
return _df[method](...args);
};
const wrap = (method, args, df = _df) => {
return (0, exports.dfWrapper)(unwrap(method, args, df));
const wrap = (method, ...args) => {
return (0, exports._DataFrame)(unwrap(method, ...args));
};
const noArgWrap = (method) => () => wrap(method);
const noArgUnwrap = (method) => () => unwrap(method);
const writeToStreamOrString = (dest, format, options) => {
if (dest instanceof stream_1.Writable) {
unwrap(`write_${format}_stream`, { writeStream: dest, ...options });
dest.end("");
}
else if (typeof dest === "string") {
unwrap(`write_${format}_path`, { path: dest, ...options });
}
else {
let body = "";
const writeStream = new stream_1.Stream.Writable({
write(chunk, _encoding, callback) {
body += chunk;
callback(null);
}
});
unwrap(`write_${format}_stream`, { writeStream, ...options, ...dest });
writeStream.end("");
return body;
}
};
const writeToBufferOrStream = (dest, format, options) => {
if (dest instanceof stream_1.Writable) {
unwrap(`write_${format}_stream`, { writeStream: dest, ...options });
dest.end("");
}
else if (typeof dest === "string") {
return unwrap(`write_${format}_path`, { path: dest, ...options });
}
else {
let buffers = [];
const writeStream = new stream_1.Stream.Writable({
write(chunk, _encoding, callback) {
buffers.push(chunk);
callback(null);
}
});
unwrap(`write_${format}_stream`, { writeStream, ...options, ...dest });
writeStream.end("");
return Buffer.concat(buffers);
}
};
const df = {

@@ -92,3 +47,3 @@ /** @ignore */

[inspect]() {
return unwrap("as_str").toString();
return _df.toString();
},

@@ -104,21 +59,32 @@ *[Symbol.iterator]() {

},
get [Symbol.toStringTag]() {
return "DataFrame";
},
get dtypes() {
return unwrap("dtypes");
return _df.dtypes();
},
get height() {
return unwrap("height");
return _df.height;
},
get width() {
return unwrap("width");
return _df.width;
},
get shape() {
return { height: this.height, width: this.width };
return _df.shape;
},
get columns() {
return unwrap("columns");
return _df.columns;
},
set columns(names) {
unwrap("set_column_names", { names });
_df.columns = names;
},
clone: noArgWrap("clone"),
get schema() {
return this.getColumns().reduce((acc, curr) => {
acc[curr.name] = curr.dtype;
return acc;
}, {});
},
clone() {
return wrap("clone");
},
describe() {

@@ -145,9 +111,12 @@ const describeCast = (df) => {

},
inner() {
return _df;
},
drop(...names) {
if (!Array.isArray(names[0]) && names.length === 1) {
return wrap("drop", { name: names[0] });
return wrap("drop", names[0]);
}
const df = this.clone();
names.flat(2).forEach((name) => {
unwrap("drop_in_place", { name }, df._df);
df.inner().dropInPlace(name);
});

@@ -158,6 +127,6 @@ return df;

if (subset.length) {
return wrap("drop_nulls", { subset: subset.flat(2) });
return wrap("dropNulls", subset.flat(2));
}
else {
return wrap("drop_nulls");
return wrap("dropNulls");
}

@@ -174,3 +143,3 @@ },

if (typeof opts === "boolean") {
return wrap("unique", { ...defaultOptions, maintainOrder: opts, subset, keep });
return wrap("unique", opts, subset, keep);
}

@@ -180,6 +149,7 @@ if (opts.subset) {

}
return wrap("unique", { ...defaultOptions, ...opts });
const o = { ...defaultOptions, ...opts };
return wrap("unique", o.maintainOrder, o.subset, o.keep);
},
explode(...columns) {
return (0, exports.dfWrapper)(_df)
return (0, exports._DataFrame)(_df)
.lazy()

@@ -190,3 +160,3 @@ .explode(columns)

extend(other) {
return wrap("extend", { other: other._df });
return wrap("extend", other.inner());
},

@@ -199,4 +169,8 @@ filter(predicate) {

},
fillNull: (strategy) => wrap("fill_null", { strategy }),
findIdxByName: (name) => unwrap("find_idx_by_name", { name }),
fillNull(strategy) {
return wrap("fillNull", strategy);
},
findIdxByName(name) {
return unwrap("findIdxByName", name);
},
fold(fn) {

@@ -209,35 +183,40 @@ if (this.width === 1) {

frameEqual(other, nullEqual = true) {
return unwrap("frame_equal", { other: other._df, nullEqual });
return unwrap("frameEqual", other._df, nullEqual);
},
getColumn(name) {
return (0, series_1.seriesWrapper)(unwrap("column", { name }));
return (0, series_1._Series)(_df.column(name));
},
getColumns() {
return unwrap("get_columns").map(s => (0, series_1.seriesWrapper)(s));
return _df.getColumns().map(series_1._Series);
},
groupBy: (...by) => (0, groupby_1.GroupBy)(_df, (0, utils_1.columnOrColumnsStrict)(by)),
hashRows(obj = 0, k1 = 1, k2 = 2, k3 = 3) {
groupBy(...by) {
return (0, groupby_1.GroupBy)(_df, (0, utils_1.columnOrColumnsStrict)(by));
},
hashRows(obj = 0n, k1 = 1n, k2 = 2n, k3 = 3n) {
if (typeof obj === "number" || typeof obj === "bigint") {
return (0, series_1.seriesWrapper)(unwrap("hash_rows", { k0: obj, k1: k1, k2: k2, k3: k3 }));
return (0, series_1._Series)(_df.hashRows(BigInt(obj), BigInt(k1), BigInt(k2), BigInt(k3)));
}
return (0, series_1.seriesWrapper)(unwrap("hash_rows", { k0: 0, k1, k2, k3, ...obj }));
const o = { k0: obj, k1: k1, k2: k2, k3: k3, ...obj };
return (0, series_1._Series)(_df.hashRows(BigInt(o.k0), BigInt(o.k1), BigInt(o.k2), BigInt(o.k3)));
},
head: (length = 5) => wrap("head", { length }),
hstack(columns) {
head(length = 5) {
return wrap("head", length);
},
hstack(columns, inPlace = false) {
if (!Array.isArray(columns)) {
columns = columns.getColumns();
}
return wrap("hstack", {
columns: columns.map(col => col._series),
in_place: false
});
const method = inPlace ? "hstackMut" : "hstack";
return wrap(method, columns.map(col => col.inner()));
},
insertAtIdx: (index, s) => unwrap("insert_at_idx", { index, new_col: s._series }),
insertAtIdx(idx, series) {
_df.insertAtIdx(idx, series.inner());
},
interpolate() {
return this.select((0, functions_2.col)("*").interpolate());
},
isDuplicated: () => (0, series_1.seriesWrapper)(unwrap("is_duplicated")),
isEmpty: () => unwrap("height") === 0,
isUnique: () => (0, series_1.seriesWrapper)(unwrap("is_unique")),
join(df, options) {
isDuplicated: () => (0, series_1._Series)(_df.isDuplicated()),
isEmpty: () => _df.height === 0,
isUnique: () => (0, series_1._Series)(_df.isUnique()),
join(other, options) {
options = { how: "inner", suffix: "right", ...options };

@@ -256,16 +235,9 @@ const on = (0, utils_1.columnOrColumns)(options.on);

}
return wrap("join", {
other: df._df,
on,
how,
left_on: leftOn,
right_on: rightOn,
suffix,
});
return wrap("join", other._df, leftOn, rightOn, how, suffix);
},
lazy: () => (0, dataframe_1.LazyDataFrame)(unwrap("lazy")),
limit: (length = 5) => wrap("head", { length }),
lazy: () => (0, dataframe_1._LazyDataFrame)(_df.lazy()),
limit: (length = 5) => wrap("head", length),
max(axis = 0) {
if (axis === 1) {
return (0, series_1.seriesWrapper)(unwrap("hmax"));
return (0, series_1._Series)(_df.hmax());
}

@@ -278,16 +250,15 @@ else {

if (axis === 1) {
return (0, series_1.seriesWrapper)(unwrap("hmean", { nullStrategy }));
return (0, series_1._Series)(_df.hmean(nullStrategy));
}
return wrap("mean");
},
median: noArgWrap("median"),
median() {
return wrap("median");
},
melt(ids, values) {
return wrap("melt", {
idVars: (0, utils_1.columnOrColumns)(ids),
valueVars: (0, utils_1.columnOrColumns)(values)
});
return wrap("melt", (0, utils_1.columnOrColumns)(ids), (0, utils_1.columnOrColumns)(values));
},
min(axis = 0) {
if (axis === 1) {
return (0, series_1.seriesWrapper)(unwrap("hmin"));
return (0, series_1._Series)(_df.hmin());
}

@@ -298,10 +269,20 @@ else {

},
nChunks: noArgUnwrap("n_chunks"),
nullCount: noArgWrap("null_count"),
quantile: (quantile) => wrap("quantile", { quantile }),
rechunk: noArgWrap("rechunk"),
nChunks() {
return _df.nChunks();
},
nullCount() {
return wrap("nullCount");
},
partitionBy(by, strict = false, mapFn = df => df) {
by = Array.isArray(by) ? by : [by];
return _df.partitionBy(by, strict).map(d => mapFn((0, exports._DataFrame)(d)));
},
quantile(quantile, interpolation = "nearest") {
return wrap("quantile", quantile, interpolation);
},
rechunk() { return wrap("rechunk"); },
rename(mapping) {
const df = this.clone();
Object.entries(mapping).forEach(([column, new_col]) => {
unwrap("rename", { column, new_col }, df._df);
df.inner().rename(column, new_col);
});

@@ -311,16 +292,14 @@ return df;

replaceAtIdx(index, newColumn) {
unwrap("replace_at_idx", {
index,
newColumn: newColumn._series
});
_df.replaceAtIdx(index, newColumn.inner());
return this;
},
rows: noArgUnwrap("to_rows"),
rows(callback) {
if (callback) {
return _df.toRowsCb(callback);
}
return _df.toRows();
},
sample(opts, frac, withReplacement = false, seed) {
if (arguments.length === 0) {
return wrap("sample_n", {
n: 1,
withReplacement,
seed
});
return wrap("sampleN", 1, withReplacement, seed);
}

@@ -331,14 +310,6 @@ if (opts?.n !== undefined || opts?.frac !== undefined) {

if (typeof opts === "number") {
return wrap("sample_n", {
n: opts,
withReplacement,
seed
});
return wrap("sampleN", opts, withReplacement, seed);
}
if (typeof frac === "number") {
return wrap("sample_frac", {
frac,
withReplacement,
seed
});
return wrap("sampleFrac", frac, withReplacement, seed);
}

@@ -349,7 +320,6 @@ else {

},
schema: noArgUnwrap("schema"),
select(...selection) {
const hasExpr = selection.flat().some(s => expr_1.Expr.isExpr(s));
if (hasExpr) {
return (0, exports.dfWrapper)(_df)
return (0, exports._DataFrame)(_df)
.lazy()

@@ -360,8 +330,8 @@ .select(selection)

else {
return wrap("select", { selection: (0, utils_1.columnOrColumnsStrict)(selection) });
return wrap("select", (0, utils_1.columnOrColumnsStrict)(selection));
}
},
shift: (opt) => wrap("shift", { periods: opt?.periods ?? opt }),
shift: (opt) => wrap("shift", opt?.periods ?? opt),
shiftAndFill(periods, fillValue) {
return (0, exports.dfWrapper)(_df)
return (0, exports._DataFrame)(_df)
.lazy()

@@ -373,7 +343,7 @@ .shiftAndFill(periods, fillValue)

if (inPlace) {
unwrap("shrink_to_fit");
_df.shrinkToFit();
}
else {
const d = this.clone();
unwrap("shrink_to_fit", {}, d._df);
d.inner().shrinkToFit();
return d;

@@ -384,5 +354,5 @@ }

if (typeof opts === "number") {
return wrap("slice", { offset: opts, length });
return wrap("slice", opts, length);
}
return wrap("slice", opts);
return wrap("slice", opts.offset, opts.length);
},

@@ -394,18 +364,20 @@ sort(arg, reverse = false) {

if (Array.isArray(arg) || expr_1.Expr.isExpr(arg)) {
return (0, exports.dfWrapper)(_df).lazy()
return (0, exports._DataFrame)(_df).lazy()
.sort(arg, reverse)
.collectSync({ noOptimization: true, stringCache: false });
}
return wrap("sort", { by: [arg].flat(), reverse });
return wrap("sort", arg, reverse, true);
},
std: noArgWrap("std"),
std() {
return wrap("std");
},
sum(axis = 0, nullStrategy = "ignore") {
if (axis === 1) {
return (0, series_1.seriesWrapper)(unwrap("hsum", { nullStrategy }));
return (0, series_1._Series)(_df.hsum(nullStrategy));
}
return wrap("sum");
},
tail: (length = 5) => wrap("tail", { length }),
tail: (length = 5) => wrap("tail", length),
toBinary() {
return unwrap("to_bincode");
return _df.toBincode();
},

@@ -415,75 +387,43 @@ toCSV(...args) {

},
writeCSV(dest, options) {
options = { hasHeader: true, sep: ",", ...options };
// writeCSV(options)
if (dest?.hasHeader !== undefined || dest?.sep !== undefined) {
return writeToStreamOrString(null, "csv", { ...options, ...dest });
writeCSV(dest, options = {}) {
if (dest instanceof stream_1.Writable || typeof dest === "string") {
return _df.writeCsv(dest, options);
}
else {
// writeCSV()
// writeCSV("path/to/some/file", options)
// writeCSV(writeStream, options)
return writeToStreamOrString(dest, "csv", options);
}
let buffers = [];
const writeStream = new stream_1.Stream.Writable({
write(chunk, _encoding, callback) {
buffers.push(chunk);
callback(null);
}
});
_df.writeCsv(writeStream, dest ?? options);
writeStream.end("");
return Buffer.concat(buffers);
},
toObject(options) {
if (options?.orient === "row") {
return unwrap("to_row_objects");
}
if (options?.orient === "col") {
return this.getColumns().reduce((acc, curr) => ({
...acc,
[curr.name]: curr.toArray()
}), {});
}
return unwrap("to_js");
toRecords() {
return _df.toObjects();
},
toJSON(arg0, options) {
// JSON.stringify(df)
// passes `""` by default then stringifies the JS output
if (arg0 === "") {
return unwrap("to_js");
}
// df.toJSON();
// same thing as to_js except skips serializing to JS & returns a json buffer
if (arg0 === undefined) {
return unwrap("to_json").toString();
}
// toJSON(options)
if (arg0?.orient === "row" || arg0?.multiline) {
return writeToStreamOrString(null, "json", arg0);
// toJSON({orient:"col"})
}
else if (arg0?.orient === "col") {
// TODO!
// do this on the rust side for better performance
return JSON.stringify(this.toObject({ orient: "col" }));
}
else {
// toJSON("path/to/some/file", options)
// toJSON(writeStream, options)
return writeToStreamOrString(arg0, "json", options);
}
return _df.toJs();
},
writeJSON(dest, options) {
// df.writeJSON();
// same thing as to_js except skips serializing to JS & returns a json buffer
if (dest === undefined) {
return unwrap("to_json").toString();
toObject() {
return this.getColumns().reduce((acc, curr) => {
acc[curr.name] = curr.toArray();
return acc;
}, {});
},
writeJSON(dest, options = { format: "lines" }) {
if (dest instanceof stream_1.Writable || typeof dest === "string") {
return _df.writeJson(dest, options);
}
// writeJSON(options)
if (dest?.orient === "row" || dest?.multiline) {
return writeToStreamOrString(null, "json", dest);
// writeJSON({orient:"col"})
}
else if (dest?.orient === "col") {
// TODO!
// do this on the rust side for better performance
return JSON.stringify(this.toObject({ orient: "col" }));
}
else {
// writeJSON("path/to/some/file", options)
// writeJSON(writeStream, options)
return writeToStreamOrString(dest, "json", options);
}
let buffers = [];
const writeStream = new stream_1.Stream.Writable({
write(chunk, _encoding, callback) {
buffers.push(chunk);
callback(null);
}
});
_df.writeJson(writeStream, { ...options, ...dest });
writeStream.end("");
return Buffer.concat(buffers);
},

@@ -494,16 +434,30 @@ toParquet(dest, options) {

writeParquet(dest, options = { compression: "uncompressed" }) {
if (dest?.compression !== undefined) {
return writeToBufferOrStream(null, "parquet", dest);
if (dest instanceof stream_1.Writable || typeof dest === "string") {
return _df.writeParquet(dest, options.compression);
}
else {
return writeToBufferOrStream(dest, "parquet", options);
}
let buffers = [];
const writeStream = new stream_1.Stream.Writable({
write(chunk, _encoding, callback) {
buffers.push(chunk);
callback(null);
}
});
_df.writeParquet(writeStream, dest?.compression ?? options?.compression);
writeStream.end("");
return Buffer.concat(buffers);
},
writeAvro(dest, options = { compression: "uncompressed" }) {
if (dest?.compression !== undefined) {
return writeToBufferOrStream(null, "avro", dest);
if (dest instanceof stream_1.Writable || typeof dest === "string") {
return _df.writeAvro(dest, options.compression);
}
else {
return writeToBufferOrStream(dest, "avro", options);
}
let buffers = [];
const writeStream = new stream_1.Stream.Writable({
write(chunk, _encoding, callback) {
buffers.push(chunk);
callback(null);
}
});
_df.writeAvro(writeStream, dest?.compression ?? options?.compression);
writeStream.end("");
return Buffer.concat(buffers);
},

@@ -514,13 +468,22 @@ toIPC(dest, options) {

writeIPC(dest, options = { compression: "uncompressed" }) {
if (dest?.compression !== undefined) {
return writeToBufferOrStream(null, "ipc", dest);
if (dest instanceof stream_1.Writable || typeof dest === "string") {
return _df.writeIpc(dest, options.compression);
}
else {
return writeToBufferOrStream(dest, "ipc", options);
}
let buffers = [];
const writeStream = new stream_1.Stream.Writable({
write(chunk, _encoding, callback) {
buffers.push(chunk);
callback(null);
}
});
_df.writeIpc(writeStream, dest?.compression ?? options?.compression);
writeStream.end("");
return Buffer.concat(buffers);
},
toSeries: (index) => (0, series_1.seriesWrapper)(unwrap("select_at_idx", { index })),
toString: () => noArgUnwrap("as_str")().toString(),
toSeries: (index = 0) => (0, series_1._Series)(_df.selectAtIdx(index)),
toString() {
return _df.toString();
},
transpose(options) {
let df = wrap("transpose", options);
let df = wrap("transpose", options?.includeHeader ?? false, options?.headerName);
if (options?.columnNames) {

@@ -543,9 +506,13 @@ function* namesIter() {

},
var: noArgWrap("var"),
map: (fn) => map((0, exports.dfWrapper)(_df), fn),
row: (index) => unwrap("to_row", { idx: index }),
vstack: (other) => wrap("vstack", { other: other._df }),
var() {
return wrap("var");
},
map: (fn) => map((0, exports._DataFrame)(_df), fn),
row(idx) {
return _df.toRow(idx);
},
vstack: (other) => wrap("vstack", other.inner()),
withColumn(column) {
if (series_1.Series.isSeries(column)) {
return wrap("with_column", { _series: column._series });
return wrap("withColumn", column.inner());
}

@@ -559,3 +526,3 @@ else {

if ((0, utils_1.isSeriesArray)(columns)) {
return columns.reduce((acc, curr) => acc.withColumn(curr), (0, exports.dfWrapper)(_df));
return columns.reduce((acc, curr) => acc.withColumn(curr), (0, exports._DataFrame)(_df));
}

@@ -577,16 +544,18 @@ else {

},
withRowCount: (name = "row_nr") => wrap("with_row_count", { name }),
withRowCount(name = "row_nr") {
return wrap("withRowCount", name);
},
where(predicate) {
return this.filter(predicate);
},
add: (other) => wrap("add", { other: prepareOtherArg(other)._series }),
sub: (other) => wrap("sub", { other: prepareOtherArg(other)._series }),
div: (other) => wrap("div", { other: prepareOtherArg(other)._series }),
mul: (other) => wrap("mul", { other: prepareOtherArg(other)._series }),
rem: (other) => wrap("rem", { other: prepareOtherArg(other)._series }),
plus: (other) => wrap("add", { other: prepareOtherArg(other)._series }),
minus: (other) => wrap("sub", { other: prepareOtherArg(other)._series }),
divideBy: (other) => wrap("div", { other: prepareOtherArg(other)._series }),
multiplyBy: (other) => wrap("mul", { other: prepareOtherArg(other)._series }),
modulo: (other) => wrap("rem", { other: prepareOtherArg(other)._series }),
add: (other) => wrap("add", prepareOtherArg(other).inner()),
sub: (other) => wrap("sub", prepareOtherArg(other).inner()),
div: (other) => wrap("div", prepareOtherArg(other).inner()),
mul: (other) => wrap("mul", prepareOtherArg(other).inner()),
rem: (other) => wrap("rem", prepareOtherArg(other).inner()),
plus: (other) => wrap("add", prepareOtherArg(other).inner()),
minus: (other) => wrap("sub", prepareOtherArg(other).inner()),
divideBy: (other) => wrap("div", prepareOtherArg(other).inner()),
multiplyBy: (other) => wrap("mul", prepareOtherArg(other).inner()),
modulo: (other) => wrap("rem", prepareOtherArg(other).inner()),
};

@@ -631,11 +600,11 @@ return new Proxy(df, {

};
exports.dfWrapper = dfWrapper;
exports._DataFrame = _DataFrame;
function DataFrameConstructor(data, options) {
if (!data) {
return (0, exports.dfWrapper)(objToDF({}));
return (0, exports._DataFrame)(objToDF({}));
}
if (Array.isArray(data)) {
return (0, exports.dfWrapper)((0, construction_1.arrayToJsDataFrame)(data, options));
return (0, exports._DataFrame)((0, construction_1.arrayToJsDataFrame)(data, options));
}
return (0, exports.dfWrapper)(objToDF(data));
return (0, exports._DataFrame)(objToDF(data));
}

@@ -645,11 +614,11 @@ function objToDF(obj) {

if (series_1.Series.isSeries(values)) {
return values.rename(name)._series;
return values.rename(name).inner();
}
return (0, series_1.Series)(name, values)._series;
return (0, series_1.Series)(name, values).inner();
});
return polars_internal_1.default.df.read_columns({ columns });
return new polars_internal_1.default.JsDataFrame(columns);
}
const isDataFrame = (ty) => (0, types_1.isExternal)(ty?._df);
const isDataFrame = (anyVal) => anyVal?.[Symbol.toStringTag] === "DataFrame";
const fromBinary = (buf) => {
return (0, exports.dfWrapper)(polars_internal_1.default.df.from_bincode(buf));
return (0, exports._DataFrame)(polars_internal_1.default.JsDataFrame.fromBincode(buf));
};

@@ -656,0 +625,0 @@ exports.DataFrame = Object.assign(DataFrameConstructor, {

@@ -5,3 +5,3 @@ export declare type DtypeToPrimitive<T> = T extends DataType.Bool ? boolean : T extends DataType.Utf8 ? string : T extends DataType.Categorical ? string : T extends DataType.Datetime ? number | Date : T extends DataType.Date ? Date : T extends DataType.UInt64 ? bigint : number;

export declare type DtypeToTypedArray<T> = T extends DataType.Int8 ? Int8Array : T extends DataType.Int16 ? Int16Array : T extends DataType.Int32 ? Int32Array : T extends DataType.Int64 ? BigInt64Array : T extends DataType.UInt8 ? Uint8Array : T extends DataType.UInt16 ? Uint16Array : T extends DataType.UInt32 ? Uint32Array : T extends DataType.UInt64 ? BigInt64Array : T extends DataType.Float32 ? Float32Array : T extends DataType.Float64 ? Float64Array : never;
export declare type Optional<T> = T | undefined;
export declare type Optional<T> = T | undefined | null;
export declare enum DataType {

@@ -25,3 +25,4 @@ Int8 = 0,

Object = 16,
Categorical = 17
Categorical = 17,
Struct = 18
}

@@ -28,0 +29,0 @@ export declare type JsDataFrame = any;

@@ -28,41 +28,74 @@ "use strict";

DataType[DataType["Categorical"] = 17] = "Categorical";
DataType[DataType["Struct"] = 18] = "Struct";
})(DataType = exports.DataType || (exports.DataType = {}));
exports.DTYPE_TO_FFINAME = {
[DataType.Int8]: "i8",
[DataType.Int16]: "i16",
[DataType.Int32]: "i32",
[DataType.Int64]: "i64",
[DataType.UInt8]: "u8",
[DataType.UInt16]: "u16",
[DataType.UInt32]: "u32",
[DataType.UInt64]: "u64",
[DataType.Float32]: "f32",
[DataType.Float64]: "f64",
[DataType.Bool]: "bool",
[DataType.Utf8]: "str",
[DataType.List]: "list",
[DataType.Date]: "date",
[DataType.Datetime]: "datetime",
[DataType.Time]: "time",
[DataType.Object]: "object",
[DataType.Categorical]: "categorical",
[DataType.Int8]: "I8",
[DataType.Int16]: "I16",
[DataType.Int32]: "I32",
[DataType.Int64]: "I64",
[DataType.UInt8]: "U8",
[DataType.UInt16]: "U16",
[DataType.UInt32]: "U32",
[DataType.UInt64]: "U64",
[DataType.Float32]: "F32",
[DataType.Float64]: "F64",
[DataType.Bool]: "Bool",
[DataType.Utf8]: "Str",
[DataType.List]: "List",
[DataType.Date]: "Date",
[DataType.Datetime]: "Datetime",
[DataType.Time]: "Time",
[DataType.Object]: "Object",
[DataType.Categorical]: "Categorical",
[DataType.Struct]: "Struct",
};
const POLARS_TYPE_TO_CONSTRUCTOR = {
Float32: "new_opt_f32",
Float64: "new_opt_f64",
Int8: "new_opt_i8",
Int16: "new_opt_i16",
Int32: "new_opt_i32",
Int64: "new_opt_i64",
UInt8: "new_opt_u8",
UInt16: "new_opt_u16",
UInt32: "new_opt_u32",
UInt64: "new_opt_u64",
Date: "new_opt_u32",
Datetime: "new_opt_u32",
Bool: "new_opt_bool",
Utf8: "new_str",
Categorical: "new_str",
Object: "new_object",
List: "new_list",
Float32(name, values, strict) {
return polars_internal_1.default.JsSeries.newOptF64(name, values, strict);
},
Float64(name, values, strict) {
return polars_internal_1.default.JsSeries.newOptF64(name, values, strict);
},
Int8(name, values, strict) {
return polars_internal_1.default.JsSeries.newOptI32(name, values, strict);
},
Int16(name, values, strict) {
return polars_internal_1.default.JsSeries.newOptI32(name, values, strict);
},
Int32(name, values, strict) {
return polars_internal_1.default.JsSeries.newOptI32(name, values, strict);
},
Int64(name, values, strict) {
return polars_internal_1.default.JsSeries.newOptI64(name, values, strict);
},
UInt8(name, values, strict) {
return polars_internal_1.default.JsSeries.newOptU32(name, values, strict);
},
UInt16(name, values, strict) {
return polars_internal_1.default.JsSeries.newOptU32(name, values, strict);
},
UInt32(name, values, strict) {
return polars_internal_1.default.JsSeries.newOptU32(name, values, strict);
},
UInt64(name, values, strict) {
return polars_internal_1.default.JsSeries.newOptU64(name, values, strict);
},
Date(name, values, strict) {
return polars_internal_1.default.JsSeries.newOptI64(name, values, strict);
},
Datetime(name, values, strict) {
return polars_internal_1.default.JsSeries.newOptI64(name, values, strict);
},
Bool(name, values, strict) {
return polars_internal_1.default.JsSeries.newOptBool(name, values, strict);
},
Utf8(name, values, strict) {
return polars_internal_1.default.JsSeries.newOptStr(name, values, strict);
},
Categorical(name, values, strict) {
return polars_internal_1.default.JsSeries.newOptStr(name, values, strict);
},
List(name, values, _strict, dtype) {
return polars_internal_1.default.JsSeries.newList(name, values, dtype);
},
};

@@ -74,4 +107,4 @@ const polarsTypeToConstructor = (dtype) => {

}
return polars_internal_1.default.series[constructor];
return constructor;
};
exports.polarsTypeToConstructor = polarsTypeToConstructor;

@@ -22,3 +22,3 @@ import { Series } from "./series/series";

*/
export declare function repeat<V>(value: V, n: number, name?: string): Series<V>;
export declare function repeat<V>(value: V, n: number, name?: string): Series;
/**

@@ -48,5 +48,5 @@ * Aggregate all the Dataframes/Series in a List of DataFrames/Series to a single DataFrame/Series.

export declare function concat(items: Array<DataFrame>, options?: ConcatOptions): DataFrame;
export declare function concat<T>(items: Array<Series<T>>, options?: {
export declare function concat<T>(items: Array<Series>, options?: {
rechunk: boolean;
}): Series<T>;
}): Series;
export {};

@@ -30,4 +30,4 @@ "use strict";

const dtype = (0, construction_1.jsTypeToPolarsType)(value);
const s = polars_internal_1.default.repeat({ name, value, dtype, n });
return (0, series_1.seriesWrapper)(s);
const s = polars_internal_1.default.JsSeries.repeat(name, value, n, dtype);
return (0, series_1._Series)(s);
}

@@ -46,3 +46,3 @@ exports.repeat = repeat;

else {
df = (0, dataframe_1.dfWrapper)(polars_internal_1.default.horizontalConcatDF({ items: items.map(i => i._df) }));
df = (0, dataframe_1._DataFrame)(polars_internal_1.default.horizontalConcat(items.map((i) => i.inner())));
}

@@ -49,0 +49,0 @@ return rechunk ? df.rechunk() : df;

@@ -154,3 +154,3 @@ import { DataFrame } from "./dataframe";

};
export declare function GroupBy(df: DataFrame, by: string[], maintainOrder?: boolean): GroupBy;
export declare function GroupBy(df: any, by: string[], maintainOrder?: boolean): GroupBy;
export {};

@@ -30,3 +30,2 @@ "use strict";

const functions_1 = require("./lazy/functions");
const polars_internal_1 = __importDefault(require("./internals/polars_internal"));
const inspect = Symbol.for("nodejs.util.inspect.custom");

@@ -50,3 +49,4 @@ const inspectOpts = { colors: true, depth: null };

aggs = [aggs].flat(2);
return (0, dataframe_1.dfWrapper)(df).lazy()
return (0, dataframe_1._DataFrame)(df)
.lazy()
.groupBy(by, maintainOrder)

@@ -61,3 +61,3 @@ .agg(...aggs)

});
return (0, dataframe_1.dfWrapper)(df)
return (0, dataframe_1._DataFrame)(df)
.lazy()

@@ -74,5 +74,9 @@ .groupBy(by, maintainOrder)

aggList: () => agg((0, functions_1.exclude)(by).list()),
count: () => (0, dataframe_1.dfWrapper)(polars_internal_1.default.df.groupby({ by, agg: "count", _df: df })),
count() {
return (0, dataframe_1._DataFrame)(df.groupby([by].flat(), null, "count"));
},
first: () => agg((0, functions_1.exclude)(by).first()),
groups: () => (0, dataframe_1.dfWrapper)(polars_internal_1.default.df.groupby({ by, agg: "groups", _df: df })),
groups() {
return (0, dataframe_1._DataFrame)(df.groupby([by].flat(), null, "groups"));
},
head: (n = 5) => agg((0, functions_1.exclude)(by).head(n)),

@@ -93,3 +97,3 @@ last: () => agg((0, functions_1.exclude)(by).last()),

function PivotOps(df, by, pivotCol, valueCol) {
const pivot = (agg) => () => (0, dataframe_1.dfWrapper)(polars_internal_1.default.df.pivot({ by, pivotCol, valueCol, agg, _df: df }));
const pivot = (agg) => () => (0, dataframe_1._DataFrame)(df.pivot([by].flat(), [pivotCol], [valueCol], agg));
const customInspect = () => util_1.default.formatWithOptions(inspectOpts, "PivotOps {by: %O}", by);

@@ -96,0 +100,0 @@ return {

@@ -7,3 +7,2 @@ import * as series from "./series/series";

import * as cfg from "./cfg";
import type { FillNullStrategy as _FillNullStrategy } from "./utils";
import { funcs as lazy, Expr as lazyExpr, GroupBy as lazyGroupBy, when as _when } from "./lazy";

@@ -18,3 +17,2 @@ declare namespace pl {

type WhenThenThen = _when.WhenThenThen;
type FillNullStrategy = _FillNullStrategy;
export import Config = cfg.Config;

@@ -44,2 +42,3 @@ export import Int8 = DataType.Int8;

export import scanParquet = io.scanParquet;
export import readRecords = io.readRecords;
export import readCSV = io.readCSV;

@@ -78,4 +77,4 @@ export import readIPC = io.readIPC;

export import when = _when.when;
const version: string;
const version: any;
}
export = pl;

@@ -21,2 +21,5 @@ "use strict";

};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
const series = __importStar(require("./series/series"));

@@ -28,3 +31,3 @@ const df = __importStar(require("./dataframe"));

const cfg = __importStar(require("./cfg"));
const package_json_1 = require("../package.json");
const polars_internal_1 = __importDefault(require("./internals/polars_internal"));
const lazy_1 = require("./lazy");

@@ -57,6 +60,7 @@ var pl;

pl.concat = func.concat;
// IO
// // IO
pl.scanCSV = io.scanCSV;
pl.scanIPC = io.scanIPC;
pl.scanParquet = io.scanParquet;
pl.readRecords = io.readRecords;
pl.readCSV = io.readCSV;

@@ -69,3 +73,3 @@ pl.readIPC = io.readIPC;

pl.readJSONStream = io.readJSONStream;
// lazy
// // lazy
pl.col = lazy_1.funcs.col;

@@ -97,4 +101,4 @@ pl.cols = lazy_1.funcs.cols;

pl.when = lazy_1.when.when;
pl.version = package_json_1.version;
pl.version = polars_internal_1.default.version();
})(pl || (pl = {}));
module.exports = pl;

@@ -6,3 +6,3 @@ import { DataType } from "../datatypes";

*/
export declare function arrayToJsSeries(name: string, values: any[], dtype?: any, strict?: boolean): any;
export declare function arrayToJsSeries(name?: string, values?: any[], dtype?: any, strict?: boolean): any;
export declare function arrayToJsDataFrame(data: any[], options?: any): any;

@@ -16,3 +16,3 @@ "use strict";

if (Array.isArray(value)) {
return (0, exports.jsTypeToPolarsType)(value[0]);
return (0, exports.jsTypeToPolarsType)(firstNonNull(value));
}

@@ -49,3 +49,3 @@ if ((0, types_1.isTypedArray)(value)) {

if (typeof value === "object" && value.constructor === Object) {
return datatypes_1.DataType.Object;
return datatypes_1.DataType.Struct;
}

@@ -89,11 +89,39 @@ switch (typeof value) {

};
const fromTypedArray = (name, value) => {
switch (value.constructor.name) {
case Int8Array.name:
return polars_internal_1.default.JsSeries.newInt8Array(name, value);
case Int16Array.name:
return polars_internal_1.default.JsSeries.newInt16Array(name, value);
case Int32Array.name:
return polars_internal_1.default.JsSeries.newInt32Array(name, value);
case BigInt64Array.name:
return polars_internal_1.default.JsSeries.newBigint64Array(name, value);
case Uint8Array.name:
return polars_internal_1.default.JsSeries.newUint8Array(name, value);
case Uint8ClampedArray.name:
return polars_internal_1.default.JsSeries.newUint8ClampedArray(name, value);
case Uint16Array.name:
return polars_internal_1.default.JsSeries.newUint16Array(name, value);
case Uint32Array.name:
return polars_internal_1.default.JsSeries.newUint32Array(name, value);
case BigUint64Array.name:
return polars_internal_1.default.JsSeries.newBiguint64Array(name, value);
case Float32Array.name:
return polars_internal_1.default.JsSeries.newFloat32Array(name, value);
case Float64Array.name:
return polars_internal_1.default.JsSeries.newFloat64Array(name, value);
default:
throw new Error(`unknown typed array type: ${value.constructor.name}`);
}
};
/**
* Construct an internal `JsSeries` from an array
*/
function arrayToJsSeries(name, values, dtype, strict = false) {
function arrayToJsSeries(name = "", values = [], dtype, strict = false) {
if ((0, types_1.isTypedArray)(values)) {
return polars_internal_1.default.series.new_from_typed_array({ name, values, strict });
return fromTypedArray(name, values);
}
//Empty sequence defaults to Float64 type
if (!values.length && !dtype) {
if (!values?.length && !dtype) {
dtype = datatypes_1.DataType.Float64;

@@ -105,19 +133,29 @@ }

const constructor = (0, datatypes_1.polarsTypeToConstructor)(datatypes_1.DataType.List);
return constructor({ name, values, strict, dtype: listDtype });
return constructor(name, values, strict, listDtype);
}
dtype = dtype ?? (0, exports.jsTypeToPolarsType)(firstValue);
let series;
if (dtype === datatypes_1.DataType.Struct) {
const df = polars_internal_1.default.fromRows(values, null, 1);
return df.toStruct(name);
}
if (firstValue instanceof Date) {
series = polars_internal_1.default.series.new_opt_date({ name, values, strict });
series = polars_internal_1.default.JsSeries.newOptDate(name, values, strict);
}
else {
const constructor = (0, datatypes_1.polarsTypeToConstructor)(dtype);
series = constructor({ name, values, strict });
series = constructor(name, values, strict);
}
if ([datatypes_1.DataType.Datetime, datatypes_1.DataType.Date].includes(dtype)) {
series = polars_internal_1.default.series.cast({ _series: series, dtype, strict: false });
if ([
datatypes_1.DataType.Datetime,
datatypes_1.DataType.Date,
datatypes_1.DataType.Categorical,
datatypes_1.DataType.Int8,
datatypes_1.DataType.Int16,
datatypes_1.DataType.UInt8,
datatypes_1.DataType.UInt16,
datatypes_1.DataType.Float32,
].includes(dtype)) {
series = series.cast(dtype, strict);
}
if (dtype === datatypes_1.DataType.Categorical) {
series = polars_internal_1.default.series.cast({ _series: series, dtype, strict: false });
}
return series;

@@ -133,3 +171,3 @@ }

}
else if (data[0]?._series) {
else if (data[0]?._s) {
dataSeries = [];

@@ -140,9 +178,9 @@ data.forEach((series, idx) => {

}
dataSeries.push(series.inner());
dataSeries.push(series._s);
});
}
else if (data[0].constructor.name === "Object") {
const df = polars_internal_1.default.df.read_rows({ rows: data, ...options });
const df = polars_internal_1.default.fromRows(data, options);
if (columns) {
polars_internal_1.default.df.set_column_names({ _df: df, names: columns });
df.columns = columns;
}

@@ -156,15 +194,15 @@ return df;

if (orient === "row") {
const df = polars_internal_1.default.df.read_array_rows({ data });
columns && polars_internal_1.default.df.set_column_names({ _df: df, names: columns });
const df = polars_internal_1.default.fromRows(data);
columns && (df.columns = columns);
return df;
}
else {
dataSeries = data.map((s, idx) => (0, series_1.Series)(`column_${idx}`, s).inner());
dataSeries = data.map((s, idx) => (0, series_1.Series)(`column_${idx}`, s)._s);
}
}
else {
dataSeries = [(0, series_1.Series)("column_0", data).inner()];
dataSeries = [(0, series_1.Series)("column_0", data)._s];
}
dataSeries = handleColumnsArg(dataSeries, columns);
return polars_internal_1.default.df.read_columns({ columns: dataSeries });
return new polars_internal_1.default.JsDataFrame(dataSeries);
}

@@ -178,7 +216,7 @@ exports.arrayToJsDataFrame = arrayToJsDataFrame;

if (!data) {
return columns.map(c => (0, series_1.Series)(c, []).inner());
return columns.map(c => series_1.Series.from(c, [])._s);
}
else if (data.length === columns.length) {
columns.forEach((name, i) => {
polars_internal_1.default.series.rename({ _series: data[i], name });
data[i].rename(name);
});

@@ -185,0 +223,0 @@ return data;

@@ -1,2 +0,2 @@

declare const bindings: any;
export default bindings;
import pl from "../native-polars.js";
export default pl;
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
/* eslint-disable camelcase */
const helper_1 = require("@node-rs/helper");
const path_1 = require("path");
// eslint-disable-next-line no-undef
const up2 = (0, path_1.join)(__dirname, "../", "../");
const bindings = (0, helper_1.loadBinding)(up2, "nodejs-polars", "nodejs-polars");
exports.default = bindings;
const native_polars_js_1 = __importDefault(require("../native-polars.js"));
exports.default = native_polars_js_1.default;
/// <reference types="node" />
import { NullValues } from "./datatypes";
import { DataType } from "./datatypes";
import { DataFrame } from "./dataframe";
import { LazyDataFrame } from "./lazy/dataframe";
import { Readable } from "stream";
declare type ScanIPCOptions = {
numRows?: number;
cache?: boolean;
rechunk?: boolean;
};
declare type ScanParquetOptions = {
numRows?: number;
parallel?: boolean;
cache?: boolean;
rechunk?: boolean;
rowCount?: RowCount;
};
declare type RowCount = {
name: string;
offset?: number;
};
declare type ReadCsvOptions = {
batchSize?: number;
columns?: Array<string>;
commentChar?: string;
encoding?: "utf8" | "utf8-lossy";
endRows?: number;
hasHeader?: boolean;
ignoreErrors?: boolean;
export declare function readRecords(records: Record<string, any>[], options?: {
schema: Record<string, DataType>;
}): DataFrame;
export declare function readRecords(records: Record<string, any>[], options?: {
inferSchemaLength?: number;
lowMemory?: boolean;
nullValues?: NullValues;
numThreads?: number;
parseDates?: boolean;
projection?: Array<number>;
quoteChar?: string;
rechunk?: boolean;
sep?: string;
startRows?: number;
rowCount?: RowCount;
};
declare type ReadJsonOptions = {
inferSchemaLength?: number;
batchSize?: number;
};
declare type ReadParquetOptions = {
columns?: string[];
projection?: number[];
numRows?: number;
parallel?: boolean;
rechunk?: boolean;
rowCount?: RowCount;
};
declare type ReadIPCOptions = {
columns?: string[];
projection?: number[];
numRows?: number;
rowCount?: RowCount;
};
declare type ReadAvroOptions = {
columns?: string[];
projection?: number[];
numRows?: number;
rowCount?: RowCount;
};
}): DataFrame;
/**

@@ -100,3 +46,3 @@ * __Read a CSV file or string into a Dataframe.__

*/
export declare function readCSV(pathOrBody: string | Buffer, options?: Partial<ReadCsvOptions>): DataFrame;
export declare function readCSV(pathOrBody: string | Buffer, options?: any): DataFrame;
/**

@@ -114,4 +60,4 @@ * __Lazily read from a CSV file or multiple files via glob patterns.__

* @param options.commentChar - character that indicates the start of a comment line, for instance '#'.
* @param options.quotChar -character that is used for csv quoting, default = ''. Set to null to turn special handling and escaping of quotes off.
* @param options.startRows -Start reading after `startRows` position.
* @param options.quoteChar -character that is used for csv quoting, default = ''. Set to null to turn special handling and escaping of quotes off.
* @param options.skipRows -Start reading after `skipRows` position.
* @param options.nullValues - Values to interpret as null values. You can provide a

@@ -125,4 +71,3 @@ * - `string` -> all values encountered equal to this string will be null

* If set to `null`, a full table scan will be done (slow).
* @param options.batchSize - Number of lines to read into the buffer at once. Modify this to change performance.
* @param options.endRows -After n rows are read from the CSV, it stops reading.
* @param options.n_rows -After n rows are read from the CSV, it stops reading.
* During multi-threaded parsing, an upper bound of `n` rows

@@ -135,3 +80,3 @@ * cannot be guaranteed.

*/
export declare function scanCSV(path: string, options?: Partial<ReadCsvOptions>): LazyDataFrame;
export declare function scanCSV(path: string, options?: any): LazyDataFrame;
/**

@@ -147,2 +92,3 @@ * __Read a JSON file or string into a DataFrame.__

* If set to `null`, a full table scan will be done (slow).
* @param options.jsonFormat - Either "lines" or "json"
* @param options.batchSize - Number of lines to read into the buffer at once. Modify this to change performance.

@@ -170,3 +116,3 @@ * @returns ({@link DataFrame})

*/
export declare function readJSON(pathOrBody: string | Buffer, options?: Partial<ReadJsonOptions>): DataFrame;
export declare function readJSON(pathOrBody: string | Buffer, options?: any): DataFrame;
/**

@@ -178,6 +124,8 @@ * Read into a DataFrame from a parquet file.

* @param options.columns Columns to select. Accepts a list of column names.
* @param options.projection -Indices of columns to select. Note that column indices start at zero.
* @param options.numRows Stop reading from parquet file after reading ``n_rows``.
* @param options.parallel Read the parquet file in parallel. The single threaded reader consumes less memory.
* @param options.rowCount Add row count as column
*/
export declare function readParquet(pathOrBody: string | Buffer, options?: ReadParquetOptions): DataFrame;
export declare function readParquet(pathOrBody: string | Buffer, options?: any): DataFrame;
/**

@@ -189,5 +137,6 @@ * Read into a DataFrame from an avro file.

* @param options.columns Columns to select. Accepts a list of column names.
* @param options.numRows Stop reading from avro file after reading ``n_rows``.
* @param options.projection -Indices of columns to select. Note that column indices start at zero.
* @param options.nRows Stop reading from avro file after reading ``n_rows``.
*/
export declare function readAvro(pathOrBody: string | Buffer, options?: ReadAvroOptions): DataFrame;
export declare function readAvro(pathOrBody: string | Buffer, options?: any): DataFrame;
/**

@@ -199,3 +148,3 @@ * __Lazily read from a parquet file or multiple files via glob patterns.__

* @param path Path to a file or or glob pattern
* @param options.numRows Stop reading from parquet file after reading ``n_rows``.
* @param options.nRows Stop reading from parquet file after reading ``n_rows``.
* @param options.cache Cache the result after reading.

@@ -205,3 +154,3 @@ * @param options.parallel Read the parquet file in parallel. The single threaded reader consumes less memory.

*/
export declare function scanParquet(path: string, options?: ScanParquetOptions): LazyDataFrame;
export declare function scanParquet(path: string, options?: any): LazyDataFrame;
/**

@@ -216,3 +165,3 @@ * __Read into a DataFrame from Arrow IPC (Feather v2) file.__

*/
export declare function readIPC(pathOrBody: string | Buffer, options?: ReadIPCOptions): DataFrame;
export declare function readIPC(pathOrBody: string | Buffer, options?: any): DataFrame;
/**

@@ -226,3 +175,3 @@ * __Lazily read from an Arrow IPC (Feather v2) file or multiple files via glob patterns.__

*/
export declare function scanIPC(path: string, options?: ScanIPCOptions): LazyDataFrame;
export declare function scanIPC(path: string, options?: any): LazyDataFrame;
/**

@@ -293,3 +242,3 @@ * __Read a stream into a Dataframe.__

*/
export declare function readCSVStream(stream: Readable, options?: ReadCsvOptions): Promise<DataFrame>;
export declare function readCSVStream(stream: Readable, options?: any): Promise<DataFrame>;
/**

@@ -330,3 +279,2 @@ * __Read a newline delimited JSON stream into a DataFrame.__

*/
export declare function readJSONStream(stream: Readable, options?: ReadJsonOptions): Promise<DataFrame>;
export {};
export declare function readJSONStream(stream: Readable, options?: any): Promise<DataFrame>;

@@ -18,3 +18,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.readJSONStream = exports.readCSVStream = exports.scanIPC = exports.readIPC = exports.scanParquet = exports.readAvro = exports.readParquet = exports.readJSON = exports.scanCSV = exports.readCSV = void 0;
exports.readJSONStream = exports.readCSVStream = exports.scanIPC = exports.readIPC = exports.scanParquet = exports.readAvro = exports.readParquet = exports.readJSON = exports.scanCSV = exports.readCSV = exports.readRecords = void 0;
const polars_internal_1 = __importDefault(require("./internals/polars_internal"));

@@ -27,16 +27,18 @@ const dataframe_1 = require("./dataframe");

const readCsvDefaultOptions = {
inferSchemaLength: 50,
batchSize: 10000,
inferSchemaLength: 100,
hasHeader: true,
ignoreErrors: true,
hasHeader: true,
chunkSize: 10000,
skipRows: 0,
sep: ",",
rechunk: false,
startRows: 0,
encoding: "utf8",
lowMemory: false,
parseDates: true,
parseDates: false,
skipRowsAfterHeader: 0
};
const readJsonDefaultOptions = {
batchSize: 10000,
inferSchemaLength: 50
inferSchemaLength: 50,
format: "lines"
};

@@ -84,35 +86,17 @@ // utility to read streams as lines.

function readCSVBuffer(buff, options) {
return (0, dataframe_1.dfWrapper)(polars_internal_1.default.df.readCSVBuffer({ ...readCsvDefaultOptions, ...options, buff }));
return (0, dataframe_1._DataFrame)(polars_internal_1.default.readCsv(buff, { ...readCsvDefaultOptions, ...options }));
}
function readCSVPath(path, options) {
return (0, dataframe_1.dfWrapper)(polars_internal_1.default.df.readCSVPath({ ...readCsvDefaultOptions, ...options, path }));
function readRecords(records, options) {
if (options?.schema) {
return (0, dataframe_1._DataFrame)(polars_internal_1.default.fromRows(records, options.schema));
}
else {
return (0, dataframe_1._DataFrame)(polars_internal_1.default.fromRows(records, undefined, options?.inferSchemaLength));
}
}
function readJSONBuffer(buff, options) {
return (0, dataframe_1.dfWrapper)(polars_internal_1.default.df.readJSONBuffer({ ...readJsonDefaultOptions, ...options, buff }));
}
function readJSONPath(path, options) {
return (0, dataframe_1.dfWrapper)(polars_internal_1.default.df.readJSONPath({ ...readJsonDefaultOptions, ...options, path }));
}
function readParquetBuffer(buff, options) {
return (0, dataframe_1.dfWrapper)(polars_internal_1.default.df.readParquetBuffer({ ...options, buff }));
}
function readParquetPath(path, options) {
return (0, dataframe_1.dfWrapper)(polars_internal_1.default.df.readParquetPath({ ...options, path }));
}
function readIPCBuffer(buff, options) {
return (0, dataframe_1.dfWrapper)(polars_internal_1.default.df.readIPCBuffer({ ...options, buff }));
}
function readIPCPath(path, options) {
return (0, dataframe_1.dfWrapper)(polars_internal_1.default.df.readIPCPath({ ...options, path }));
}
function readAvroBuffer(buff, options) {
return (0, dataframe_1.dfWrapper)(polars_internal_1.default.df.readAvroBuffer({ ...readCsvDefaultOptions, ...options, buff }));
}
function readAvroPath(path, options) {
return (0, dataframe_1.dfWrapper)(polars_internal_1.default.df.readAvroPath({ ...readCsvDefaultOptions, ...options, path }));
}
exports.readRecords = readRecords;
function readCSV(pathOrBody, options) {
const extensions = [".tsv", ".csv"];
if (Buffer.isBuffer(pathOrBody)) {
return readCSVBuffer(pathOrBody, options);
return (0, dataframe_1._DataFrame)(polars_internal_1.default.readCsv(pathOrBody, { ...readCsvDefaultOptions, ...options }));
}

@@ -122,6 +106,7 @@ if (typeof pathOrBody === "string") {

if (inline) {
return readCSVBuffer(Buffer.from(pathOrBody, "utf-8"), options);
const buf = Buffer.from(pathOrBody, "utf-8");
return (0, dataframe_1._DataFrame)(polars_internal_1.default.readCsv(buf, { ...readCsvDefaultOptions, ...options }));
}
else {
return readCSVPath(pathOrBody, options);
return (0, dataframe_1._DataFrame)(polars_internal_1.default.readCsv(pathOrBody, { ...readCsvDefaultOptions, ...options }));
}

@@ -134,11 +119,25 @@ }

exports.readCSV = readCSV;
const scanCsvDefaultOptions = {
inferSchemaLength: 100,
cache: true,
hasHeader: true,
ignoreErrors: true,
skipRows: 0,
sep: ",",
rechunk: false,
encoding: "utf8",
lowMemory: false,
parseDates: false,
skipRowsAfterHeader: 0
};
function scanCSV(path, options) {
options = { ...readCsvDefaultOptions, ...options };
return (0, dataframe_2.LazyDataFrame)(polars_internal_1.default.ldf.scanCSV({ path, ...options }));
options = { ...scanCsvDefaultOptions, ...options };
return (0, dataframe_2._LazyDataFrame)(polars_internal_1.default.scanCsv(path, options));
}
exports.scanCSV = scanCSV;
function readJSON(pathOrBody, options) {
function readJSON(pathOrBody, options = readJsonDefaultOptions) {
options = { ...readJsonDefaultOptions, ...options };
const extensions = [".ndjson", ".json", ".jsonl"];
if (Buffer.isBuffer(pathOrBody)) {
return readJSONBuffer(pathOrBody, options);
return (0, dataframe_1._DataFrame)(polars_internal_1.default.readJson(pathOrBody, options));
}

@@ -148,6 +147,6 @@ if (typeof pathOrBody === "string") {

if (inline) {
return readJSONBuffer(Buffer.from(pathOrBody, "utf-8"), options);
return (0, dataframe_1._DataFrame)(polars_internal_1.default.readJson(Buffer.from(pathOrBody, "utf-8"), options));
}
else {
return readJSONPath(pathOrBody, options);
return (0, dataframe_1._DataFrame)(polars_internal_1.default.readJson(pathOrBody, options));
}

@@ -160,5 +159,5 @@ }

exports.readJSON = readJSON;
function readParquet(pathOrBody, options) {
function readParquet(pathOrBody, options = {}) {
if (Buffer.isBuffer(pathOrBody)) {
return readParquetBuffer(pathOrBody, options);
return (0, dataframe_1._DataFrame)(polars_internal_1.default.readParquet(pathOrBody, options));
}

@@ -168,6 +167,6 @@ if (typeof pathOrBody === "string") {

if (inline) {
return readParquetBuffer(Buffer.from(pathOrBody, "utf-8"), options);
return (0, dataframe_1._DataFrame)(polars_internal_1.default.readParquet(Buffer.from(pathOrBody), options));
}
else {
return readParquetPath(pathOrBody, options);
return (0, dataframe_1._DataFrame)(polars_internal_1.default.readParquet(pathOrBody, options));
}

@@ -180,5 +179,5 @@ }

exports.readParquet = readParquet;
function readAvro(pathOrBody, options) {
function readAvro(pathOrBody, options = {}) {
if (Buffer.isBuffer(pathOrBody)) {
return readAvroBuffer(pathOrBody, options);
return (0, dataframe_1._DataFrame)(polars_internal_1.default.readAvro(pathOrBody, options));
}

@@ -188,6 +187,6 @@ if (typeof pathOrBody === "string") {

if (inline) {
return readAvroBuffer(Buffer.from(pathOrBody, "utf-8"), options);
return (0, dataframe_1._DataFrame)(polars_internal_1.default.readAvro(Buffer.from(pathOrBody), options));
}
else {
return readAvroPath(pathOrBody, options);
return (0, dataframe_1._DataFrame)(polars_internal_1.default.readAvro(pathOrBody, options));
}

@@ -200,9 +199,9 @@ }

exports.readAvro = readAvro;
function scanParquet(path, options) {
return (0, dataframe_2.LazyDataFrame)(polars_internal_1.default.ldf.scanParquet({ path, ...options }));
function scanParquet(path, options = {}) {
return (0, dataframe_2._LazyDataFrame)(polars_internal_1.default.scanParquet(path, options));
}
exports.scanParquet = scanParquet;
function readIPC(pathOrBody, options) {
function readIPC(pathOrBody, options = {}) {
if (Buffer.isBuffer(pathOrBody)) {
return readIPCBuffer(pathOrBody, options);
return (0, dataframe_1._DataFrame)(polars_internal_1.default.readIpc(pathOrBody, options));
}

@@ -212,6 +211,6 @@ if (typeof pathOrBody === "string") {

if (inline) {
return readIPCBuffer(Buffer.from(pathOrBody, "utf-8"), options);
return (0, dataframe_1._DataFrame)(polars_internal_1.default.readIpc(Buffer.from(pathOrBody, "utf-8"), options));
}
else {
return readIPCPath(pathOrBody, options);
return (0, dataframe_1._DataFrame)(polars_internal_1.default.readIpc(pathOrBody, options));
}

@@ -224,4 +223,4 @@ }

exports.readIPC = readIPC;
function scanIPC(path, options) {
return (0, dataframe_2.LazyDataFrame)(polars_internal_1.default.ldf.scanIPC({ path, ...options }));
function scanIPC(path, options = {}) {
return (0, dataframe_2._LazyDataFrame)(polars_internal_1.default.scanIpc(path, options));
}

@@ -258,11 +257,11 @@ exports.scanIPC = scanIPC;

exports.readCSVStream = readCSVStream;
function readJSONStream(stream, options) {
let batchSize = options?.batchSize ?? 10000;
function readJSONStream(stream, options = readJsonDefaultOptions) {
options = { ...readJsonDefaultOptions, ...options };
return new Promise((resolve, reject) => {
const chunks = [];
stream
.pipe(new LineBatcher({ batchSize }))
.pipe(new LineBatcher({ batchSize: options.batchSize }))
.on("data", (chunk) => {
try {
const df = readJSONBuffer(chunk, options);
const df = (0, dataframe_1._DataFrame)(polars_internal_1.default.readJson(chunk, options));
chunks.push(df);

@@ -269,0 +268,0 @@ }

@@ -5,3 +5,2 @@ import { DataFrame } from "../dataframe";

import { LazyGroupBy } from "./groupby";
declare type JsLazyFrame = any;
declare type LazyJoinOptions = {

@@ -298,3 +297,3 @@ how?: "left" | "inner" | "outer" | "cross";

}
export declare const LazyDataFrame: (ldf: JsLazyFrame) => LazyDataFrame;
export declare const _LazyDataFrame: (_ldf: any) => LazyDataFrame;
export {};
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.LazyDataFrame = void 0;
exports._LazyDataFrame = void 0;
const dataframe_1 = require("../dataframe");
const expr_1 = require("./expr");
const utils_1 = require("../utils");
const polars_internal_1 = __importDefault(require("../internals/polars_internal"));
const groupby_1 = require("./groupby");
const LazyDataFrame = (ldf) => {
const unwrap = (method, args, _ldf = ldf) => {
return polars_internal_1.default.ldf[method]({ _ldf, ...args });
const _LazyDataFrame = (_ldf) => {
const unwrap = (method, ...args) => {
return _ldf[method](...args);
};
const wrap = (method, args, _ldf = ldf) => {
return (0, exports.LazyDataFrame)(unwrap(method, args, _ldf));
const wrap = (method, ...args) => {
return (0, exports._LazyDataFrame)(unwrap(method, ...args));
};

@@ -25,17 +21,29 @@ const wrapNullArgs = (method) => () => wrap(method);

return {
_ldf: ldf,
_ldf,
get columns() {
return unwrap("columns");
return _ldf.columns;
},
describePlan: () => unwrap("describePlan"),
describeOptimizedPlan: withOptimizationToggle("describeOptimizedPlan"),
cache: wrapNullArgs("cache"),
clone: wrapNullArgs("clone"),
collectSync: () => (0, dataframe_1.dfWrapper)(unwrap("collectSync")),
collect: () => unwrap("collect").then(dataframe_1.dfWrapper),
describePlan() {
return _ldf.describePlan();
},
describeOptimizedPlan() {
return _ldf.describeOptimizedPlan();
},
cache() {
return (0, exports._LazyDataFrame)(_ldf.cache());
},
clone() {
return (0, exports._LazyDataFrame)(_ldf.clone());
},
collectSync() {
return (0, dataframe_1._DataFrame)(_ldf.collectSync());
},
collect() {
return _ldf.collect().then(dataframe_1._DataFrame);
},
drop(...cols) {
return wrap("dropColumns", { cols: cols.flat(2) });
return (0, exports._LazyDataFrame)(_ldf.dropColumns(cols.flat(2)));
},
distinct(...args) {
return this.unique(...args);
return (0, exports._LazyDataFrame)(_ldf.unique(...args));
},

@@ -48,3 +56,4 @@ unique(opts = false, subset, keep = "first") {

if (typeof opts === "boolean") {
return wrap("unique", { ...defaultOptions, maintainOrder: opts, subset, keep });
const o = { ...defaultOptions, maintainOrder: opts, subset, keep };
return (0, exports._LazyDataFrame)(_ldf.unique(o.maintainOrder, o?.subset?.flat(2), o.keep));
}

@@ -54,7 +63,8 @@ if (opts.subset) {

}
return wrap("unique", { ...defaultOptions, ...opts });
const o = { ...defaultOptions, ...opts };
return (0, exports._LazyDataFrame)(_ldf.unique(o.maintainOrder, o.subset, o.keep));
},
dropNulls(...subset) {
if (subset.length) {
return wrap("dropNulls", { subset: subset.flat(2) });
return wrap("dropNulls", subset.flat(2));
}

@@ -67,7 +77,7 @@ else {

if (!columns.length) {
const cols = (0, utils_1.selectionToExprList)((0, exports.LazyDataFrame)(ldf).columns, false);
return wrap("explode", { column: cols });
const cols = (0, utils_1.selectionToExprList)(_ldf.columns, false);
return wrap("explode", cols);
}
const column = (0, utils_1.selectionToExprList)(columns, false);
return wrap("explode", { column });
return wrap("explode", column);
},

@@ -80,6 +90,5 @@ fetchSync(numRows, opts) {

if (opts) {
const _ldf = unwrap("optimizationToggle", opts);
return (0, dataframe_1.dfWrapper)(unwrap("fetchSync", { numRows }, _ldf));
_ldf = _ldf.optimizationToggle(opts.typeCoercion, opts.predicatePushdown, opts.projectionPushdown, opts.simplifyExpr, opts.stringCache, opts.slicePushdown);
}
return (0, dataframe_1.dfWrapper)(unwrap("fetchSync", { numRows }));
return (0, dataframe_1._DataFrame)(_ldf.fetchSync(numRows));
},

@@ -92,6 +101,5 @@ fetch(numRows, opts) {

if (opts) {
const _ldf = unwrap("optimizationToggle", opts);
return unwrap("fetch", { numRows }, _ldf).then(dataframe_1.dfWrapper);
_ldf = _ldf.optimizationToggle(opts.typeCoercion, opts.predicatePushdown, opts.projectionPushdown, opts.simplifyExpr, opts.stringCache, opts.slicePushdown);
}
return unwrap("fetch", { numRows }).then(dataframe_1.dfWrapper);
return _ldf.fetch(numRows).then(dataframe_1._DataFrame);
},

@@ -103,16 +111,18 @@ first() {

const fillValue = (0, expr_1.exprToLitOrExpr)(exprOrValue)._expr;
return wrap("fillNull", { fillValue });
return (0, exports._LazyDataFrame)(_ldf.fillNull(fillValue));
},
filter(exprOrValue) {
const predicate = (0, expr_1.exprToLitOrExpr)(exprOrValue, false)._expr;
return wrap("filter", { predicate });
return (0, exports._LazyDataFrame)(_ldf.filter(predicate));
},
groupBy(opt, maintainOrder = true) {
if (opt?.by !== undefined) {
return (0, groupby_1.LazyGroupBy)(ldf, opt.by, opt.maintainOrder);
const by = (0, utils_1.selectionToExprList)([opt.by], false);
return (0, groupby_1.LazyGroupBy)(_ldf.groupby(by, opt.maintainOrder));
}
return (0, groupby_1.LazyGroupBy)(ldf, opt, maintainOrder);
const by = (0, utils_1.selectionToExprList)([opt], false);
return (0, groupby_1.LazyGroupBy)(_ldf.groupby(by, maintainOrder));
},
head(len = 5) {
return wrap("slice", { offset: 0, len });
return (0, exports._LazyDataFrame)(_ldf.slice(0, len));
},

@@ -142,42 +152,48 @@ join(df, options) {

}
return wrap("join", {
other: df._ldf,
how,
leftOn,
rightOn,
suffix,
allowParallel,
forceParallel
});
const ldf = _ldf.join(df._ldf, leftOn, rightOn, allowParallel, forceParallel, how, suffix, [], []);
return (0, exports._LazyDataFrame)(ldf);
},
last: () => wrap("tail", { length: 1 }),
last() {
return (0, exports._LazyDataFrame)(_ldf.tail(1));
},
limit(len = 5) {
return wrap("slice", { offset: 0, len });
return (0, exports._LazyDataFrame)(_ldf.slice(0, len));
},
max: wrapNullArgs("max"),
mean: wrapNullArgs("mean"),
median: wrapNullArgs("median"),
max() {
return (0, exports._LazyDataFrame)(_ldf.max());
},
mean() {
return (0, exports._LazyDataFrame)(_ldf.mean());
},
median() {
return (0, exports._LazyDataFrame)(_ldf.median());
},
melt(ids, values) {
return wrap("melt", {
idVars: (0, utils_1.columnOrColumnsStrict)(ids),
valueVars: (0, utils_1.columnOrColumnsStrict)(values)
});
return (0, exports._LazyDataFrame)(_ldf.melt((0, utils_1.columnOrColumnsStrict)(ids), (0, utils_1.columnOrColumnsStrict)(values)));
},
min: wrapNullArgs("min"),
quantile: (quantile) => wrap("quantile", { quantile }),
min() {
return (0, exports._LazyDataFrame)(_ldf.min());
},
quantile(quantile, interpolation = "nearest") {
return (0, exports._LazyDataFrame)(_ldf.quantile(quantile, interpolation));
},
rename(mapping) {
const existing = Object.keys(mapping);
const replacements = Object.values(mapping);
return wrap("rename", { existing, replacements });
return (0, exports._LazyDataFrame)(_ldf.rename(existing, replacements));
},
reverse: wrapNullArgs("reverse"),
reverse() {
return (0, exports._LazyDataFrame)(_ldf.reverse());
},
select(...exprs) {
const predicate = (0, utils_1.selectionToExprList)(exprs, false);
return wrap("select", { predicate });
const selections = (0, utils_1.selectionToExprList)(exprs, false);
return (0, exports._LazyDataFrame)(_ldf.select(selections));
},
shift: (periods) => wrap("shift", { periods }),
shift(periods) {
return (0, exports._LazyDataFrame)(_ldf.shift(periods));
},
shiftAndFill(optOrPeriods, fillValue) {
if (typeof optOrPeriods === "number") {
fillValue = (0, expr_1.exprToLitOrExpr)(fillValue)._expr;
return wrap("shiftAndFill", { periods: optOrPeriods, fillValue });
return (0, exports._LazyDataFrame)(_ldf.shiftAndFill(optOrPeriods, fillValue));
}

@@ -187,3 +203,3 @@ else {

const periods = optOrPeriods.periods;
return wrap("shiftAndFill", { periods, fillValue });
return (0, exports._LazyDataFrame)(_ldf.shiftAndFill(periods, fillValue));
}

@@ -193,5 +209,5 @@ },

if (opt?.offset !== undefined) {
return wrap("slice", { offset: opt.offset, len: opt.length });
return (0, exports._LazyDataFrame)(_ldf.slice(opt.offset, opt.length));
}
return wrap("slice", { offset: opt, len });
return (0, exports._LazyDataFrame)(_ldf.slice(opt, len));
},

@@ -203,3 +219,3 @@ sort(arg, reverse = false) {

if (typeof arg === "string") {
return wrap("sort", { by: arg, reverse });
return wrap("sort", arg, reverse, true);
}

@@ -209,20 +225,32 @@ else {

const by = (0, utils_1.selectionToExprList)(arg, false);
return wrap("sort_by_exprs", { by, reverse });
return wrap("sortByExprs", by, reverse, true);
}
},
std: wrapNullArgs("std"),
sum: wrapNullArgs("sum"),
var: wrapNullArgs("var"),
std() {
return (0, exports._LazyDataFrame)(_ldf.std());
},
sum() {
return (0, exports._LazyDataFrame)(_ldf.sum());
},
var() {
return (0, exports._LazyDataFrame)(_ldf.var());
},
tail(length = 5) {
return wrap("tail", { length });
return (0, exports._LazyDataFrame)(_ldf.tail(length));
},
withColumn: (expr) => wrap("withColumn", { expr: expr._expr }),
withColumn(expr) {
return (0, exports._LazyDataFrame)(_ldf.withColumn(expr._expr));
},
withColumns(...columns) {
const exprs = (0, utils_1.selectionToExprList)(columns, false);
return wrap("withColumns", { exprs });
return (0, exports._LazyDataFrame)(_ldf.withColumns(exprs));
},
withColumnRenamed: (existing, replacement) => wrap("withColumnRenamed", { existing, replacement }),
withRowCount: (name = "row_nr") => wrap("withRowCount", { name }),
withColumnRenamed(existing, replacement) {
return (0, exports._LazyDataFrame)(_ldf.rename([existing], [replacement]));
},
withRowCount(name = "row_nr") {
return (0, exports._LazyDataFrame)(_ldf.withRowCount(name));
},
};
};
exports.LazyDataFrame = LazyDataFrame;
exports._LazyDataFrame = _LazyDataFrame;

@@ -13,2 +13,4 @@ /// <reference types="node" />

get lst(): expr.List;
get struct(): expr.Struct;
[Symbol.toStringTag](): string;
[INSPECT_SYMBOL](): string;

@@ -210,2 +212,3 @@ /** serializes the Expr to a [bincode buffer](https://docs.rs/bincode/latest/bincode/index.html)

}): Expr;
inner(): any;
/** Interpolate intermediate values. The interpolation method is linear. */

@@ -505,2 +508,20 @@ interpolate(): Expr;

}): Expr;
/**
* Sort this column by the ordering of another column, or multiple other columns.
In projection/ selection context the whole column is sorted.
If used in a groupby context, the groups are sorted.
Parameters
----------
@param by
The column(s) used for sorting.
@param reverse
false -> order from small to large.
true -> order from large to small.
*/
sortBy(by: ExprOrString[] | ExprOrString, reverse?: boolean | boolean[]): Expr;
sortBy(options: {
by: ExprOrString[] | ExprOrString;
reverse?: boolean | boolean[];
}): Expr;
/** Get standard deviation. */

@@ -525,5 +546,5 @@ std(): Expr;

*/
take(index: Expr | number[] | Series<number>): Expr;
take(index: Expr | number[] | Series): Expr;
take({ index }: {
index: Expr | number[] | Series<number>;
index: Expr | number[] | Series;
}): Expr;

@@ -546,2 +567,3 @@ /** Take every nth value in the Series and return as a new Series. */

}
export declare const _Expr: (_expr: any) => Expr;
export interface ExprConstructor {

@@ -548,0 +570,0 @@ isExpr(arg: any): arg is Expr;

@@ -25,38 +25,20 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.exprToLitOrExpr = exports.Expr = void 0;
exports.exprToLitOrExpr = exports.Expr = exports._Expr = void 0;
const polars_internal_1 = __importDefault(require("../internals/polars_internal"));
const functions_1 = require("./functions");
const utils_1 = require("../utils");
const types_1 = require("util/types");
const series_1 = require("../series/series");
const expr = __importStar(require("./expr/"));
const _Expr = (_expr) => {
const wrap = (method, args) => {
return _Expr(polars_internal_1.default.expr[method]({ _expr, ...args }));
const unwrap = (method, ...args) => {
return _expr[method](...args);
};
const wrap = (method, ...args) => {
return (0, exports._Expr)(unwrap(method, ...args));
};
const wrapNullArgs = (method) => () => wrap(method);
const wrapExprArg = (method, lit = false) => (other) => {
const expr = (0, exports.exprToLitOrExpr)(other, lit)._expr;
return wrap(method, { other: expr });
const expr = (0, exports.exprToLitOrExpr)(other, lit).inner();
return wrap(method, expr);
};
const wrapUnary = (method, key) => (val) => wrap(method, { [key]: val?.[key] ?? val });
const wrapUnaryWithDefault = (method, key, otherwise) => (val = otherwise) => wrap(method, { [key]: val?.[key] ?? val });
const wrapBinary = (method, key0, key1) => (val0, val1) => {
if (val0[key0] !== undefined) {
return wrap(method, val0);
}
return wrap(method, {
[key0]: val0,
[key1]: val1
});
};
const wrapUnaryNumber = (method, key) => {
const f = (val) => {
if (typeof val === "number") {
return f({ [key]: val });
}
return wrap(method, val);
};
return f;
};
const rolling = (method) => (opts, weights, minPeriods, center) => {

@@ -68,5 +50,5 @@ const windowSize = opts?.["windowSize"] ?? (typeof opts === "number" ? opts : null);

const callOpts = {
window_size: opts?.["windowSize"] ?? (typeof opts === "number" ? opts : null),
windowSize: opts?.["windowSize"] ?? (typeof opts === "number" ? opts : null),
weights: opts?.["weights"] ?? weights,
min_periods: opts?.["minPeriods"] ?? minPeriods ?? windowSize,
minPeriods: opts?.["minPeriods"] ?? minPeriods ?? windowSize,
center: opts?.["center"] ?? center ?? false,

@@ -78,10 +60,13 @@ };

_expr,
[Symbol.toStringTag]() {
return "Expr";
},
[utils_1.INSPECT_SYMBOL]() {
return polars_internal_1.default.expr.as_str({ _expr });
return _expr.toString();
},
toBinary() {
return polars_internal_1.default.expr.to_bincode({ _expr });
return null;
},
toString() {
return polars_internal_1.default.expr.as_str({ _expr });
return _expr.toString();
},

@@ -97,116 +82,255 @@ get str() {

},
abs: wrapNullArgs("abs"),
aggGroups: wrapNullArgs("aggGroups"),
alias: wrapUnary("alias", "name"),
and: wrapExprArg("and"),
argMax: wrapNullArgs("argMax"),
argMin: wrapNullArgs("argMin"),
argSort: wrapUnaryWithDefault("argSort", "reverse", false),
argUnique: wrapNullArgs("argUnique"),
as: wrapUnary("alias", "name"),
backwardFill: wrapNullArgs("backwardFill"),
get struct() {
return expr.StructFunctions(_expr);
},
abs() {
return (0, exports._Expr)(_expr.abs());
},
aggGroups() {
return (0, exports._Expr)(_expr.aggGroups());
},
alias(name) {
return (0, exports._Expr)(_expr.alias(name));
},
inner() {
return _expr;
},
and(other) {
const expr = (0, exports.exprToLitOrExpr)(other, false).inner();
return (0, exports._Expr)(_expr.and(expr));
},
argMax() {
return (0, exports._Expr)(_expr.argMax());
},
argMin() {
return (0, exports._Expr)(_expr.argMin());
},
argSort(reverse = false) {
reverse = reverse?.reverse ?? reverse;
return (0, exports._Expr)(_expr.argSort(reverse));
},
argUnique() {
return (0, exports._Expr)(_expr.argUnique());
},
as(name) {
return (0, exports._Expr)(_expr.alias(name));
},
backwardFill() {
return (0, exports._Expr)(_expr.backwardFill());
},
cast(dtype, strict = false) {
return wrap("cast", { dtype, strict });
return (0, exports._Expr)(_expr.cast(dtype, strict));
},
ceil: wrapNullArgs("ceil"),
ceil() {
return (0, exports._Expr)(_expr.ceil());
},
clip(arg, max) {
if (typeof arg === "number") {
return wrap("clip", { min: arg, max });
return (0, exports._Expr)(_expr.clip(arg, max));
}
else {
return wrap("clip", arg);
return (0, exports._Expr)(_expr.clip(arg.min, arg.max));
}
},
count: wrapNullArgs("count"),
cumCount: wrapUnaryWithDefault("cumCount", "reverse", false),
cumMax: wrapUnaryWithDefault("cumMax", "reverse", false),
cumMin: wrapUnaryWithDefault("cumMin", "reverse", false),
cumProd: wrapUnaryWithDefault("cumProd", "reverse", false),
cumSum: wrapUnaryWithDefault("cumSum", "reverse", false),
diff: wrapBinary("diff", "n", "nullBehavior"),
dot: wrapExprArg("dot"),
count() {
return (0, exports._Expr)(_expr.count());
},
cumCount(reverse = false) {
reverse = reverse?.reverse ?? reverse;
return (0, exports._Expr)(_expr.cumcount(reverse?.reverse ?? reverse));
},
cumMax(reverse = false) {
reverse = reverse?.reverse ?? reverse;
return (0, exports._Expr)(_expr.cummax(reverse));
},
cumMin(reverse = false) {
reverse = reverse?.reverse ?? reverse;
return (0, exports._Expr)(_expr.cummin(reverse));
},
cumProd(reverse = false) {
reverse = reverse?.reverse ?? reverse;
return (0, exports._Expr)(_expr.cumprod(reverse));
},
cumSum(reverse = false) {
reverse = reverse?.reverse ?? reverse;
return (0, exports._Expr)(_expr.cumsum(reverse));
},
diff(n, nullBehavior = "ignore") {
if (typeof n === "number") {
return (0, exports._Expr)(_expr.diff(n, nullBehavior));
}
else {
return (0, exports._Expr)(_expr.diff(n.n, n.nullBehavior));
}
},
dot(other) {
const expr = (0, exports.exprToLitOrExpr)(other, false).inner();
return (0, exports._Expr)(_expr.dot(expr));
},
exclude(...columns) {
return wrap("exclude", { columns: columns.flat(2) });
return (0, exports._Expr)(_expr.exclude(columns.flat(2)));
},
explode: wrapNullArgs("explode"),
explode() {
return (0, exports._Expr)(_expr.explode());
},
extend(o, n) {
if (n !== null && typeof n === "number") {
return wrap("extendConstant", { value: o, n });
return (0, exports._Expr)(_expr.extendConstant(o, n));
}
return wrap("extendConstant", o);
return (0, exports._Expr)(_expr.extendConstant(o.value, o.n));
},
extendConstant(o, n) {
if (n !== null && typeof n === "number") {
return wrap("extendConstant", { value: o, n });
return (0, exports._Expr)(_expr.extendConstant(o, n));
}
return wrap("extendConstant", o);
return (0, exports._Expr)(_expr.extendConstant(o.value, o.n));
},
fillNan: wrapExprArg("fillNan", true),
fillNan(other) {
const expr = (0, exports.exprToLitOrExpr)(other, true).inner();
return (0, exports._Expr)(_expr.fillNan(expr));
},
fillNull(fillValue) {
if (["backward", "forward", "mean", "min", "max", "zero", "one"].includes(fillValue)) {
return wrap("fillNullWithStrategy", { strategy: fillValue });
return (0, exports._Expr)(_expr.fillNullWithStrategy(fillValue));
}
const expr = (0, exports.exprToLitOrExpr)(fillValue)._expr;
return wrap("fillNull", { other: expr });
const expr = (0, exports.exprToLitOrExpr)(fillValue).inner();
return (0, exports._Expr)(_expr.fillNull(expr));
},
filter: wrapExprArg("filter"),
first: wrapNullArgs("first"),
flatten: wrapNullArgs("explode"),
floor: wrapNullArgs("floor"),
forwardFill: wrapNullArgs("forwardFill"),
filter(predicate) {
const expr = (0, exports.exprToLitOrExpr)(predicate).inner();
return (0, exports._Expr)(_expr.filter(expr));
},
first() {
return (0, exports._Expr)(_expr.first());
},
flatten() {
return (0, exports._Expr)(_expr.explode());
},
floor() {
return (0, exports._Expr)(_expr.floor());
},
forwardFill() {
return (0, exports._Expr)(_expr.forwardFill());
},
hash(obj = 0, k1 = 1, k2 = 2, k3 = 3) {
if (typeof obj === "number" || typeof obj === "bigint") {
return wrap("hash", { k0: obj, k1: k1, k2: k2, k3: k3 });
return wrap("hash", BigInt(obj), BigInt(k1), BigInt(k2), BigInt(k3));
}
return wrap("hash", { k0: 0, k1, k2, k3, ...obj });
const o = { k0: obj, k1: k1, k2: k2, k3: k3, ...obj };
return wrap("hash", BigInt(o.k0), BigInt(o.k1), BigInt(o.k2), BigInt(o.k3));
},
head: wrapUnaryNumber("head", "length"),
interpolate: wrapNullArgs("interpolate"),
isDuplicated: wrapNullArgs("isDuplicated"),
isFinite: wrapNullArgs("isFinite"),
isFirst: wrapNullArgs("isFirst"),
head(length) {
if (typeof length === "number") {
return wrap("head", length);
}
return wrap("head", length.length);
},
interpolate() {
return (0, exports._Expr)(_expr.interpolate());
},
isDuplicated() {
return (0, exports._Expr)(_expr.isDuplicated());
},
isFinite() {
return (0, exports._Expr)(_expr.isFinite());
},
isInfinite() {
return (0, exports._Expr)(_expr.isInfinite());
},
isFirst() {
return (0, exports._Expr)(_expr.isFirst());
},
isNan() {
return (0, exports._Expr)(_expr.isNan());
},
isNotNan() {
return (0, exports._Expr)(_expr.isNotNan());
},
isNotNull() {
return (0, exports._Expr)(_expr.isNotNull());
},
isNull() {
return (0, exports._Expr)(_expr.isNull());
},
isUnique() {
return (0, exports._Expr)(_expr.isUnique());
},
isIn(other) {
if (Array.isArray(other)) {
other = (0, functions_1.lit)((0, series_1.Series)(other));
other = polars_internal_1.default.lit((0, series_1.Series)(other).inner());
}
else {
other = (0, exports.exprToLitOrExpr)(other, false);
other = (0, exports.exprToLitOrExpr)(other, false).inner();
}
return wrap("isIn", { other: other._expr });
return wrap("isIn", other);
},
isInfinite: wrapNullArgs("isInfinite"),
isNan: wrapNullArgs("isNan"),
isNotNan: wrapNullArgs("isNotNan"),
isNotNull: wrapNullArgs("isNotNull"),
isNull: wrapNullArgs("isNull"),
isUnique: wrapNullArgs("isUnique"),
keepName: wrapNullArgs("keepName"),
keepName() {
return (0, exports._Expr)(_expr.keepName());
},
kurtosis(obj, bias = true) {
return wrap("kurtosis", {
fisher: obj?.["fisher"] ?? (typeof obj === "boolean" ? obj : true),
bias: obj?.["bias"] ?? bias,
});
const fisher = obj?.["fisher"] ?? (typeof obj === "boolean" ? obj : true);
bias = obj?.["bias"] ?? bias;
return (0, exports._Expr)(_expr.kurtosis(fisher, bias));
},
last: wrapNullArgs("last"),
list: wrapNullArgs("list"),
lowerBound: wrapNullArgs("lowerBound"),
max: wrapNullArgs("max"),
mean: wrapNullArgs("mean"),
median: wrapNullArgs("median"),
min: wrapNullArgs("min"),
mode: wrapNullArgs("mode"),
not: wrapNullArgs("not"),
nUnique: wrapNullArgs("nUnique"),
or: wrapExprArg("or"),
last() {
return (0, exports._Expr)(_expr.last());
},
list() {
return (0, exports._Expr)(_expr.list());
},
lowerBound() {
return (0, exports._Expr)(_expr.lowerBound());
},
max() {
return (0, exports._Expr)(_expr.max());
},
mean() {
return (0, exports._Expr)(_expr.mean());
},
median() {
return (0, exports._Expr)(_expr.median());
},
min() {
return (0, exports._Expr)(_expr.min());
},
mode() {
return (0, exports._Expr)(_expr.mode());
},
not() {
return (0, exports._Expr)(_expr.not());
},
nUnique() {
return (0, exports._Expr)(_expr.nUnique());
},
or(other) {
const expr = (0, exports.exprToLitOrExpr)(other).inner();
return (0, exports._Expr)(_expr.or(expr));
},
over(...exprs) {
const partitionBy = (0, utils_1.selectionToExprList)(exprs, false);
return wrap("over", { partitionBy });
return wrap("over", partitionBy);
},
pow: wrapUnary("pow", "exponent"),
prefix: wrapUnary("prefix", "prefix"),
quantile: wrapUnary("quantile", "quantile"),
rank: wrapUnary("rank", "method"),
reinterpret: wrapUnaryWithDefault("reinterpret", "signed", true),
repeatBy: wrapExprArg("repeatBy"),
reverse: wrapNullArgs("reverse"),
pow(exponent) {
return (0, exports._Expr)(_expr.pow(exponent?.exponent ?? exponent));
},
prefix(prefix) {
return (0, exports._Expr)(_expr.prefix(prefix));
},
quantile(quantile, interpolation = "nearest") {
return (0, exports._Expr)(_expr.quantile(quantile, interpolation));
},
rank(method, reverse = false) {
return (0, exports._Expr)(_expr.rank(method?.method ?? method, method?.reverse ?? reverse));
},
reinterpret(signed = true) {
signed = signed?.signed ?? signed;
return (0, exports._Expr)(_expr.reinterpret(signed));
},
repeatBy(expr) {
const e = (0, exports.exprToLitOrExpr)(expr, false)._expr;
return (0, exports._Expr)(_expr.repeatBy(e));
},
reverse() {
return (0, exports._Expr)(_expr.reverse());
},
rollingMax: rolling("rollingMax"),

@@ -221,5 +345,3 @@ rollingMean: rolling("rollingMean"),

if (typeof val === "number") {
return wrap("rollingQuantile", {
quantile: val,
interpolation,
return wrap("rollingQuantile", val, interpolation ?? "nearest", {
windowSize,

@@ -231,11 +353,23 @@ weights,

}
return wrap("rollingQuantile", val);
windowSize = val?.["windowSize"] ?? (typeof val === "number" ? val : null);
if (windowSize === null) {
throw new Error("window size is required");
}
const options = {
windowSize: val?.["windowSize"] ?? (typeof val === "number" ? val : null),
weights: val?.["weights"] ?? weights,
minPeriods: val?.["minPeriods"] ?? minPeriods ?? windowSize,
center: val?.["center"] ?? center ?? false,
};
return wrap("rollingQuantile", val.quantile, val.interpolation ?? "nearest", options);
},
rollingSkew(val, bias = true) {
if (typeof val === "number") {
return wrap("rollingSkew", { windowSize: val, bias });
return wrap("rollingSkew", val, bias);
}
return wrap("rollingSkew", { bias: true, ...val });
return wrap("rollingSkew", val.windowSize, val.bias ?? bias);
},
round: wrapUnaryNumber("round", "decimals"),
round(decimals) {
return (0, exports._Expr)(_expr.round(decimals?.decimals ?? decimals));
},
sample(opts, frac, withReplacement = false, seed) {

@@ -259,38 +393,63 @@ if (opts?.n !== undefined || opts?.frac !== undefined) {

},
shift: wrapUnary("shift", "periods"),
shift(periods) {
return (0, exports._Expr)(_expr.shift(periods));
},
shiftAndFill(optOrPeriods, fillValue) {
if (typeof optOrPeriods === "number") {
fillValue = (0, exports.exprToLitOrExpr)(fillValue)._expr;
return wrap("shiftAndFill", { periods: optOrPeriods, fillValue });
fillValue = (0, exports.exprToLitOrExpr)(fillValue).inner();
return wrap("shiftAndFill", optOrPeriods, fillValue);
}
else {
fillValue = (0, exports.exprToLitOrExpr)(optOrPeriods.fillValue)._expr;
fillValue = (0, exports.exprToLitOrExpr)(optOrPeriods.fillValue).inner();
const periods = optOrPeriods.periods;
return wrap("shiftAndFill", { periods, fillValue });
return wrap("shiftAndFill", periods, fillValue);
}
},
skew: wrapUnaryWithDefault("skew", "bias", true),
skew(bias) {
return wrap("skew", bias?.bias ?? bias ?? true);
},
slice(arg, len) {
if (typeof arg === "number") {
return wrap("slice", { offset: (0, functions_1.lit)(arg)._expr, length: (0, functions_1.lit)(len)._expr });
return wrap("slice", polars_internal_1.default.lit(arg), polars_internal_1.default.lit(len));
}
return wrap("slice", { offset: (0, functions_1.lit)(arg.offset)._expr, length: (0, functions_1.lit)(arg.length)._expr });
return wrap("slice", polars_internal_1.default.lit(arg.offset), polars_internal_1.default.lit(arg.length));
},
sort(reverse = false, nullsLast = false) {
if (typeof reverse === "boolean") {
return wrap("sortWith", { reverse, nullsLast });
return wrap("sortWith", reverse, nullsLast);
}
return wrap("sortWith", reverse);
return wrap("sortWith", reverse?.reverse ?? false, reverse?.nullsLast ?? nullsLast);
},
std: wrapNullArgs("std"),
suffix: wrapUnary("suffix", "suffix"),
sum: wrapNullArgs("sum"),
tail: wrapUnaryNumber("tail", "length"),
sortBy(arg, reverse = false) {
if (arg?.by !== undefined) {
return this.sortBy(arg.by, arg.reverse);
}
reverse = Array.isArray(reverse) ? reverse.flat() : [reverse];
const by = (0, utils_1.selectionToExprList)(arg, false);
return wrap("sortBy", by, reverse);
},
std() {
return (0, exports._Expr)(_expr.std());
},
suffix(suffix) {
return (0, exports._Expr)(_expr.suffix(suffix));
},
sum() {
return (0, exports._Expr)(_expr.sum());
},
tail(length) {
return (0, exports._Expr)(_expr.tail(length));
},
take(indices) {
if (Array.isArray(indices)) {
indices = (0, functions_1.lit)((0, series_1.Series)(indices));
indices = polars_internal_1.default.lit((0, series_1.Series)(indices).inner());
}
return wrap("take", { other: indices._expr });
else {
indices = indices.inner();
}
return wrap("take", indices);
},
takeEvery: wrapUnary("takeEvery", "n"),
takeEvery(n) {
return (0, exports._Expr)(_expr.takeEvery(n));
},
unique(opt) {

@@ -302,5 +461,11 @@ if (opt) {

},
upperBound: wrapNullArgs("upperBound"),
where: wrapExprArg("filter"),
var: wrapNullArgs("var"),
upperBound() {
return (0, exports._Expr)(_expr.upperBound());
},
where(expr) {
return this.filter(expr);
},
var() {
return (0, exports._Expr)(_expr.var());
},
add: wrapExprArg("add"),

@@ -330,11 +495,20 @@ sub: wrapExprArg("sub"),

};
const isExpr = (anyVal) => (0, types_1.isExternal)(anyVal?._expr);
exports._Expr = _Expr;
const isExpr = (anyVal) => {
try {
return anyVal?.[Symbol.toStringTag]?.() === "Expr";
}
catch (err) {
return false;
}
};
const fromBinary = (buf) => {
return _Expr(polars_internal_1.default.expr.from_bincode(buf));
return null;
// return _Expr(pli.JsExpr.from_bincode(buf));
};
exports.Expr = Object.assign(_Expr, { isExpr, fromBinary });
exports.Expr = Object.assign(exports._Expr, { isExpr, fromBinary });
/** @ignore */
const exprToLitOrExpr = (expr, stringToLit = true) => {
if (typeof expr === "string" && !stringToLit) {
return (0, functions_1.col)(expr);
return (0, exports._Expr)(polars_internal_1.default.col(expr));
}

@@ -344,6 +518,9 @@ else if (exports.Expr.isExpr(expr)) {

}
else if (series_1.Series.isSeries(expr)) {
return (0, exports._Expr)(polars_internal_1.default.lit(expr._s));
}
else {
return (0, functions_1.lit)(expr);
return (0, exports._Expr)(polars_internal_1.default.lit(expr));
}
};
exports.exprToLitOrExpr = exprToLitOrExpr;
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ExprDateTimeFunctions = void 0;
const expr_1 = require("../expr");
const polars_internal_1 = __importDefault(require("../../internals/polars_internal"));
const ExprDateTimeFunctions = (_expr) => {
const wrap = (method, args) => {
return expr_1.Expr(polars_internal_1.default.expr.date[method]({ _expr, ...args }));
const wrap = (method, ...args) => {
return (0, expr_1._Expr)(_expr[method](...args));
};

@@ -22,3 +18,3 @@ const wrapNullArgs = (method) => () => wrap(method);

second: wrapNullArgs("second"),
strftime: (fmt) => wrap("strftime", { fmt }),
strftime: (fmt) => wrap("strftime", fmt),
timestamp: wrapNullArgs("timestamp"),

@@ -25,0 +21,0 @@ week: wrapNullArgs("week"),

import * as dt from "./datetime";
import * as lst from "./list";
import * as str from "./string";
import * as struct from "./struct";
declare namespace expr {

@@ -8,6 +9,8 @@ export import DateTimeFunctions = dt.ExprDateTimeFunctions;

export import StringFunctions = str.ExprStringFunctions;
export import StructFunctions = struct.ExprStructFunctions;
export import List = lst.ExprList;
export import Datetime = dt.ExprDateTime;
export import String = str.ExprString;
export import Struct = struct.ExprStruct;
}
export = expr;

@@ -24,2 +24,3 @@ "use strict";

const str = __importStar(require("./string"));
const struct = __importStar(require("./struct"));
var expr;

@@ -30,3 +31,4 @@ (function (expr) {

expr.StringFunctions = str.ExprStringFunctions;
expr.StructFunctions = struct.ExprStructFunctions;
})(expr || (expr = {}));
module.exports = expr;
import { Expr } from "../expr";
import { ListFunctions } from "../../shared_traits";
/**
* namespace containing expr list functions
*/
export interface ExprList {
/**
* Get the value by index in the sublists.
* So index `0` would return the first item of every sublist
* and index `-1` would return the last item of every sublist
* if an index is out of bounds, it will return a `null`.
*/
get(index: number): Expr;
/** Get the first value of the sublists. */
first(): Expr;
/**
* Join all string items in a sublist and place a separator between them.
* This errors if inner type of list `!= Utf8`.
* @param separator A string used to separate one element of the list from the next in the resulting string.
* If omitted, the list elements are separated with a comma.
*/
join(separator?: string): Expr;
/** Get the last value of the sublists. */
last(): Expr;
lengths(): Expr;
max(): Expr;
mean(): Expr;
min(): Expr;
reverse(): Expr;
sort(reverse?: boolean): Expr;
sort(opt: {
reverse: boolean;
}): Expr;
sum(): Expr;
unique(): Expr;
}
export declare type ExprList = ListFunctions<Expr>;
export declare const ExprListFunctions: (_expr: any) => ExprList;
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ExprListFunctions = void 0;
const expr_1 = require("../expr");
const polars_internal_1 = __importDefault(require("../../internals/polars_internal"));
const ExprListFunctions = (_expr) => {
const wrap = (method, args) => {
return expr_1.Expr(polars_internal_1.default.expr.lst[method]({ _expr, ...args }));
const wrap = (method, ...args) => {
return (0, expr_1._Expr)(_expr[method](...args));
};
return {
argMax() {
return wrap("lstArgMax");
},
argMin() {
return wrap("lstArgMin");
},
get(index) {
return wrap("get", { index });
return wrap("lstGet", index);
},
eval(expr, parallel) {
return wrap("lstEval", expr, parallel);
},
first() {
return wrap("get", { index: 0 });
return wrap("lstGet", 0);
},
join(separator = ",") {
return wrap("join", { separator });
return wrap("lstJoin", separator);
},
last() {
return wrap("get", { index: -1 });
return wrap("lstGet", -1);
},
lengths() {
return wrap("lengths");
return wrap("lstLengths");
},
max() {
return wrap("max");
return wrap("lstMax");
},
mean() {
return wrap("mean");
return wrap("lstMean");
},
min() {
return wrap("min");
return wrap("lstMin");
},
reverse() {
return wrap("reverse");
return wrap("lstReverse");
},
shift(n) {
return wrap("lstShift", n);
},
slice(offset, length) {
return wrap("lstSlice", offset, length);
},
sort(reverse = false) {
return typeof reverse === "boolean" ?
wrap("sort", { reverse }) :
wrap("sort", reverse);
wrap("lstSort", reverse) :
wrap("lstSort", reverse.reverse);
},
sum() {
return wrap("sum");
return wrap("lstSum");
},
unique() {
return wrap("unique");
return wrap("lstUnique");
},

@@ -52,0 +63,0 @@ };

@@ -176,5 +176,5 @@ import { DataType } from "../../datatypes";

*/
strftime(datatype: DataType.Date, fmt?: string): Expr;
strftime(datatype: DataType.Datetime, fmt?: string): Expr;
strptime(datatype: DataType.Date, fmt?: string): Expr;
strptime(datatype: DataType.Datetime, fmt?: string): Expr;
}
export declare const ExprStringFunctions: (_expr: any) => ExprString;
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ExprStringFunctions = void 0;
const datatypes_1 = require("../../datatypes");
const polars_internal_1 = __importDefault(require("../../internals/polars_internal"));
const utils_1 = require("../../utils");
const expr_1 = require("../expr");
const ExprStringFunctions = (_expr) => {
const wrap = (method, args) => {
return expr_1.Expr(polars_internal_1.default.expr.str[method]({ _expr, ...args }));
const wrap = (method, ...args) => {
return (0, expr_1._Expr)(_expr[method](...args));
};

@@ -18,5 +14,5 @@ const handleDecode = (encoding, strict) => {

case "hex":
return wrap(`decodeHex`, { strict });
return wrap(`strHexDecode`, strict);
case "base64":
return wrap(`decodeBase64`, { strict });
return wrap(`strBase64Decode`, strict);
default:

@@ -28,6 +24,6 @@ throw new RangeError("supported encodings are 'hex' and 'base64'");

concat(delimiter) {
return wrap("concat", { delimiter });
return wrap("strConcat", delimiter);
},
contains(pat) {
return wrap("contains", { pat: (0, utils_1.regexToString)(pat) });
return wrap("strContains", (0, utils_1.regexToString)(pat));
},

@@ -43,5 +39,5 @@ decode(arg, strict = false) {

case "hex":
return wrap(`encodeHex`);
return wrap(`strHexEncode`);
case "base64":
return wrap(`encodeBase64`);
return wrap(`strBase64Encode`);
default:

@@ -52,38 +48,38 @@ throw new RangeError("supported encodings are 'hex' and 'base64'");

extract(pat, groupIndex) {
return wrap("extract", { pat: (0, utils_1.regexToString)(pat), groupIndex });
return wrap("strExtract", (0, utils_1.regexToString)(pat), groupIndex);
},
jsonPathMatch(pat) {
return wrap("jsonPathMatch", { pat });
return wrap("strJsonPathMatch", pat);
},
lengths() {
return wrap("lengths");
return wrap("strLengths");
},
lstrip() {
return wrap("lstrip");
return wrap("strLstrip");
},
replace(pat, val) {
return wrap("replace", { pat: (0, utils_1.regexToString)(pat), val });
return wrap("strReplace", (0, utils_1.regexToString)(pat), val);
},
replaceAll(pat, val) {
return wrap("replaceAll", { pat: (0, utils_1.regexToString)(pat), val });
return wrap("strReplaceAll", (0, utils_1.regexToString)(pat), val);
},
rstrip() {
return wrap("rstrip");
return wrap("strRstrip");
},
slice(start, length) {
return wrap("slice", { start, length });
return wrap("strSlice", start, length);
},
split(by, options) {
const inclusive = typeof options === "boolean" ? options : options?.inclusive;
return wrap("split", { by, inclusive });
return wrap("strSplit", by, inclusive);
},
strip() {
return wrap("strip");
return wrap("strStrip");
},
strftime(dtype, fmt) {
strptime(dtype, fmt) {
if (dtype === datatypes_1.DataType.Date) {
return wrap("parseDate", { fmt });
return wrap("strParseDate", fmt, false, false);
}
else if (dtype === datatypes_1.DataType.Datetime) {
return wrap("parseDateTime", { fmt });
return wrap("strParseDatetime", fmt, false, false);
}

@@ -95,6 +91,6 @@ else {

toLowerCase() {
return wrap("toLowerCase");
return wrap("strToLowercase");
},
toUpperCase() {
return wrap("toUpperCase");
return wrap("strToUppercase");
},

@@ -101,0 +97,0 @@ };

@@ -98,3 +98,3 @@ import { Expr } from "./expr";

*/
export declare function col(col: string | string[] | Series<string>): Expr;
export declare function col(col: string | string[] | Series): Expr;
export declare function cols(col: string | string[]): Expr;

@@ -121,9 +121,9 @@ export declare function cols(col: string, ...cols: string[]): Expr;

export declare function arange<T>(opts: {
low: Series<T> | T;
high: Series<T> | T;
low: any;
high: any;
step: number;
eager: boolean;
}): any;
export declare function arange<T>(low: Series<T> | T, high?: Series<T> | T, step?: number, eager?: true): Series<T>;
export declare function arange<T>(low: Series<T> | T, high?: Series<T> | T, step?: number, eager?: false): Expr;
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;
/**

@@ -139,3 +139,3 @@ * __Find the indexes that would sort the columns.__

export declare function avg(column: string): Expr;
export declare function avg(column: Series<any>): number;
export declare function avg(column: Series): number;
/**

@@ -156,3 +156,3 @@ * Concat the arrays in a Series dtype List in linear time.

export declare function count(column: string): Expr;
export declare function count(column: Series<any>): number;
export declare function count(column: Series): number;
/** Compute the covariance between two columns/ expressions. */

@@ -172,3 +172,3 @@ export declare function cov(a: ExprOrString, b: ExprOrString): Expr;

export declare function first(column: string): Expr;
export declare function first<T>(column: Series<T>): T;
export declare function first<T>(column: Series): T;
/**

@@ -209,15 +209,14 @@ * String format utility for expressions

export declare function head(column: ExprOrString, n?: number): Expr;
export declare function head<T>(column: Series<T>, n?: number): Series<T>;
export declare function head(column: Series, n?: number): Series;
/** Get the last value. */
export declare function last(column: ExprOrString): Expr;
export declare function last<T>(column: Series<T>): T;
export declare function last(column: ExprOrString | Series): any;
/** Get the mean value. */
export declare function mean(column: ExprOrString): Expr;
export declare function mean(column: Series<any>): number;
export declare function mean(column: Series): number;
/** Get the median value. */
export declare function median(column: ExprOrString): Expr;
export declare function median(column: Series<any>): number;
export declare function median(column: Series): number;
/** Count unique values. */
export declare function nUnique(column: ExprOrString): Expr;
export declare function nUnique(column: Series<any>): number;
export declare function nUnique(column: Series): number;
/** Compute the pearson's correlation between two columns. */

@@ -227,3 +226,3 @@ export declare function pearsonCorr(a: ExprOrString, b: ExprOrString): Expr;

export declare function quantile(column: ExprOrString, q: number): Expr;
export declare function quantile(column: Series<any>, q: number): number;
export declare function quantile(column: Series, q: number): number;
/**

@@ -239,4 +238,4 @@ * __Run polars expressions without a context.__

export declare function tail(column: ExprOrString, n?: number): Expr;
export declare function tail<T>(column: Series<T>, n?: number): Series<T>;
export declare function tail(column: Series, n?: number): Series;
/** Syntactic sugar for `pl.col(column).list()` */
export declare function list(column: ExprOrString): Expr;

@@ -110,6 +110,6 @@ "use strict";

if (Array.isArray(col)) {
return expr_1.Expr(polars_internal_1.default.cols({ name: col }));
return (0, expr_1._Expr)(polars_internal_1.default.cols(col));
}
else {
return expr_1.Expr(polars_internal_1.default.col({ name: col }));
return (0, expr_1._Expr)(polars_internal_1.default.col(col));
}

@@ -127,5 +127,5 @@ }

if (series_1.Series.isSeries(value)) {
return expr_1.Expr(polars_internal_1.default.lit({ value: value._series }));
return (0, expr_1._Expr)(polars_internal_1.default.lit(value.inner()));
}
return expr_1.Expr(polars_internal_1.default.lit({ value }));
return (0, expr_1._Expr)(polars_internal_1.default.lit(value));
}

@@ -144,3 +144,3 @@ exports.lit = lit;

}
return expr_1.Expr(polars_internal_1.default.arange({ low: low._expr, high: high._expr, step }));
return (0, expr_1._Expr)(polars_internal_1.default.arange(low, high, step));
}

@@ -161,3 +161,3 @@ }

const by = (0, utils_1.selectionToExprList)(exprs);
return expr_1.Expr(polars_internal_1.default.argSortBy({ by, reverse }));
return (0, expr_1._Expr)(polars_internal_1.default.argsortBy(by, reverse));
}

@@ -171,3 +171,3 @@ exports.argSortBy = argSortBy;

const items = (0, utils_1.selectionToExprList)(exprs, false);
return expr_1.Expr(polars_internal_1.default.concatList({ items }));
return expr_1.Expr(polars_internal_1.default.concatLst(items));
}

@@ -180,3 +180,3 @@ exports.concatList = concatList;

const items = (0, utils_1.selectionToExprList)(opts, false);
return expr_1.Expr(polars_internal_1.default.concatString({ items, sep }));
return expr_1.Expr(polars_internal_1.default.concatStr(items, sep));
}

@@ -195,5 +195,5 @@ exports.concatString = concatString;

function cov(a, b) {
a = (0, expr_1.exprToLitOrExpr)(a, false)._expr;
b = (0, expr_1.exprToLitOrExpr)(b, false)._expr;
return expr_1.Expr(polars_internal_1.default.cov({ a, b }));
a = (0, expr_1.exprToLitOrExpr)(a, false);
b = (0, expr_1.exprToLitOrExpr)(b, false);
return (0, expr_1._Expr)(polars_internal_1.default.cov(a, b));
}

@@ -208,3 +208,3 @@ exports.cov = cov;

if (column.length) {
return column[0];
return column.get(0);
}

@@ -282,6 +282,7 @@ else {

exports.head = head;
/** Get the last value. */
function last(column) {
if (series_1.Series.isSeries(column)) {
if (column.length) {
return column[-1];
return column.get(-1);
}

@@ -320,5 +321,5 @@ else {

function pearsonCorr(a, b) {
a = (0, expr_1.exprToLitOrExpr)(a, false)._expr;
b = (0, expr_1.exprToLitOrExpr)(b, false)._expr;
return expr_1.Expr(polars_internal_1.default.pearsonCorr({ a, b }));
a = (0, expr_1.exprToLitOrExpr)(a, false);
b = (0, expr_1.exprToLitOrExpr)(b, false);
return (0, expr_1._Expr)(polars_internal_1.default.pearsonCorr(a, b));
}

@@ -344,5 +345,5 @@ exports.pearsonCorr = pearsonCorr;

function spearmanRankCorr(a, b) {
a = (0, expr_1.exprToLitOrExpr)(a, false)._expr;
b = (0, expr_1.exprToLitOrExpr)(b, false)._expr;
return expr_1.Expr(polars_internal_1.default.spearmanRankCorr({ a, b }));
a = (0, expr_1.exprToLitOrExpr)(a, false);
b = (0, expr_1.exprToLitOrExpr)(b, false);
return (0, expr_1._Expr)(polars_internal_1.default.spearmanRankCorr(a, b));
}

@@ -364,11 +365,11 @@ exports.spearmanRankCorr = spearmanRankCorr;

exports.list = list;
// export function collect_all() {}
// export function all() {} // fold
// export function any() {} // fold
// export function apply() {} // lambda
// export function fold() {}
// export function map_binary() {} //lambda
// export function map() {} //lambda
// export function max() {} // fold
// export function min() {} // fold
// export function sum() {} // fold
// // export function collect_all() {}
// // export function all() {} // fold
// // export function any() {} // fold
// // export function apply() {} // lambda
// // export function fold() {}
// // export function map_binary() {} //lambda
// // export function map() {} //lambda
// // export function max() {} // fold
// // export function min() {} // fold
// // export function sum() {} // fold

@@ -8,2 +8,2 @@ import { Expr } from "./expr";

}
export declare const LazyGroupBy: (_ldf: any, by: any[], maintainOrder: boolean) => LazyGroupBy;
export declare const LazyGroupBy: (_lgb: any) => LazyGroupBy;
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.LazyGroupBy = void 0;
const utils_1 = require("../utils");
const polars_internal_1 = __importDefault(require("../internals/polars_internal"));
const dataframe_1 = require("./dataframe");
const LazyGroupBy = (_ldf, by, maintainOrder) => {
by = (0, utils_1.selectionToExprList)(by, false);
const baseArgs = { by, _ldf, maintainOrder };
const unwrap = (args) => (0, dataframe_1.LazyDataFrame)(polars_internal_1.default.ldf.groupby(args));
const LazyGroupBy = (_lgb) => {
return {
agg(...aggs) {
return unwrap({
aggs: aggs.flatMap(a => a._expr),
aggMethod: "agg",
...baseArgs
});
const agg = (0, utils_1.selectionToExprList)(aggs.flat(), false);
return (0, dataframe_1._LazyDataFrame)(_lgb.agg(agg));
},
head(n = 5) {
return unwrap({
n,
aggs: [],
aggMethod: "head",
...baseArgs
});
return (0, dataframe_1._LazyDataFrame)(_lgb.head(n));
},
tail(n = 5) {
return unwrap({
n,
aggs: [],
aggMethod: "tail",
...baseArgs
});
return (0, dataframe_1._LazyDataFrame)(_lgb.tail(n));
}

@@ -38,0 +18,0 @@ };

@@ -9,13 +9,13 @@ "use strict";

const polars_internal_1 = __importDefault(require("../internals/polars_internal"));
function WhenThenThen(_when) {
function WhenThenThen(_whenthenthen) {
return {
when: ({ _expr }) => WhenThenThen(polars_internal_1.default._whenthenthen.when({ _when, _expr })),
then: ({ _expr }) => WhenThenThen(polars_internal_1.default._whenthenthen.then({ _when, _expr })),
otherwise: ({ _expr }) => expr_1.Expr(polars_internal_1.default._whenthenthen.otherwise({ _when, _expr }))
when: ({ _expr }) => WhenThenThen(_whenthenthen.when(_expr)),
then: ({ _expr }) => WhenThenThen(_whenthenthen.then(_expr)),
otherwise: ({ _expr }) => expr_1.Expr(_whenthenthen.otherwise(_expr))
};
}
function WhenThen(_when) {
function WhenThen(_whenthen) {
return {
when: ({ _expr }) => WhenThenThen(polars_internal_1.default._whenthen.when({ _when, _expr })),
otherwise: ({ _expr }) => expr_1.Expr(polars_internal_1.default._whenthen.otherwise({ _when, _expr }))
when: ({ _expr }) => WhenThenThen(_whenthen.when(_expr)),
otherwise: ({ _expr }) => expr_1.Expr(_whenthen.otherwise(_expr))
};

@@ -29,3 +29,3 @@ }

return {
then: ({ _expr }) => WhenThen(polars_internal_1.default._when.then({ _when, _expr }))
then: ({ _expr }) => WhenThen(_when.then(_expr))
};

@@ -77,4 +77,4 @@ }

function when(expr) {
return When(polars_internal_1.default.when(expr));
return When(polars_internal_1.default.when(expr._expr));
}
exports.when = when;

@@ -1,95 +0,4 @@

import { JsSeries, Series } from "./series";
export interface DateTimeFunctions {
/**
* Extract day from underlying Date representation.
* Can be performed on Date and Datetime.
*
* Returns the day of month starting from 1.
* The return value ranges from 1 to 31. (The last day of month differs by months.)
* @returns day as pl.UInt32
*/
day(): Series<number>;
/**
* Extract hour from underlying DateTime representation.
* Can be performed on Datetime.
*
* Returns the hour number from 0 to 23.
* @returns Hour as UInt32
*/
hour(): Series<number>;
/**
* Extract minutes from underlying DateTime representation.
* Can be performed on Datetime.
*
* Returns the minute number from 0 to 59.
* @returns minute as UInt32
*/
minute(): Series<number>;
/**
* Extract month from underlying Date representation.
* Can be performed on Date and Datetime.
*
* Returns the month number starting from 1.
* The return value ranges from 1 to 12.
* @returns Month as UInt32
*/
month(): Series<number>;
/**
* Extract seconds from underlying DateTime representation.
* Can be performed on Datetime.
*
* Returns the number of nanoseconds since the whole non-leap second.
* The range from 1,000,000,000 to 1,999,999,999 represents the leap second.
* @returns Nanosecond as UInt32
*/
nanosecond(): Series<number>;
/**
* Extract ordinal day from underlying Date representation.
* Can be performed on Date and Datetime.
*
* Returns the day of year starting from 1.
* The return value ranges from 1 to 366. (The last day of year differs by years.)
* @returns Day as UInt32
*/
ordinalDay(): Series<number>;
/**
* Extract seconds from underlying DateTime representation.
* Can be performed on Datetime.
*
* Returns the second number from 0 to 59.
* @returns Second as UInt32
*/
second(): Series<number>;
/**
* Format Date/datetime with a formatting rule: See [chrono strftime/strptime](https://docs.rs/chrono/0.4.19/chrono/format/strftime/index.html).
*/
strftime(fmt: string): Series<string>;
/** Return timestamp in ms as Int64 type. */
timestamp(): Series<number>;
/**
* Extract the week from the underlying Date representation.
* Can be performed on Date and Datetime
*
* Returns the ISO week number starting from 1.
* The return value ranges from 1 to 53. (The last week of year differs by years.)
* @returns Week number as UInt32
*/
week(): Series<number>;
/**
* Extract the week day from the underlying Date representation.
* Can be performed on Date and Datetime.
*
* Returns the weekday number where monday = 0 and sunday = 6
* @returns Week day as UInt32
*/
weekday(): Series<number>;
/**
* Extract year from underlying Date representation.
* Can be performed on Date and Datetime.
*
* Returns the year number in the calendar date.
* @returns Year as Int32
*/
year(): Series<number>;
}
export declare const DateTimeFunctions: (_s: JsSeries) => DateTimeFunctions;
import { Series } from "./series";
import { DateFunctions } from "../shared_traits";
export declare type SeriesDateFunctions = DateFunctions<Series>;
export declare const SeriesDateFunctions: (_s: any) => SeriesDateFunctions;
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.DateTimeFunctions = void 0;
const polars_internal_1 = __importDefault(require("../internals/polars_internal"));
exports.SeriesDateFunctions = void 0;
const series_1 = require("./series");
const DateTimeFunctions = (_s) => {
const wrap = (method, args, _series = _s) => {
return (0, series_1.seriesWrapper)(polars_internal_1.default.series.date[method]({ _series, ...args }));
const SeriesDateFunctions = (_s) => {
const wrap = (method, ...args) => {
return (0, series_1._Series)(_s[method](...args));
};

@@ -22,3 +18,3 @@ const wrapNullArgs = (method) => () => wrap(method);

second: wrapNullArgs("second"),
strftime: (fmt) => wrap("strftime", { fmt }),
strftime: (fmt) => wrap("strftime", fmt),
timestamp: wrapNullArgs("timestamp"),

@@ -30,2 +26,2 @@ week: wrapNullArgs("week"),

};
exports.DateTimeFunctions = DateTimeFunctions;
exports.SeriesDateFunctions = SeriesDateFunctions;

@@ -1,33 +0,4 @@

import { JsSeries, Series } from "./series";
export interface ListFunctions<T> {
get(index: number): Series<T>;
first(): Series<T>;
/**
* Join all string items in a sublist and place a separator between them.
* This errors if inner type of list `!= Utf8`.
* @param separator A string used to separate one element of the list from the next in the resulting string.
* If omitted, the list elements are separated with a comma.
*/
join(separator?: string): Series<string>;
last(): Series<T>;
/** Get the length of the arrays as UInt32. */
lengths(): Series<number>;
/** Compute the max value of the arrays in the list */
max(): Series<number>;
/** Compute the mean value of the arrays in the list */
mean(): Series<number>;
/** Compute the min value of the arrays in the list */
min(): Series<number>;
/** Reverse the arrays in the list */
reverse(): Series<Series<T>>;
/** Sort the arrays in the list */
sort(reverse?: boolean): Series<Series<T>>;
sort(opt: {
reverse: boolean;
}): Series<Series<T>>;
/** Sum all the arrays in the list */
sum(): Series<number>;
/** Get the unique/distinct values in the list */
unique(): Series<Series<T>>;
}
export declare const ListFunctions: <T>(_s: JsSeries) => ListFunctions<T>;
import { Series } from "./series";
import { ListFunctions } from "../shared_traits";
export declare type SeriesListFunctions = ListFunctions<Series>;
export declare const SeriesListFunctions: (_s: any) => ListFunctions<Series>;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ListFunctions = void 0;
exports.SeriesListFunctions = void 0;
const series_1 = require("./series");
const functions_1 = require("../lazy/functions");
const ListFunctions = (_s) => {
const callExpr = (method) => (...args) => {
const s = (0, series_1.seriesWrapper)(_s);
const SeriesListFunctions = (_s) => {
const wrap = (method, ...args) => {
const s = (0, series_1._Series)(_s);
return s
.toFrame()
.select((0, functions_1.col)(s.name)
.lst[method](...args)
.select((0, functions_1.col)(s.name).lst[method](...args)
.as(s.name))

@@ -17,16 +16,57 @@ .getColumn(s.name);

return {
get: callExpr("get"),
first: callExpr("first"),
join: callExpr("join"),
last: callExpr("last"),
lengths: callExpr("lengths"),
max: callExpr("max"),
mean: callExpr("mean"),
min: callExpr("min"),
reverse: callExpr("reverse"),
sort: callExpr("sort"),
sum: callExpr("sum"),
unique: callExpr("unique")
argMax() {
return wrap("argMax");
},
argMin() {
return wrap("argMin");
},
get(index) {
return wrap("get", index);
},
eval(expr, parallel) {
return wrap("eval", expr, parallel);
},
first() {
return wrap("get", 0);
},
join(separator = ",") {
return wrap("join", separator);
},
last() {
return wrap("get", -1);
},
lengths() {
return wrap("lengths");
},
max() {
return wrap("max");
},
mean() {
return wrap("mean");
},
min() {
return wrap("min");
},
reverse() {
return wrap("reverse");
},
shift(n) {
return wrap("shift", n);
},
slice(offset, length) {
return wrap("slice", offset, length);
},
sort(reverse = false) {
return typeof reverse === "boolean" ?
wrap("sort", reverse) :
wrap("sort", reverse.reverse);
},
sum() {
return wrap("sum");
},
unique() {
return wrap("unique");
},
};
};
exports.ListFunctions = ListFunctions;
exports.SeriesListFunctions = SeriesListFunctions;
/// <reference types="node" />
import { DataType, DtypeToPrimitive, Optional } from "../datatypes";
import { DataType, Optional } from "../datatypes";
import { DataFrame } from "../dataframe";
import { StringFunctions } from "./string";
import { ListFunctions } from "./list";
import { DateTimeFunctions } from "./datetime";
import { SeriesListFunctions } from "./list";
import { SeriesDateFunctions } from "./datetime";
import { SeriesStructFunctions } from "./struct";
import { RankMethod } from "../utils";
import { Arithmetic, Comparison, Cumulative, Rolling, Round, Sample } from "../shared_traits";
declare const inspect: unique symbol;
declare type ValueOrNever<V> = V extends ArrayLike<infer U> ? Series<U> : never;
declare type DataTypeOrValue<T, U> = U extends true ? DtypeToPrimitive<T> : DtypeToPrimitive<T> | null;
declare type ArrayLikeDataType<T> = ArrayLike<DtypeToPrimitive<T>>;
declare type ArrayLikeOrDataType<T, U> = ArrayLike<DataTypeOrValue<T, U>>;
/** @ignore */
export declare type JsSeries = any;
export interface Series<T> extends ArrayLike<T>, Rolling<Series<T>>, Arithmetic<Series<T>>, Comparison<Series<boolean>>, Cumulative<Series<T>>, Round<Series<T>>, Sample<Series<T>> {
/** @ignore */
_series: JsSeries;
export interface Series extends ArrayLike<any>, Rolling<Series>, Arithmetic<Series>, Comparison<Series>, Cumulative<Series>, Round<Series>, Sample<Series> {
inner(): any;
name: string;
dtype: DataType;
str: StringFunctions;
lst: ListFunctions<T>;
date: DateTimeFunctions;
lst: SeriesListFunctions;
struct: SeriesStructFunctions;
date: SeriesDateFunctions;
[inspect](): string;
[Symbol.iterator](): IterableIterator<T>;
inner(): JsSeries;
bitand(other: Series<any>): Series<T>;
bitor(other: Series<any>): Series<T>;
bitxor(other: Series<any>): Series<T>;
[Symbol.iterator](): IterableIterator<any>;
bitand(other: Series): Series;
bitor(other: Series): Series;
bitxor(other: Series): Series;
/**
* Take absolute values
*/
abs(): Series<T>;
abs(): Series;
/**

@@ -41,3 +35,3 @@ * __Rename this Series.__

*/
alias(name: string): Series<T>;
alias(name: string): Series;
/**

@@ -62,3 +56,3 @@ * __Append a Series to this one.__

*/
append(other: Series<T>): void;
append(other: Series): void;
/**

@@ -76,7 +70,7 @@ * Get the index of the maximal value.

*/
argTrue(): Series<number>;
argTrue(): Series;
/**
* Get unique index as Series.
*/
argUnique(): Series<number>;
argUnique(): Series;
/**

@@ -88,7 +82,7 @@ * Index location of the sorted variant of this Series.

*/
argSort(): Series<T>;
argSort(reverse: boolean): Series<T>;
argSort(): Series;
argSort(reverse: boolean): Series;
argSort({ reverse }: {
reverse: boolean;
}): Series<T>;
}): Series;
/**

@@ -101,20 +95,16 @@ * __Rename this Series.__

*/
as(name: string): Series<T>;
as(name: string): Series;
/**
* Cast between data types.
*/
cast<D extends DataType>(dtype: D): Series<DtypeToPrimitive<D>>;
cast<D extends DataType>(dtype: D, strict: boolean): Series<DtypeToPrimitive<D>>;
cast<D extends DataType>(dtype: D, opt: {
strict: boolean;
}): Series<DtypeToPrimitive<D>>;
cast(dtype: DataType, strict?: boolean): Series;
/**
* Get the length of each individual chunk
*/
chunkLengths(): Array<number>;
chunkLengths(): Array<any>;
/**
* Cheap deep clones.
*/
clone(): Series<T>;
concat(other: Series<T>): Series<T>;
clone(): Series;
concat(other: Series): Series;
/**

@@ -172,7 +162,7 @@ * __Quick summary statistics of a series. __

*/
diff(n: number, nullBehavior: "ignore" | "drop"): Series<T>;
diff(n: number, nullBehavior: "ignore" | "drop"): Series;
diff({ n, nullBehavior }: {
n: number;
nullBehavior: "ignore" | "drop";
}): Series<T>;
}): Series;
/**

@@ -189,7 +179,7 @@ * Compute the dot/inner product between two Series

*/
dot(other: Series<any>): Optional<number>;
dot(other: Series): number | undefined | null;
/**
* Create a new Series that copies data from this Series without null values.
*/
dropNulls(): Series<T>;
dropNulls(): Series;
/**

@@ -224,7 +214,3 @@ * __Explode a list or utf8 Series.__

*/
extend(value: any, n: number): Series<T>;
extend(opt: {
value: any;
n: number;
}): Series<T>;
extend(value: any, n: number): Series;
/**

@@ -235,7 +221,3 @@ * Extend the Series with given number of values.

*/
extendConstant(value: any, n: number): Series<T>;
extendConstant(opt: {
value: any;
n: number;
}): Series<T>;
extendConstant(value: any, n: number): Series;
/**

@@ -268,6 +250,6 @@ * __Fill null values with a filling strategy.__

*/
fillNull(strategy: "backward" | "forward" | "min" | "max" | "mean" | "one" | "zero"): Series<T>;
fillNull(strategy: "backward" | "forward" | "min" | "max" | "mean" | "one" | "zero"): Series;
fillNull({ strategy }: {
strategy: "backward" | "forward" | "min" | "max" | "mean" | "one" | "zero";
}): Series<T>;
}): Series;
/**

@@ -278,8 +260,8 @@ * __Filter elements by a boolean mask.__

*/
filter(predicate: Series<boolean>): Series<T>;
filter(predicate: Series): Series;
filter({ predicate }: {
predicate: Series<boolean>;
}): Series<T>;
get(index: number): T;
getIndex(n: number): T;
predicate: Series;
}): Series;
get(index: number): any;
getIndex(n: number): any;
/**

@@ -311,9 +293,9 @@ * Returns True if the Series has a validity bitmask.

*/
hash(k0?: number, k1?: number, k2?: number, k3?: number): Series<bigint>;
hash(k0?: number | bigint, k1?: number | bigint, k2?: number | bigint, k3?: number | bigint): Series;
hash({ k0, k1, k2, k3 }: {
k0?: number;
k1?: number;
k2?: number;
k3?: number;
}): Series<bigint>;
k0?: number | bigint;
k1?: number | bigint;
k2?: number | bigint;
k3?: number | bigint;
}): Series;
/**

@@ -335,3 +317,3 @@ * __Get first N elements as Series.__

*/
head(length?: number): Series<T>;
head(length?: number): Series;
/**

@@ -357,3 +339,3 @@ * __Interpolate intermediate values.__

*/
interpolate(): Series<T>;
interpolate(): Series;
/**

@@ -385,11 +367,11 @@ * Check if this Series is a Boolean.

*/
isDuplicated(): Series<boolean>;
isDuplicated(): Series;
/**
* Get mask of finite values if Series dtype is Float.
*/
isFinite(): T extends number ? Series<boolean> : never;
isFinite(): Series;
/**
* Get a mask of the first unique value.
*/
isFirst(): Series<boolean>;
isFirst(): Series;
/**

@@ -402,3 +384,3 @@ * Check if this Series is a Float.

*/
isIn<U>(other: Series<U> | U[]): Series<boolean>;
isIn<U>(other: Series | U[]): Series;
/**

@@ -420,3 +402,3 @@ * __Get mask of infinite values if Series dtype is Float.__

*/
isInfinite(): T extends number ? Series<boolean> : never;
isInfinite(): Series;
/**

@@ -442,3 +424,3 @@ * __Get mask of non null values.__

*/
isNotNull(): Series<boolean>;
isNotNull(): Series;
/**

@@ -464,3 +446,3 @@ * __Get mask of null values.__

*/
isNull(): Series<boolean>;
isNull(): Series;
/**

@@ -487,3 +469,3 @@ * Check if this Series datatype is numeric.

*/
isUnique(): Series<boolean>;
isUnique(): Series;
/**

@@ -540,3 +522,3 @@ * Checks if this Series datatype is a Utf8.

*/
limit(n?: number): Series<T>;
limit(n?: number): Series;
/**

@@ -605,3 +587,3 @@ * Get the maximum value in this Series.

*/
mode(): Series<T>;
mode(): Series;
/**

@@ -646,3 +628,3 @@ * Get the number of chunks that this Series contains.

*/
peakMax(): Series<boolean>;
peakMax(): Series;
/**

@@ -666,3 +648,3 @@ * Get a boolean mask of the local minimum peaks.

*/
peakMin(): Series<boolean>;
peakMin(): Series;
/**

@@ -679,3 +661,3 @@ * Get the quantile value of this Series.

*/
quantile(quantile: number): number;
quantile(quantile: number, interpolation?: string): number;
/**

@@ -702,11 +684,6 @@ * Assign ranks to data, dealing with ties appropriately.

*/
rank(method?: RankMethod): Series<number>;
rechunk(): Series<T>;
rechunk(inPlace: boolean): void;
rechunk({ inPlace }: {
inPlace: true;
}): void;
rechunk({ inPlace }: {
inPlace: false;
}): Series<T>;
rank(method?: RankMethod): Series;
rechunk(): Series;
rechunk(inPlace: true): Series;
rechunk(inPlace: false): void;
/**

@@ -725,3 +702,3 @@ * __Reinterpret the underlying bits as a signed/unsigned integer.__

*/
reinterpret(signed?: boolean): T extends bigint ? Series<number> : T extends number ? Series<bigint> : never;
reinterpret(signed?: boolean): Series;
/**

@@ -746,3 +723,3 @@ * __Rename this Series.__

*/
rename(name: string): Series<T>;
rename(name: string): Series;
rename(name: string, inPlace: boolean): void;

@@ -772,6 +749,3 @@ rename({ name, inPlace }: {

*/
seriesEqual<U>(other: Series<U>, nullEqual?: boolean): boolean;
seriesEqual<U>(other: Series<U>, opt: {
nullEqual?: boolean;
}): boolean;
seriesEqual<U>(other: Series, nullEqual?: boolean, strict?: boolean): boolean;
/**

@@ -782,4 +756,4 @@ * __Set masked values__

*/
set(filter: Series<boolean>, value: T): Series<T>;
setAtIdx(indices: number[] | Series<number>, value: T): Series<T>;
set(filter: Series, value: any): Series;
setAtIdx(indices: number[] | Series, value: any): Series;
/**

@@ -812,6 +786,3 @@ * __Shift the values by a given period__

*/
shift(periods: number): Series<T>;
shift(opts: {
periods?: number;
}): Series<T>;
shift(periods: number): Series;
/**

@@ -825,7 +796,7 @@ * Shift the values by a given period

*/
shiftAndFill(periods: number, fillValue: any): Series<T>;
shiftAndFill(opt: {
shiftAndFill(periods: number, fillValue: any): Series;
shiftAndFill(args: {
periods: number;
fillValue: any;
}): Series<T>;
}): Series;
/**

@@ -835,7 +806,4 @@ * __Shrink memory usage of this Series to fit the exact capacity needed to hold the data.__

*/
shrinkToFit(): Series<T>;
shrinkToFit(): Series;
shrinkToFit(inPlace: true): void;
shrinkToFit({ inPlace }: {
inPlace: true;
}): void;
/**

@@ -853,5 +821,2 @@ * __Compute the sample skewness of a data set.__

skew(bias?: boolean): number | undefined;
skew(opt: {
bias?: boolean;
}): number | undefined;
/**

@@ -863,7 +828,3 @@ * Create subslices of the Series.

*/
slice(opt: {
offset: number;
length: number;
}): Series<T>;
slice(start: number, length?: number): Series<T>;
slice(start: number, length?: number): Series;
/**

@@ -895,7 +856,7 @@ * __Sort this Series.__

*/
sort(): Series<T>;
sort(reverse?: boolean): Series<T>;
sort(): Series;
sort(reverse?: boolean): Series;
sort(options: {
reverse: boolean;
}): Series<T>;
}): Series;
/**

@@ -929,3 +890,3 @@ * Reduce this Series to the sum value.

*/
tail(length?: number): Series<T>;
tail(length?: number): Series;
/**

@@ -946,3 +907,3 @@ * Take every nth value in the Series and return as new Series.

*/
takeEvery(n: number): Series<T>;
takeEvery(n: number): Series;
/**

@@ -964,3 +925,3 @@ * Take values by index.

*/
take(indices: Array<number>): Series<T>;
take(indices: Array<number>): Series;
/**

@@ -985,3 +946,3 @@ * __Get unique elements in series.__

maintainOrder: boolean;
}): Series<T>;
}): Series;
/**

@@ -1018,3 +979,3 @@ * __Count the unique values in a Series.__

*/
zipWith<U>(mask: Series<boolean>, other: Series<T>): Series<U>;
zipWith(mask: Series, other: Series): Series;
/**

@@ -1035,4 +996,11 @@ * __Convert this Series to a Javascript Array.__

*/
toArray(): Array<T>;
toArray(): Array<any>;
/**
* Converts series to a javascript typedArray.
*
* __Warning:__
* This will throw an error if you have nulls, or are using non numeric data types
*/
toTypedArray(): any;
/**
* _Returns a Javascript object representation of Series_

@@ -1065,11 +1033,14 @@ * Often this is much faster than the iterator, or `values` method

/** Returns an iterator over the values */
values(): IterableIterator<T>;
values(): IterableIterator<any>;
}
/** @ignore */
export declare const seriesWrapper: <T>(_s: JsSeries) => Series<T>;
export interface RollingOptions {
windowSize: number;
weights?: Array<number>;
minPeriods: number;
center: boolean;
}
export declare function _Series(_s: any): Series;
export interface SeriesConstructor {
<V extends ArrayLike<any>>(values: V): ValueOrNever<V>;
<V extends ArrayLike<any>>(name: string, values: V): ValueOrNever<V>;
<T extends DataType, U extends ArrayLikeDataType<T>>(name: string, values: U, dtype: T): Series<DtypeToPrimitive<T>>;
<T extends DataType, U extends boolean, V extends ArrayLikeOrDataType<T, U>>(name: string, values: V, dtype?: T, strict?: U): Series<DataTypeOrValue<T, U>>;
(values: any): Series;
(name: string, values: any[], dtype?: any): Series;
/**

@@ -1079,15 +1050,12 @@ * Creates an array from an array-like object.

*/
from<T>(arrayLike: ArrayLike<T>): Series<T>;
from<T>(arrayLike: ArrayLike<T>): Series;
from<T>(name: string, arrayLike: ArrayLike<T>): Series;
/**
* Returns a new Series from a set of elements.
* @param items — A set of elements to include in the new series object.
*/
of<T>(...items: T[]): Series<T>;
isSeries(arg: any): arg is Series<any>;
/**
* @param binary used to serialize/deserialize series. This will only work with the output from series.toBinary().
* Returns a new Series from a set of elements.
* @param items — A set of elements to include in the new Series object.
*/
fromBinary(binary: Buffer): Series<unknown>;
of<T>(...items: T[]): Series;
isSeries(arg: any): arg is Series;
}
export declare const Series: SeriesConstructor;
export {};

@@ -6,3 +6,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.Series = exports.seriesWrapper = void 0;
exports.Series = exports._Series = void 0;
const polars_internal_1 = __importDefault(require("../internals/polars_internal"));

@@ -15,39 +15,26 @@ const construction_1 = require("../internals/construction");

const datetime_1 = require("./datetime");
const struct_1 = require("./struct");
const error_1 = require("../error");
const functions_1 = require("../lazy/functions");
const types_1 = require("util/types");
const inspect = Symbol.for("nodejs.util.inspect.custom");
/** @ignore */
const seriesWrapper = (_s) => {
const unwrap = (method, args, _series = _s) => {
return polars_internal_1.default.series[method]({ _series, ...args });
function _Series(_s) {
const unwrap = (method, ...args) => {
return _s[method](...args);
};
const wrap = (method, args, _series = _s) => {
return (0, exports.seriesWrapper)(unwrap(method, args, _series));
const wrap = (method, ...args) => {
return _Series(unwrap(method, ...args));
};
const noArgWrap = (method) => () => wrap(method);
const noArgUnwrap = (method) => () => unwrap(method);
const dtypeAccessor = (fn) => (method, args, _series = _s) => {
const dtype = unwrap("dtype");
if (args.field?._series) {
return fn(method, { [args.key]: args.field._series }, _series);
}
else {
const dt = datatypes_1.DTYPE_TO_FFINAME[datatypes_1.DataType[dtype]];
const internalMethod = `${method}_${dt}`;
if (datatypes_1.DataType[dtype] === datatypes_1.DataType.List) {
return (0, exports.seriesWrapper)(fn(internalMethod, { [args.key]: args.field }, _series));
}
return fn(internalMethod, { [args.key]: args.field }, _series);
}
const dtypeWrap = (method, ...args) => {
const dtype = _s.dtype;
const dt = datatypes_1.DTYPE_TO_FFINAME[dtype];
const internalMethod = `series${method}${dt}`;
return _Series(polars_internal_1.default[internalMethod](_s, ...args));
};
const inPlaceOptional = (method) => (obj) => {
if (obj === true || obj?.["inPlace"] === true) {
unwrap(method, { inPlace: true });
}
else {
return wrap(method);
}
const dtypeUnwrap = (method, ...args) => {
const dtype = _s.dtype;
const dt = datatypes_1.DTYPE_TO_FFINAME[dtype];
const internalMethod = `series${method}${dt}`;
return polars_internal_1.default[internalMethod](_s, ...args);
};
const rolling = (method) => (opts, weights, minPeriods, center) => {
const rolling = (method, opts, weights, minPeriods, center) => {
const windowSize = opts?.["windowSize"] ?? (typeof opts === "number" ? opts : null);

@@ -58,19 +45,19 @@ if (windowSize === null) {

const callOpts = {
window_size: opts?.["windowSize"] ?? (typeof opts === "number" ? opts : null),
windowSize: opts?.["windowSize"] ?? (typeof opts === "number" ? opts : null),
weights: opts?.["weights"] ?? weights,
min_periods: opts?.["minPeriods"] ?? minPeriods ?? windowSize,
minPeriods: opts?.["minPeriods"] ?? minPeriods ?? windowSize,
center: opts?.["center"] ?? center ?? false,
};
return wrap(method, callOpts);
return _Series(_s[method](callOpts));
};
const seriesObject = {
_series: _s,
const series = {
_s,
[inspect]() {
return unwrap("get_fmt");
return _s.toString();
},
*[Symbol.iterator]() {
let start = 0;
let len = unwrap("len");
let len = _s.len();
while (start < len) {
const v = this.get(start);
const v = _s.getIdx(start);
start++;

@@ -81,15 +68,15 @@ yield v;

toString() {
return unwrap("get_fmt");
return _s.toString();
},
get [Symbol.toStringTag]() {
[Symbol.toStringTag]() {
return "Series";
},
get dtype() {
return unwrap("dtype");
return _s.dtype;
},
get name() {
return unwrap("name");
return _s.name;
},
get length() {
return unwrap("len");
return _s.len();
},

@@ -100,28 +87,42 @@ get str() {

get lst() {
return (0, list_1.ListFunctions)(_s);
return (0, list_1.SeriesListFunctions)(_s);
},
get date() {
return (0, datetime_1.DateTimeFunctions)(_s);
return (0, datetime_1.SeriesDateFunctions)(_s);
},
abs: noArgWrap("abs"),
get struct() {
return (0, struct_1.SeriesStructFunctions)(_s);
},
abs() {
return wrap("abs");
},
add(field) {
return dtypeAccessor(wrap)("add", { field, key: "other" });
return dtypeWrap("Add", field);
},
alias(name) {
const s = this.clone();
unwrap("rename", { name }, s._series);
return s;
const s = _s.clone();
s.rename(name);
return _Series(s);
},
append(other) {
return wrap("append", { other: other._series });
_s.append(other.inner());
},
argMax: noArgUnwrap("arg_max"),
argMin: noArgUnwrap("arg_min"),
argSort(reverse = false) {
return typeof reverse === "boolean" ?
wrap("argsort", { reverse }) :
wrap("argsort", reverse);
argMax() {
return _s.argMax();
},
argTrue: noArgWrap("arg_true"),
argUnique: noArgWrap("arg_unique"),
argMin() {
return _s.argMin();
},
argSort(reverse = false, nullsLast = true) {
if (typeof reverse === "boolean") {
return _Series(_s.argsort(reverse, nullsLast));
}
return _Series(_s.argsort(reverse.reverse, reverse.nullsLast ?? nullsLast));
},
argTrue() {
return _Series(_s.argTrue());
},
argUnique() {
return _Series(_s.argUnique());
},
as(name) {

@@ -131,23 +132,23 @@ return this.alias(name);

bitand(other) {
return wrap("bitand", { other: other._series });
return _Series(_s.bitand(other._s));
},
bitor(other) {
return wrap("bitor", { other: other._series });
return _Series(_s.bitor(other._s));
},
bitxor(other) {
return wrap("bitxor", { other: other._series });
return _Series(_s.bitxor(other._s));
},
cast(dtype, strict = false) {
return typeof strict === "boolean" ?
wrap("cast", { dtype, strict }) :
wrap("cast", { dtype, ...strict });
return _Series(_s.cast(dtype, strict));
},
chunkLengths: noArgUnwrap("chunk_lengths"),
chunkLengths() {
return _s.chunkLengths();
},
clone() {
return wrap("clone");
return _Series(_s.clone());
},
concat(other) {
const s = this.clone();
unwrap("append", { other: other._series }, s._series);
return s;
const s = _s.clone();
s.append(other.inner());
return _Series(s);
},

@@ -160,24 +161,16 @@ cumCount(reverse) {

},
cumMax(reverse = false) {
return typeof reverse === "boolean" ?
wrap("cummax", { reverse }) :
wrap("cummax", reverse);
cumSum(reverse) {
return _Series(_s.cumsum(reverse));
},
cumMin(reverse = false) {
return typeof reverse === "boolean" ?
wrap("cummin", { reverse }) :
wrap("cummin", reverse);
cumMax(reverse) {
return _Series(_s.cummax(reverse));
},
cumProd(reverse = false) {
return typeof reverse === "boolean" ?
wrap("cumprod", { reverse }) :
wrap("cumprod", reverse);
cumMin(reverse) {
return _Series(_s.cummin(reverse));
},
cumSum(reverse = false) {
return typeof reverse === "boolean" ?
wrap("cumsum", { reverse }) :
wrap("cumsum", reverse);
cumProd(reverse) {
return _Series(_s.cumprod(reverse));
},
describe() {
let s = (0, exports.seriesWrapper)(_s);
let s = this.clone();
let stats = {};

@@ -211,5 +204,2 @@ if (!this.length) {

}
else if (s.isDateTime()) {
throw (0, error_1.todo)();
}
else {

@@ -223,12 +213,9 @@ throw new error_1.InvalidOperationError("describe", s.dtype);

},
diff(n = 1, null_behavior = "ignore") {
diff(n = 1, nullBehavior = "ignore") {
return typeof n === "number" ?
wrap("diff", { n, null_behavior }) :
wrap("diff", {
n: n?.n ?? 1,
null_behavior: n.nullBehavior ?? null_behavior
});
_Series(_s.diff(n, nullBehavior)) :
_Series(_s.diff(n?.n ?? 1, n.nullBehavior ?? nullBehavior));
},
div(field) {
return dtypeAccessor(wrap)("div", { field, key: "other" });
return dtypeWrap("Div", field);
},

@@ -239,7 +226,9 @@ divideBy(field) {

dot(other) {
return unwrap("dot", { other: other._series });
return wrap("dot", other._s);
},
dropNulls: noArgWrap("drop_nulls"),
dropNulls() {
return wrap("dropNulls");
},
eq(field) {
return dtypeAccessor(wrap)("eq", { field, key: "rhs" });
return dtypeWrap("Eq", field);
},

@@ -249,49 +238,51 @@ equals(field) {

},
explode: noArgWrap("explode"),
extend(o, n) {
return this.extendConstant(o, n);
explode() {
return wrap("explode");
},
extendConstant(o, n) {
if (n !== null && typeof n === "number") {
return wrap("extend_constant", { value: o, n });
}
return wrap("extend_constant", o);
extend(value, n) {
return wrap("extendConstant", value, n);
},
extendConstant(value, n) {
return wrap("extendConstant", value, n);
},
fillNull(strategy) {
return typeof strategy === "string" ?
wrap("fill_null", { strategy }) :
wrap("fill_null", strategy);
wrap("fillNull", strategy) :
wrap("fillNull", strategy.strategy);
},
filter(predicate) {
return exports.Series.isSeries(predicate) ?
wrap("filter", { filter: predicate._series }) :
wrap("filter", { filter: predicate.predicate._series });
wrap("filter", predicate._s) :
wrap("filter", SeriesConstructor("", predicate)._s);
},
get(field) {
return dtypeAccessor(unwrap)("get", { field, key: "index" });
return dtypeUnwrap("Get", field);
},
getIndex(idx) {
return unwrap("get_idx", { idx });
return _s.getIdx(idx);
},
gt(field) {
return dtypeAccessor(wrap)("gt", { field, key: "rhs" });
return dtypeWrap("Gt", field);
},
gtEq(field) {
return dtypeAccessor(wrap)("gt_eq", { field, key: "rhs" });
},
greaterThan(field) {
return this.gt(field);
},
gtEq(field) {
return dtypeWrap("GtEq", field);
},
greaterThanEquals(field) {
return this.gtEq(field);
},
hash(obj = 0, k1 = 1, k2 = 2, k3 = 3) {
hash(obj = 0n, k1 = 1n, k2 = 2n, k3 = 3n) {
if (typeof obj === "number" || typeof obj === "bigint") {
return wrap("hash", { k0: obj, k1: k1, k2: k2, k3: k3 });
return wrap("hash", BigInt(obj), BigInt(k1), BigInt(k2), BigInt(k3));
}
return wrap("hash", { k0: 0, k1, k2, k3, ...obj });
const o = { k0: obj, k1: k1, k2: k2, k3: k3, ...obj };
return wrap("hash", BigInt(o.k0), BigInt(o.k1), BigInt(o.k2), BigInt(o.k3));
},
hasValidity: noArgUnwrap("has_validity"),
hasValidity() {
return _s.hasValidity();
},
head(length = 5) {
return wrap("head", { length });
return wrap("head", length);
},

@@ -301,101 +292,167 @@ inner() {

},
interpolate: noArgWrap("interpolate"),
interpolate() {
return wrap("interpolate");
},
isBoolean() {
const dtype = unwrap("dtype");
return datatypes_1.DataType[dtype] === datatypes_1.DataType.Bool;
const dtype = this.dtype;
return dtype === polars_internal_1.default.DataType.Bool;
},
isDateTime() {
const dtype = unwrap("dtype");
return [datatypes_1.DataType.Date, datatypes_1.DataType.Datetime].includes(datatypes_1.DataType[dtype]);
const dtype = this.dtype;
return [polars_internal_1.default.DataType.Date, polars_internal_1.default.DataType.Datetime].includes(dtype);
},
isDuplicated: noArgWrap("is_duplicated"),
isDuplicated() {
return wrap("isDuplicated");
},
isFinite() {
const dtype = unwrap("dtype");
if (![datatypes_1.DataType.Float32, datatypes_1.DataType.Float64].includes(datatypes_1.DataType[dtype])) {
const dtype = this.dtype;
if (![polars_internal_1.default.DataType.Float32, polars_internal_1.default.DataType.Float64].includes(dtype)) {
throw new error_1.InvalidOperationError("isFinite", dtype);
}
else {
return wrap("is_finite");
return wrap("isFinite");
}
},
isFirst: noArgWrap("is_first"),
isFirst() {
return wrap("isFirst");
},
isFloat() {
const dtype = this.dtype;
return [datatypes_1.DataType.Float32, datatypes_1.DataType.Float64].includes(datatypes_1.DataType[dtype]);
return [polars_internal_1.default.DataType.Float32, polars_internal_1.default.DataType.Float64].includes(dtype);
},
isIn(other) {
return exports.Series.isSeries(other) ?
wrap("is_in", { other: other._series }) :
wrap("is_in", { other: (0, exports.Series)(other)._series });
wrap("isIn", other._s) :
wrap("isIn", (0, exports.Series)("", other)._s);
},
isInfinite() {
const dtype = unwrap("dtype");
if (![datatypes_1.DataType.Float32, datatypes_1.DataType.Float64].includes(datatypes_1.DataType[dtype])) {
throw new error_1.InvalidOperationError("isInfinite", dtype);
const dtype = this.dtype;
if (![polars_internal_1.default.DataType.Float32, polars_internal_1.default.DataType.Float64].includes(dtype)) {
throw new error_1.InvalidOperationError("isFinite", dtype);
}
else {
return wrap("is_infinite");
return wrap("isInfinite");
}
},
isNotNull: noArgWrap("is_not_null"),
isNull: noArgWrap("is_null"),
isNotNull() {
return wrap("isNotNull");
},
isNull() {
return wrap("isNull");
},
isNaN() {
return wrap("isNan");
},
isNotNaN() {
return wrap("isNotNan");
},
isNumeric() {
const dtype = unwrap("dtype");
const dtype = this.dtype;
const numericTypes = [
datatypes_1.DataType.Int8,
datatypes_1.DataType.Int16,
datatypes_1.DataType.Int32,
datatypes_1.DataType.Int64,
datatypes_1.DataType.UInt8,
datatypes_1.DataType.UInt16,
datatypes_1.DataType.UInt32,
datatypes_1.DataType.UInt64,
datatypes_1.DataType.Float32,
datatypes_1.DataType.Float64
polars_internal_1.default.DataType.Int8,
polars_internal_1.default.DataType.Int16,
polars_internal_1.default.DataType.Int32,
polars_internal_1.default.DataType.Int64,
polars_internal_1.default.DataType.UInt8,
polars_internal_1.default.DataType.UInt16,
polars_internal_1.default.DataType.UInt32,
polars_internal_1.default.DataType.UInt64,
polars_internal_1.default.DataType.Float32,
polars_internal_1.default.DataType.Float64
];
return numericTypes.includes(datatypes_1.DataType[dtype]);
return numericTypes.includes(dtype);
},
isUnique: noArgWrap("is_unique"),
isUnique() {
return wrap("isUnique");
},
isUtf8() {
const dtype = unwrap("dtype");
return datatypes_1.DataType[dtype] === datatypes_1.DataType.Utf8;
return this.dtype === polars_internal_1.default.DataType.Utf8;
},
kurtosis(fisher = true, bias = true) {
if (typeof fisher === "boolean") {
return unwrap("kurtosis", { fisher, bias });
return _s.kurtosis(fisher, bias);
}
return unwrap("kurtosis", {
const d = {
fisher: true,
bias,
...fisher
});
};
return _s.kurtosis(d.fisher, d.bias);
},
len: noArgUnwrap("len"),
lessThan: (field) => dtypeAccessor(wrap)("lt", { field, key: "rhs" }),
lessThanEquals: (field) => dtypeAccessor(wrap)("lt_eq", { field, key: "rhs" }),
limit: (n = 10) => wrap("limit", { num_elements: n }),
ltEq: (field) => dtypeAccessor(wrap)("lt_eq", { field, key: "rhs" }),
lt: (field) => dtypeAccessor(wrap)("lt", { field, key: "rhs" }),
max: noArgUnwrap("max"),
mean: noArgUnwrap("mean"),
median: noArgUnwrap("median"),
min: noArgUnwrap("min"),
minus: (field) => dtypeAccessor(wrap)("sub", { field, key: "other" }),
mode: noArgWrap("mode"),
mul: (field) => dtypeAccessor(wrap)("mul", { field, key: "other" }),
nChunks: noArgUnwrap("n_chunks"),
neq: (field) => dtypeAccessor(wrap)("neq", { field, key: "rhs" }),
notEquals: (field) => dtypeAccessor(wrap)("neq", { field, key: "rhs" }),
nullCount: noArgUnwrap("null_count"),
nUnique: noArgUnwrap("n_unique"),
peakMax: noArgWrap("peak_max"),
peakMin: noArgWrap("peak_min"),
plus: (field) => dtypeAccessor(wrap)("add", { field, key: "other" }),
quantile: (quantile) => unwrap("quantile", { quantile }),
rank: (method = "average") => wrap("rank", { method }),
rechunk: inPlaceOptional("rechunk"),
len() {
return this.length;
},
lt(field) {
return dtypeWrap("Lt", field);
},
lessThan(field) {
return dtypeWrap("Lt", field);
},
ltEq(field) {
return dtypeWrap("LtEq", field);
},
lessThanEquals(field) {
return dtypeWrap("LtEq", field);
},
limit(n = 10) {
return wrap("limit", n);
},
max() {
return _s.max();
},
mean() {
return _s.mean();
},
median() {
return _s.median();
},
min() {
return _s.min();
},
mode() {
return wrap("mode");
},
minus(other) {
return dtypeWrap("Sub", other);
},
mul(other) {
return dtypeWrap("Mul", other);
},
nChunks() {
return _s.nChunks();
},
neq(other) {
return dtypeWrap("Neq", other);
},
notEquals(other) {
return this.neq(other);
},
nullCount() {
return _s.nullCount();
},
nUnique() {
return _s.nUnique();
},
peakMax() {
return wrap("peakMax");
},
peakMin() {
return wrap("peakMin");
},
plus(other) {
return dtypeWrap("Add", other);
},
quantile(quantile, interpolation = "nearest") {
return _s.quantile(quantile, interpolation);
},
rank(method = "average", reverse = false) {
return wrap("rank", method, reverse);
},
rechunk(inPlace = false) {
return wrap("rechunk", inPlace);
},
reinterpret(signed = true) {
const dtype = unwrap("dtype");
if ([datatypes_1.DataType.UInt64, datatypes_1.DataType.Int64].includes(datatypes_1.DataType[dtype])) {
return wrap("reinterpret", { signed });
const dtype = this.dtype;
if ([polars_internal_1.default.DataType.UInt64, polars_internal_1.default.DataType.Int64].includes(dtype)) {
return wrap("reinterpret", signed);
}

@@ -406,7 +463,11 @@ else {

},
rem: (field) => dtypeAccessor(wrap)("rem", { field, key: "other" }),
modulo: (field) => dtypeAccessor(wrap)("rem", { field, key: "other" }),
rem(field) {
return dtypeWrap("Rem", field);
},
modulo(field) {
return this.rem(field);
},
rename(obj, inPlace = false) {
if (obj?.inPlace ?? inPlace) {
unwrap("rename", { name: obj?.name ?? obj });
_s.rename(obj?.name ?? obj);
}

@@ -417,14 +478,26 @@ else {

},
rollingMax: rolling("rolling_max"),
rollingMean: rolling("rolling_mean"),
rollingMin: rolling("rolling_min"),
rollingSum: rolling("rolling_sum"),
rollingStd: rolling("rolling_std"),
rollingVar: rolling("rolling_var"),
rollingMedian: rolling("rollingMedian"),
rollingQuantile(val, interpolation, windowSize, weights, minPeriods, center) {
rollingMax(windowSize, weights, minPeriods, center) {
return rolling("rollingMax", windowSize, weights, minPeriods, center);
},
rollingMean(windowSize, weights, minPeriods, center) {
return rolling("rollingMean", windowSize, weights, minPeriods, center);
},
rollingMin(windowSize, weights, minPeriods, center) {
return rolling("rollingMin", windowSize, weights, minPeriods, center);
},
rollingSum(windowSize, weights, minPeriods, center) {
return rolling("rollingSum", windowSize, weights, minPeriods, center);
},
rollingStd(windowSize, weights, minPeriods, center) {
return rolling("rollingStd", windowSize, weights, minPeriods, center);
},
rollingVar(windowSize, weights, minPeriods, center) {
return rolling("rollingVar", windowSize, weights, minPeriods, center);
},
rollingMedian(windowSize, weights, minPeriods, center) {
return rolling("rollingMedian", windowSize, weights, minPeriods, center);
},
rollingQuantile(val, interpolation = "nearest", windowSize, weights, minPeriods, center) {
if (typeof val === "number") {
return wrap("rolling_quantile", {
quantile: val,
interpolation,
return wrap("rollingQuantile", val, interpolation ?? "nearest", {
windowSize,

@@ -436,3 +509,13 @@ weights,

}
return wrap("rolling_quantile", val);
windowSize = val?.["windowSize"] ?? (typeof val === "number" ? val : null);
if (windowSize === null) {
throw new Error("window size is required");
}
const options = {
windowSize: val?.["windowSize"] ?? (typeof val === "number" ? val : null),
weights: val?.["weights"] ?? weights,
minPeriods: val?.["minPeriods"] ?? minPeriods ?? windowSize,
center: val?.["center"] ?? center ?? false,
};
return wrap("rollingQuantile", val.quantile, val.interpolation ?? "nearest", options);
},

@@ -445,11 +528,15 @@ rollingSkew(windowSize, bias) {

},
floor: noArgWrap("floor"),
ceil: noArgWrap("ceil"),
floor() {
return wrap("floor");
},
ceil() {
return wrap("ceil");
},
round(opt) {
if (this.isNumeric()) {
if (typeof opt === "number") {
return wrap("round", { decimals: opt });
return wrap("round", opt);
}
else {
return wrap("round", opt);
return wrap("round", opt.decimals);
}

@@ -462,26 +549,18 @@ }

clip(arg, max) {
const dtypes = [
datatypes_1.DataType.Int32,
datatypes_1.DataType.Int64,
datatypes_1.DataType.Float32,
datatypes_1.DataType.Float64,
datatypes_1.DataType.UInt32
];
if (dtypes.includes(this.dtype)) {
throw new error_1.InvalidOperationError("clip", this.dtype);
}
if (typeof arg === "number") {
return wrap("clip", { min: arg, max });
}
else {
return wrap("clip", arg);
}
return this
.toFrame()
.select((0, functions_1.col)(this.name).clip(arg, max))
.getColumn(this.name);
},
setAtIdx(indices, value) {
indices = exports.Series.isSeries(indices) ? indices.cast(datatypes_1.DataType.UInt32).toArray() : indices;
return dtypeWrap("SetAtIdx", indices, value);
},
set(mask, value) {
mask = exports.Series.isSeries(mask) ? mask : exports.Series.from(mask);
return dtypeWrap("SetWithMask", mask.inner(), value);
},
sample(opts, frac, withReplacement = false, seed) {
if (arguments.length === 0) {
return wrap("sample_n", {
n: 1,
withReplacement,
seed
});
return wrap("sampleN", 1, withReplacement, seed);
}

@@ -492,14 +571,6 @@ if (opts?.n !== undefined || opts?.frac !== undefined) {

if (typeof opts === "number") {
return wrap("sample_n", {
n: opts,
withReplacement,
seed
});
return wrap("sampleN", opts, withReplacement, seed);
}
if (typeof frac === "number") {
return wrap("sample_frac", {
frac,
withReplacement,
seed
});
return wrap("sampleFrac", frac, withReplacement, seed);
}

@@ -510,82 +581,86 @@ else {

},
seriesEqual(other, opt = true) {
return unwrap("series_equal", {
other: other._series,
null_equal: opt?.nullEqual ?? opt
});
seriesEqual(other, nullEqual = true, strict = false) {
return _s.seriesEqual(other._s, nullEqual, strict);
},
set(filter, value) {
const dtype = this.dtype;
const dt = datatypes_1.DTYPE_TO_FFINAME[datatypes_1.DataType[dtype]];
return wrap(`set_with_mask_${dt}`, { filter: filter._series, value });
shift(periods = 1) {
return wrap("shift", periods);
},
setAtIdx(indices, value) {
const dtype = this.dtype;
const dt = datatypes_1.DTYPE_TO_FFINAME[datatypes_1.DataType[dtype]];
indices = exports.Series.isSeries(indices) ? indices.cast(datatypes_1.DataType.UInt32).toArray() : indices;
unwrap(`set_at_idx_${dt}`, { indices, value });
return this;
},
shift(opt = 1) {
if (typeof opt === "number") {
return wrap("shift", { periods: opt });
}
return wrap("shift", opt);
},
shiftAndFill(opt, fillValue) {
shiftAndFill(periods, fillValue) {
return this
.toFrame()
.select((0, functions_1.col)(this.name).shiftAndFill(opt, fillValue))
.select((0, functions_1.col)(this.name).shiftAndFill(periods, fillValue))
.getColumn(this.name);
},
shrinkToFit: inPlaceOptional("shrink_to_fit"),
skew(opt = true) {
if (typeof opt === "boolean") {
return unwrap("skew", { bias: opt });
shrinkToFit(inPlace) {
if (inPlace) {
_s.shrinkToFit();
}
return unwrap("skew", opt);
else {
const s = this.clone();
s.shrinkToFit();
return s;
}
},
slice(opts, length) {
if (typeof opts === "number") {
return wrap("slice", { offset: opts, length });
skew(bias = true) {
if (typeof bias === "boolean") {
return _s.skew(bias);
}
return wrap("slice", opts);
return _s.skew(bias?.bias ?? true);
},
sort(opt = false) {
if (typeof opt === "boolean") {
return wrap("sort", { reverse: opt });
slice(offset, length) {
if (typeof offset === "number") {
return wrap("slice", offset, length);
}
return wrap("sort", opt);
return wrap("slice", offset.offset, offset.length);
},
sub: (field) => dtypeAccessor(wrap)("sub", { field, key: "other" }),
sum: noArgUnwrap("sum"),
tail: (length = 5) => wrap("tail", { length }),
take: (indices) => wrap("take", { indices }),
takeEvery: (n) => wrap("take_every", { n }),
multiplyBy: (field) => dtypeAccessor(wrap)("mul", { field, key: "other" }),
sort(reverse) {
if (typeof reverse === "boolean") {
return wrap("sort", reverse);
}
return wrap("sort", reverse?.reverse ?? false);
},
sub(field) {
return dtypeWrap("Sub", field);
},
sum() {
return _s.sum();
},
tail(length = 5) {
return wrap("tail", length);
},
take(indices) {
return wrap("take", indices);
},
takeEvery(n) {
return wrap("takeEvery", n);
},
multiplyBy(field) {
return this.mul(field);
},
toArray() {
const arr = unwrap("to_js").values;
const dtype = this.dtype;
if (datatypes_1.DataType[dtype] === datatypes_1.DataType.List) {
return arr.map((s) => s.values);
return _s.toArray();
},
toTypedArray() {
if (!this.hasValidity()) {
return _s.toTypedArray();
}
return arr;
else {
throw new Error("data contains nulls, unable to convert to TypedArray");
}
},
toFrame() {
return (0, dataframe_1.dfWrapper)(polars_internal_1.default.df.read_columns({ columns: [_s] }));
return (0, dataframe_1._DataFrame)(new polars_internal_1.default.JsDataFrame([_s]));
},
toBinary() {
return unwrap("to_bincode");
return _s.toBinary();
},
toJSON(arg0) {
// JSON.stringify passes `""` by default then stringifies the JS output
if (arg0 === "") {
return unwrap("to_js");
}
return unwrap("to_json").toString();
toJSON() {
return _s.toJson().toString();
},
toObject: noArgUnwrap("to_js"),
unique(opt) {
if (opt) {
return wrap("unique_stable");
toObject() {
return JSON.parse(_s.toJson().toString());
},
unique(maintainOrder) {
if (maintainOrder) {
return wrap("uniqueStable");
}

@@ -597,3 +672,3 @@ else {

valueCounts() {
return (0, dataframe_1.dfWrapper)(unwrap("value_counts"));
return null;
},

@@ -604,6 +679,6 @@ values() {

zipWith(mask, other) {
return wrap("zip_with", { mask: mask._series, other: other._series });
},
return wrap("zipWith", mask._s, other._s);
}
};
return new Proxy(seriesObject, {
return new Proxy(series, {
get: function (target, prop, receiver) {

@@ -624,23 +699,29 @@ if (typeof prop !== "symbol" && !Number.isNaN(Number(prop))) {

});
};
exports.seriesWrapper = seriesWrapper;
function SeriesConstructor(arg0, arg1, dtype, strict) {
}
exports._Series = _Series;
let SeriesConstructor = function (arg0, arg1, dtype, strict) {
if (typeof arg0 === "string") {
const _s = (0, construction_1.arrayToJsSeries)(arg0, arg1, dtype, strict);
return (0, exports.seriesWrapper)(_s);
return _Series(_s);
}
return SeriesConstructor("", arg0);
}
const isSeries = (anyVal) => (0, types_1.isExternal)(anyVal?._series);
const from = (values) => {
if ((0, types_1.isTypedArray)(values)) {
return (0, exports.seriesWrapper)(polars_internal_1.default.series.new_from_typed_array({ name: "", values }));
};
const isSeries = (anyVal) => {
try {
return anyVal?.[Symbol.toStringTag]?.() === "Series";
}
return SeriesConstructor("", values);
catch (err) {
return false;
}
};
const fromBinary = (buf) => {
return (0, exports.seriesWrapper)(polars_internal_1.default.series.from_bincode(buf));
const from = (name, values) => {
if (Array.isArray(name)) {
return SeriesConstructor("", values);
}
else {
return SeriesConstructor(name, values);
}
};
const of = (...values) => {
return from(values);
return exports.Series.from(values);
};

@@ -650,4 +731,3 @@ exports.Series = Object.assign(SeriesConstructor, {

from,
fromBinary,
of
});
import { DataType } from "../datatypes";
import { JsSeries, Series } from "./series";
import { Series } from "./series";
/**

@@ -15,3 +15,3 @@ * namespace containing series string functions

*/
concat(delimiter: string): Series<string>;
concat(delimiter: string): Series;
/**

@@ -22,3 +22,3 @@ * Check if strings in Series contain regex pattern.

*/
contains(pattern: string | RegExp): Series<boolean>;
contains(pattern: string | RegExp): Series;
/**

@@ -44,7 +44,7 @@ * Decodes a value using the provided encoding

*/
decode(encoding: "hex" | "base64", strict?: boolean): Series<string>;
decode(encoding: "hex" | "base64", strict?: boolean): Series;
decode(options: {
encoding: "hex" | "base64";
strict?: boolean;
}): Series<string>;
}): Series;
/**

@@ -66,3 +66,3 @@ * Encodes a value using the provided encoding

*/
encode(encoding: "hex" | "base64"): Series<string>;
encode(encoding: "hex" | "base64"): Series;
/**

@@ -98,3 +98,3 @@ * Extract the target capture group from provided patterns.

*/
extract(pattern: string | RegExp, groupIndex: number): Series<string>;
extract(pattern: string | RegExp, groupIndex: number): Series;
/**

@@ -128,7 +128,7 @@ * Extract the first match of json string with provided JSONPath expression.

*/
jsonPathMatch(jsonPath: string): Series<string>;
jsonPathMatch(jsonPath: string): Series;
/** Get length of the string values in the Series. */
lengths(): Series<number>;
lengths(): Series;
/** Remove leading whitespace. */
lstrip(): Series<string>;
lstrip(): Series;
/**

@@ -139,3 +139,3 @@ * Replace first regex match with a string value.

*/
replace(pattern: string | RegExp, value: string): Series<string>;
replace(pattern: string | RegExp, value: string): Series;
/**

@@ -146,11 +146,11 @@ * Replace all regex matches with a string value.

*/
replaceAll(pattern: string | RegExp, value: string): Series<string>;
replaceAll(pattern: string | RegExp, value: string): Series;
/** Modify the strings to their lowercase equivalent. */
toLowerCase(): Series<string>;
toLowerCase(): Series;
/** Modify the strings to their uppercase equivalent. */
toUpperCase(): Series<string>;
toUpperCase(): Series;
/** Remove trailing whitespace. */
rstrip(): Series<string>;
rstrip(): Series;
/** Remove leading and trailing whitespace. */
strip(): Series<string>;
strip(): Series;
/**

@@ -161,3 +161,3 @@ * Create subslices of the string values of a Utf8 Series.

*/
slice(start: number, length?: number): Series<string>;
slice(start: number, length?: number): Series;
/**

@@ -171,11 +171,11 @@ * Split a string into substrings using the specified separator.

inclusive?: boolean;
} | boolean): Series<Series<string>>;
} | boolean): Series;
/**
* Parse a Series of dtype Utf8 to a Date/Datetime Series.
* @param datatype Date or Datetime.
* @param fmt formatting syntax. [Read more](https://docs.rs/chrono/0.4.19/chrono/format/strftime/index.html)
* @param fmt formatting syntax. [Read more](https://docs.rs/chrono/0.4.19/chrono/format/strptime/index.html)
*/
strftime(datatype: DataType.Date, fmt?: string): Series<Date>;
strftime(datatype: DataType.Datetime, fmt?: string): Series<Date>;
strptime(datatype: DataType.Date, fmt?: string): Series;
strptime(datatype: DataType.Datetime, fmt?: string): Series;
}
export declare const StringFunctions: (_s: JsSeries) => StringFunctions;
export declare const StringFunctions: (_s: any) => StringFunctions;
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.StringFunctions = void 0;
const polars_internal_1 = __importDefault(require("../internals/polars_internal"));
const datatypes_1 = require("../datatypes");
const series_1 = require("./series");

@@ -13,20 +8,12 @@ const utils_1 = require("../utils");

const StringFunctions = (_s) => {
const wrap = (method, args, _series = _s) => {
return (0, series_1.seriesWrapper)(polars_internal_1.default.series.str[method]({ _series, ...args }));
const wrap = (method, ...args) => {
const ret = _s[method](...args);
return (0, series_1._Series)(ret);
};
const callExpr = (method) => (...args) => {
const s = (0, series_1.seriesWrapper)(_s);
return s
.toFrame()
.select((0, functions_1.col)(s.name)
.lst[method](...args)
.as(s.name))
.getColumn(s.name);
};
const handleDecode = (encoding, strict) => {
switch (encoding) {
case "hex":
return wrap(`decodeHex`, { strict });
return wrap("strHexDecode", strict);
case "base64":
return wrap(`decodeBase64`, { strict });
return wrap("strBase64Decode", strict);
default:

@@ -38,13 +25,12 @@ throw new RangeError("supported encodings are 'hex' and 'base64'");

concat(delimiter) {
const s = (0, series_1.seriesWrapper)(_s);
return s
return (0, series_1._Series)(_s)
.toFrame()
.select((0, functions_1.col)(s.name)
.select((0, functions_1.col)(_s.name)
.str
.concat(delimiter)
.as(s.name))
.getColumn(s.name);
.as(_s.name))
.getColumn(_s.name);
},
contains(pat) {
return wrap("contains", { pat: (0, utils_1.regexToString)(pat) });
return wrap("strContains", (0, utils_1.regexToString)(pat));
},

@@ -60,5 +46,5 @@ decode(arg, strict = false) {

case "hex":
return wrap(`encodeHex`);
return wrap(`strHexEncode`);
case "base64":
return wrap(`encodeBase64`);
return wrap(`strBase64Encode`);
default:

@@ -69,28 +55,28 @@ throw new RangeError("supported encodings are 'hex' and 'base64'");

extract(pat, groupIndex) {
return wrap("extract", { pat: (0, utils_1.regexToString)(pat), groupIndex });
return wrap("strExtract", (0, utils_1.regexToString)(pat), groupIndex);
},
jsonPathMatch(pat) {
return wrap("jsonPathMatch", { pat });
return wrap("strJsonPathMatch", pat);
},
lengths() {
return wrap("lengths");
return wrap("strLengths");
},
lstrip() {
return wrap("replace", { pat: /^\s*/.source, val: "" });
return wrap("strReplace", /^\s*/.source, "");
},
replace(pat, val) {
return wrap("replace", { pat: (0, utils_1.regexToString)(pat), val });
return wrap("strReplace", (0, utils_1.regexToString)(pat), val);
},
replaceAll(pat, val) {
return wrap("replaceAll", { pat: (0, utils_1.regexToString)(pat), val });
return wrap("strReplaceAll", (0, utils_1.regexToString)(pat), val);
},
rstrip() {
return wrap("replace", { pat: /[ \t]+$/.source, val: "" });
return wrap("strReplace", /[ \t]+$/.source, "");
},
slice(start, length) {
return wrap("slice", { start, length });
return wrap("strSlice", start, length);
},
split(by, options) {
const inclusive = typeof options === "boolean" ? options : options?.inclusive;
const s = (0, series_1.seriesWrapper)(_s);
const s = (0, series_1._Series)(_s);
return s

@@ -119,3 +105,3 @@ .toFrame()

strip() {
const s = (0, series_1.seriesWrapper)(_s);
const s = (0, series_1._Series)(_s);
return s

@@ -129,18 +115,17 @@ .toFrame()

},
strftime(dtype, fmt) {
if (dtype === datatypes_1.DataType.Date) {
return wrap("parseDate", { fmt });
}
else if (dtype === datatypes_1.DataType.Datetime) {
return wrap("parseDateTime", { fmt });
}
else {
throw new Error(`only "DataType.Date" and "DataType.Datetime" are supported`);
}
strptime(dtype, fmt) {
const s = (0, series_1._Series)(_s);
return s
.toFrame()
.select((0, functions_1.col)(s.name)
.str
.strptime(dtype, fmt)
.as(s.name))
.getColumn(s.name);
},
toLowerCase() {
return wrap("toLowerCase");
return wrap("strToLowercase");
},
toUpperCase() {
return wrap("toUpperCase");
return wrap("strToUppercase");
},

@@ -147,0 +132,0 @@ };

@@ -0,1 +1,2 @@

import { Expr } from "./lazy/expr";
export declare type RollingOptions = {

@@ -334,1 +335,159 @@ windowSize: number;

}
export interface ListFunctions<T> {
argMin(): T;
argMax(): T;
/**
* Get the value by index in the sublists.
* So index `0` would return the first item of every sublist
* and index `-1` would return the last item of every sublist
* if an index is out of bounds, it will return a `null`.
*/
get(index: number): T;
/**
Run any polars expression against the lists' elements
Parameters
----------
@param expr
Expression to run. Note that you can select an element with `pl.first()`, or `pl.col()`
@param parallel
Run all expression parallel. Don't activate this blindly.
Parallelism is worth it if there is enough work to do per thread.
This likely should not be use in the groupby context, because we already parallel execution per group
@example
--------
>>> df = pl.DataFrame({"a": [1, 8, 3], "b": [4, 5, 2]})
>>> df.withColumn(
... pl.concatList(["a", "b"]).lst.eval(pl.first().rank()).alias("rank")
... )
shape: (3, 3)
┌─────┬─────┬────────────┐
│ a ┆ b ┆ rank │
│ --- ┆ --- ┆ --- │
│ i64 ┆ i64 ┆ list [f32] │
╞═════╪═════╪════════════╡
│ 1 ┆ 4 ┆ [1.0, 2.0] │
├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┤
│ 8 ┆ 5 ┆ [2.0, 1.0] │
├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┤
│ 3 ┆ 2 ┆ [2.0, 1.0] │
└─────┴─────┴────────────┘
*/
eval(expr: Expr, parallel: boolean): T;
/** Get the first value of the sublists. */
first(): T;
/**
* Join all string items in a sublist and place a separator between them.
* This errors if inner type of list `!= Utf8`.
* @param separator A string used to separate one element of the list from the next in the resulting string.
* If omitted, the list elements are separated with a comma.
*/
join(separator?: string): T;
/** Get the last value of the sublists. */
last(): T;
lengths(): T;
max(): T;
mean(): T;
min(): T;
reverse(): T;
shift(periods: number): T;
slice(offset: number, length: number): T;
sort(reverse?: boolean): T;
sort(opt: {
reverse: boolean;
}): T;
sum(): T;
unique(): T;
}
export interface DateFunctions<T> {
/**
* Extract day from underlying Date representation.
* Can be performed on Date and Datetime.
*
* Returns the day of month starting from 1.
* The return value ranges from 1 to 31. (The last day of month differs by months.)
* @returns day as pl.UInt32
*/
day(): T;
/**
* Extract hour from underlying DateTime representation.
* Can be performed on Datetime.
*
* Returns the hour number from 0 to 23.
* @returns Hour as UInt32
*/
hour(): T;
/**
* Extract minutes from underlying DateTime representation.
* Can be performed on Datetime.
*
* Returns the minute number from 0 to 59.
* @returns minute as UInt32
*/
minute(): T;
/**
* Extract month from underlying Date representation.
* Can be performed on Date and Datetime.
*
* Returns the month number starting from 1.
* The return value ranges from 1 to 12.
* @returns Month as UInt32
*/
month(): T;
/**
* Extract seconds from underlying DateTime representation.
* Can be performed on Datetime.
*
* Returns the number of nanoseconds since the whole non-leap second.
* The range from 1,000,000,000 to 1,999,999,999 represents the leap second.
* @returns Nanosecond as UInt32
*/
nanosecond(): T;
/**
* Extract ordinal day from underlying Date representation.
* Can be performed on Date and Datetime.
*
* Returns the day of year starting from 1.
* The return value ranges from 1 to 366. (The last day of year differs by years.)
* @returns Day as UInt32
*/
ordinalDay(): T;
/**
* Extract seconds from underlying DateTime representation.
* Can be performed on Datetime.
*
* Returns the second number from 0 to 59.
* @returns Second as UInt32
*/
second(): T;
/**
* Format Date/datetime with a formatting rule: See [chrono strftime/strptime](https://docs.rs/chrono/0.4.19/chrono/format/strftime/index.html).
*/
strftime(fmt: string): T;
/** Return timestamp in ms as Int64 type. */
timestamp(): T;
/**
* Extract the week from the underlying Date representation.
* Can be performed on Date and Datetime
*
* Returns the ISO week number starting from 1.
* The return value ranges from 1 to 53. (The last week of year differs by years.)
* @returns Week number as UInt32
*/
week(): T;
/**
* Extract the week day from the underlying Date representation.
* Can be performed on Date and Datetime.
*
* Returns the weekday number where monday = 0 and sunday = 6
* @returns Week day as UInt32
*/
weekday(): T;
/**
* Extract year from underlying Date representation.
* Can be performed on Date and Datetime.
*
* Returns the year number in the calendar date.
* @returns Year as Int32
*/
year(): T;
}
import { Expr } from "./lazy/expr";
import type { Series } from "./series/series";
import type { DataFrame } from "./dataframe";
import { Series } from "./series/series";
import { DataFrame } from "./dataframe";
export declare type ValueOrArray<T> = T | Array<ValueOrArray<T>>;

@@ -20,7 +20,7 @@ export declare type ColumnSelection = ValueOrArray<string>;

export declare function columnOrColumnsStrict(...columns: string[] | ValueOrArray<string>[]): Array<string>;
export declare function selectionToExprList(columns: any[], stringToLit?: any): Expr[];
export declare function selectionToExprList(columns: any[], stringToLit?: any): any[];
export declare function isPath(s: string, expectedExtensions?: string[]): boolean;
export declare const range: (start: number, end: number) => number[];
export declare const isDataFrameArray: (ty: any) => ty is DataFrame[];
export declare const isSeriesArray: <T>(ty: any) => ty is Series<T>[];
export declare const isSeriesArray: <T>(ty: any) => ty is Series[];
export declare const isExprArray: (ty: any) => ty is Expr[];

@@ -27,0 +27,0 @@ export declare const isIterator: <T>(ty: any) => ty is Iterable<T>;

@@ -8,2 +8,4 @@ "use strict";

const expr_1 = require("./lazy/expr");
const series_1 = require("./series/series");
const dataframe_1 = require("./dataframe");
const path_1 = __importDefault(require("path"));

@@ -35,7 +37,7 @@ const types_1 = require("util/types");

exports.range = range;
const isDataFrameArray = (ty) => Array.isArray(ty) && (0, types_1.isExternal)(ty[0]?._df);
const isDataFrameArray = (ty) => Array.isArray(ty) && dataframe_1.DataFrame.isDataFrame(ty[0]);
exports.isDataFrameArray = isDataFrameArray;
const isSeriesArray = (ty) => Array.isArray(ty) && (0, types_1.isExternal)(ty[0]?._series);
const isSeriesArray = (ty) => Array.isArray(ty) && series_1.Series.isSeries(ty[0]);
exports.isSeriesArray = isSeriesArray;
const isExprArray = (ty) => Array.isArray(ty) && (0, types_1.isExternal)(ty[0]?._expr);
const isExprArray = (ty) => Array.isArray(ty) && expr_1.Expr.isExpr(ty[0]);
exports.isExprArray = isExprArray;

@@ -42,0 +44,0 @@ const isIterator = (ty) => ty !== null && typeof ty[Symbol.iterator] === "function";

{
"name": "nodejs-polars",
"version": "0.4.1",
"version": "0.5.1",
"repository": "https://github.com/pola-rs/polars.git",

@@ -25,10 +25,7 @@ "license": "SEE LICENSE IN LICENSE",

"additional": [
"i686-pc-windows-msvc",
"aarch64-apple-darwin",
"aarch64-linux-android",
"aarch64-unknown-linux-gnu",
"armv7-unknown-linux-gnueabihf",
"aarch64-apple-darwin",
"aarch64-linux-android",
"x86_64-unknown-linux-musl",
"aarch64-unknown-linux-musl",
"aarch64-pc-windows-msvc"
"i686-pc-windows-msvc"
]

@@ -38,3 +35,3 @@ }

"engines": {
"node": ">= 10.20"
"node": ">= 16"
},

@@ -48,5 +45,6 @@ "publishConfig": {

"bench": "node -r @swc-node/register benchmark/bench.ts",
"build": "napi build --platform --release polars",
"build:debug": "napi build --platform",
"build:ts": " rm -rf bin; tsc -p tsconfig.build.json; mv bin/polars/* bin",
"build": "napi build --platform --release polars",
"build:debug": "napi build --platform polars",
"build:ts": " rm -rf bin; tsc -p tsconfig.build.json",
"cp:bin": "cp ./polars/*.node bin/",
"format:rs": "cargo fmt",

@@ -61,3 +59,3 @@ "format:source": "prettier --config ./package.json --write './**/*.{js,ts}'",

"devDependencies": {
"@napi-rs/cli": "^1.3.4",
"@napi-rs/cli": "^2.6.2",
"@types/chance": "^1.1.3",

@@ -85,5 +83,2 @@ "@types/jest": "^27.0.3",

},
"dependencies": {
"@node-rs/helper": "^1.2.1"
},
"packageManager": "yarn@3.1.1",

@@ -94,14 +89,11 @@ "workspaces": [

"optionalDependencies": {
"nodejs-polars-win32-x64-msvc": "0.4.1",
"nodejs-polars-darwin-x64": "0.4.1",
"nodejs-polars-linux-x64-gnu": "0.4.1",
"nodejs-polars-win32-ia32-msvc": "0.4.1",
"nodejs-polars-linux-arm64-gnu": "0.4.1",
"nodejs-polars-linux-arm-gnueabihf": "0.4.1",
"nodejs-polars-darwin-arm64": "0.4.1",
"nodejs-polars-android-arm64": "0.4.1",
"nodejs-polars-linux-x64-musl": "0.4.1",
"nodejs-polars-linux-arm64-musl": "0.4.1",
"nodejs-polars-win32-arm64-msvc": "0.4.1"
"nodejs-polars-win32-x64-msvc": "0.5.1",
"nodejs-polars-darwin-x64": "0.5.1",
"nodejs-polars-linux-x64-gnu": "0.5.1",
"nodejs-polars-darwin-arm64": "0.5.1",
"nodejs-polars-android-arm64": "0.5.1",
"nodejs-polars-linux-arm64-gnu": "0.5.1",
"nodejs-polars-linux-arm-gnueabihf": "0.5.1",
"nodejs-polars-win32-ia32-msvc": "0.5.1"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc