Skip to content

Commit

Permalink
bump polars version (#177)
Browse files Browse the repository at this point in the history
* bump polars version

* lint
  • Loading branch information
universalmind303 authored Mar 7, 2024
1 parent ce3b2df commit bf78f49
Show file tree
Hide file tree
Showing 17 changed files with 178 additions and 148 deletions.
26 changes: 14 additions & 12 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,17 @@ crate-type = ["cdylib", "lib"]
[dependencies]
ahash = "0.8.7"
bincode = "1.3.3"
napi = {version = "2.14.2", default-features = false, features = ["napi8", "serde-json"]}
napi-derive = {version = "2.14.6", default-features = false}
polars-core = {git = "https://github.com/pola-rs/polars.git", rev = "fa59ffc1685043b44476dcb2a3f3804460ead5c5", default-features = false}
polars-io = {git = "https://github.com/pola-rs/polars.git", rev = "fa59ffc1685043b44476dcb2a3f3804460ead5c5", default-features = false}
polars-lazy = {git = "https://github.com/pola-rs/polars.git", rev = "fa59ffc1685043b44476dcb2a3f3804460ead5c5", default-features = false}
napi = { version = "2.14.2", default-features = false, features = [
"napi8",
"serde-json",
] }
napi-derive = { version = "2.14.6", default-features = false }
polars-core = { git = "https://github.com/pola-rs/polars.git", rev = "3cf4897e679b056d17a235d48867035265d43cdc", default-features = false }
polars-io = { git = "https://github.com/pola-rs/polars.git", rev = "3cf4897e679b056d17a235d48867035265d43cdc", default-features = false }
polars-lazy = { git = "https://github.com/pola-rs/polars.git", rev = "3cf4897e679b056d17a235d48867035265d43cdc", default-features = false }
thiserror = "1"
smartstring = {version = "1"}
serde_json = {version = "1"}
smartstring = { version = "1" }
serde_json = { version = "1" }
either = "1.9"

[dependencies.polars]
Expand Down Expand Up @@ -54,7 +57,6 @@ features = [
"reinterpret",
"mode",
"extract_jsonpath",
"lazy_regex",
"cum_agg",
"rolling_window",
"repeat_by",
Expand All @@ -66,7 +68,6 @@ features = [
"pct_change",
"moment",
"diagonal_concat",
"horizontal_concat",
"abs",
"dot_diagram",
"dataframe_arithmetic",
Expand All @@ -89,10 +90,11 @@ features = [
"timezones",
"peaks",
"string_pad",
"cov"
"cov",
"group_by_list",
]
git = "https://github.com/pola-rs/polars.git"
rev = "fa59ffc1685043b44476dcb2a3f3804460ead5c5"
rev = "3cf4897e679b056d17a235d48867035265d43cdc"

[build-dependencies]
napi-build = "2.1.0"
Expand All @@ -103,4 +105,4 @@ lto = "fat"

[features]
default = ["range"]
range = ["polars-lazy/range"]
range = ["polars-lazy/range"]
4 changes: 2 additions & 2 deletions __tests__/dataframe.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1582,13 +1582,13 @@ describe("io", () => {
{
name: "foo",
datatype: "Float64",
bit_settings: "SORTED_ASC",
bit_settings: "",
values: [1.0],
},
{
name: "bar",
datatype: "String",
bit_settings: "SORTED_ASC",
bit_settings: "",
values: ["a"],
},
],
Expand Down
10 changes: 5 additions & 5 deletions __tests__/expr.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ describe("expr", () => {
});
test.each`
args | cumCount
${undefined} | ${[0, 1, 2]}
${true} | ${[2, 1, 0]}
${{ reverse: true }} | ${[2, 1, 0]}
${undefined} | ${[1, 2, 3]}
${true} | ${[3, 2, 1]}
${{ reverse: true }} | ${[3, 2, 1]}
`("$# cumCount", ({ args, cumCount }) => {
const df = pl.DataFrame({ a: [1, 2, 3] });
const expected = pl.DataFrame({ a: cumCount });
Expand Down Expand Up @@ -331,8 +331,8 @@ describe("expr", () => {
});
test.each`
args | hashValue
${[0]} | ${6340063056640878722n}
${[{ k0: 1n, k1: 1 }]} | ${9788354747012366704n}
${[0]} | ${7355865757046787768n}
${[{ k0: 1n, k1: 1 }]} | ${2179653058507248884n}
`("$# hash", ({ args, hashValue }) => {
const df = pl.DataFrame({ a: [1] });
const expected = pl.DataFrame({ hash: [hashValue] });
Expand Down
8 changes: 4 additions & 4 deletions __tests__/series.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ describe("series", () => {
${"getIndex"} | ${pl.Series(["a", "b", "c"]).getIndex(0)} | ${"a"}
${"hasValidity"} | ${pl.Series([1, null, 2]).hasValidity()} | ${true}
${"hasValidity"} | ${pl.Series([1, 1, 2]).hasValidity()} | ${false}
${"hash"} | ${pl.Series([1]).hash()} | ${pl.Series([6340063056640878722n])}
${"hash"} | ${pl.Series([1]).hash()} | ${pl.Series([7355865757046787768n])}
${"head"} | ${pl.Series([1, 2, 3, 4, 5, 5, 5]).head()} | ${pl.Series([1, 2, 3, 4, 5])}
${"head"} | ${pl.Series([1, 2, 3, 4, 5, 5, 5]).head(2)} | ${pl.Series([1, 2])}
${"interpolate"} | ${pl.Series([1, 2, null, null, 5]).interpolate()} | ${pl.Series([1, 2, 3, 4, 5])}
Expand Down Expand Up @@ -520,8 +520,8 @@ describe("series", () => {
${"slice"} | ${pl.Series([1, 2, 3, 3, 0]).slice(-3, 3)} | ${pl.Series([3, 3, 0])}
${"slice"} | ${pl.Series([1, 2, 3, 3, 0]).slice(1, 3)} | ${pl.Series([2, 3, 3])}
${"sort"} | ${pl.Series([4, 2, 5, 1, 2, 3, 3, 0]).sort()} | ${pl.Series([0, 1, 2, 2, 3, 3, 4, 5])}
${"sort"} | ${pl.Series([4, 2, 5, 0]).sort({ reverse: true })} | ${pl.Series([5, 4, 2, 0])}
${"sort"} | ${pl.Series([4, 2, 5, 0]).sort({ reverse: false })} | ${pl.Series([0, 2, 4, 5])}
${"sort"} | ${pl.Series([4, 2, 5, 0]).sort({ descending: true })} | ${pl.Series([5, 4, 2, 0])}
${"sort"} | ${pl.Series([4, 2, 5, 0]).sort({ descending: false })} | ${pl.Series([0, 2, 4, 5])}
${"sum"} | ${pl.Series([1, 2, 2, 1]).sum()} | ${6}
${"tail"} | ${pl.Series([1, 2, 2, 1]).tail(2)} | ${pl.Series([2, 1])}
${"gatherEvery"} | ${pl.Series([1, 3, 2, 9, 1]).gatherEvery(2)} | ${pl.Series([1, 2, 1])}
Expand All @@ -535,7 +535,7 @@ describe("series", () => {
.gather([2])} | ${pl.Series([[6, 7, 8]])}
${"toArray"} | ${pl.Series([1, 2, 3]).toArray()} | ${[1, 2, 3]}
${"unique"} | ${pl.Series([1, 2, 3, 3]).unique().sort()} | ${pl.Series([1, 2, 3])}
${"cumCount"} | ${pl.Series([1, 2, 3, 3]).cumCount()} | ${pl.Series([0, 1, 2, 3])}
${"cumCount"} | ${pl.Series([1, 2, 3, 3]).cumCount()} | ${pl.Series([1, 2, 3, 4])}
${"shiftAndFill"} | ${pl.Series("foo", [1, 2, 3]).shiftAndFill(1, 99)} | ${pl.Series("foo", [99, 1, 2])}
${"bitand"} | ${pl
.Series("bit", [1, 2, 3], pl.Int32)
Expand Down
11 changes: 10 additions & 1 deletion polars/lazy/expr/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ export type { ExprStruct as StructNamespace } from "./struct";

import { DataType } from "../../datatypes";
import pli from "../../internals/polars_internal";
import { ExprOrString, selectionToExprList, INSPECT_SYMBOL } from "../../utils";
import {
ExprOrString,
selectionToExprList,
INSPECT_SYMBOL,
regexToString,
} from "../../utils";
import { Series } from "../../series";
import {
Arithmetic,
Expand All @@ -23,6 +28,7 @@ import {
EwmOps,
} from "../../shared_traits";
import { InterpolationMethod, FillNullStrategy, RankMethod } from "../../types";
import { isRegExp } from "util/types";
/**
* Expressions that can be used in various contexts.
*/
Expand Down Expand Up @@ -1246,6 +1252,9 @@ export const Expr: ExprConstructor = Object.assign(_Expr, {
});

export const exprToLitOrExpr = (expr: any, stringToLit = true): Expr => {
if (isRegExp(expr)) {
return _Expr(pli.lit(regexToString(expr)));
}
if (typeof expr === "string" && !stringToLit) {
return _Expr(pli.col(expr));
}
Expand Down
15 changes: 13 additions & 2 deletions polars/lazy/expr/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,19 @@ export const ExprListFunctions = (_expr: any): ExprList => {
first() {
return this.get(0);
},
join(separator = ",") {
return wrap("listJoin", exprToLitOrExpr(separator)._expr);
join(options?) {
if (typeof options === "string") {
options = { separator: options };
}
options = options ?? {};
let separator = options?.separator ?? ",";
const ignoreNulls = options?.ignoreNulls ?? false;

if (!Expr.isExpr(separator)) {
separator = pli.lit(separator);
}

return wrap("listJoin", separator, ignoreNulls);
},
last() {
return this.get(-1);
Expand Down
27 changes: 19 additions & 8 deletions polars/lazy/expr/string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { StringFunctions } from "../../shared_traits";
import { DataType } from "../../datatypes";
import { regexToString } from "../../utils";
import { Expr, _Expr, exprToLitOrExpr } from "../expr";
import { lit } from "../functions";

/**
* namespace containing expr string functions
Expand Down Expand Up @@ -106,7 +107,7 @@ export interface StringNamespace extends StringFunctions<Expr> {
* └─────────┘
* ```
*/
extract(pat: string | RegExp, groupIndex: number): Expr;
extract(pat: any, groupIndex: number): Expr;
/**
* Parse string values as JSON.
* Throw errors if encounter invalid JSON strings.
Expand Down Expand Up @@ -267,7 +268,7 @@ export interface StringNamespace extends StringFunctions<Expr> {
* └──────────┘
* ```
*/
zFill(length: number): Expr;
zFill(length: number | Expr): Expr;
/**
* Add a trailing fillChar to a string until string length is reached.
* If string is longer or equal to given length no modifications will be done
Expand Down Expand Up @@ -306,7 +307,7 @@ export interface StringNamespace extends StringFunctions<Expr> {
* @param start - Start of the slice (negative indexing may be used).
* @param length - Optional length of the slice.
*/
slice(start: number, length?: number): Expr;
slice(start: number | Expr, length?: number | Expr): Expr;
/**
* Split a string into substrings using the specified separator and return them as a Series.
* @param separator — A string that identifies character or characters to use in separating the string.
Expand Down Expand Up @@ -364,8 +365,8 @@ export const ExprStringFunctions = (_expr: any): StringNamespace => {
throw new RangeError("supported encodings are 'hex' and 'base64'");
}
},
extract(pat: string | RegExp, groupIndex: number) {
return wrap("strExtract", regexToString(pat), groupIndex);
extract(pat: any, groupIndex: number) {
return wrap("strExtract", exprToLitOrExpr(pat, true)._expr, groupIndex);
},
jsonExtract(dtype?: DataType, inferSchemaLength?: number) {
return wrap("strJsonDecode", dtype, inferSchemaLength);
Expand Down Expand Up @@ -394,13 +395,23 @@ export const ExprStringFunctions = (_expr: any): StringNamespace => {
padStart(length: number, fillChar: string) {
return wrap("strPadStart", length, fillChar);
},
zFill(length: number) {
return wrap("strZFill", length);
zFill(length: number | Expr) {
if (!Expr.isExpr(length)) {
length = lit(length)._expr;
}
return wrap("zfill", length);
},
padEnd(length: number, fillChar: string) {
return wrap("strPadEnd", length, fillChar);
},
slice(start: number, length?: number) {
slice(start, length?) {
if (!Expr.isExpr(start)) {
start = lit(start)._expr;
}
if (!Expr.isExpr(length)) {
length = lit(length)._expr;
}

return wrap("strSlice", start, length);
},
split(by: string, options?) {
Expand Down
18 changes: 13 additions & 5 deletions polars/lazy/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,15 +305,23 @@ export function concatList(...exprs): Expr {
}

/** Concat Utf8 Series in linear time. Non utf8 columns are cast to utf8. */
export function concatString(opts: { exprs: ExprOrString[]; sep: string });
export function concatString(exprs: ExprOrString[], sep?: string);
export function concatString(opts, sep = ",") {
export function concatString(opts: {
exprs: ExprOrString[];
sep: string;
ignoreNulls?: boolean;
});
export function concatString(
exprs: ExprOrString[],
sep?: string,
ignoreNulls?: boolean,
);
export function concatString(opts, sep = ",", ignoreNulls = true) {
if (opts?.exprs) {
return concatString(opts.exprs, opts.sep);
return concatString(opts.exprs, opts.sep, opts.ignoreNulls);
}
const items = selectionToExprList(opts as any, false);

return (Expr as any)(pli.concatStr(items, sep));
return (Expr as any)(pli.concatStr(items, sep, ignoreNulls));
}

/** Count the number of values in this column. */
Expand Down
16 changes: 7 additions & 9 deletions polars/series/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,8 @@ export interface Series
slice(start: number, length?: number): Series;
/**
* __Sort this Series.__
* @param reverse - Reverse sort
* @param descending - Sort in descending order.
* @param nullsLast - Place nulls at the end.
* @example
* ```
* s = pl.Series("a", [1, 3, 4, 2])
Expand All @@ -878,7 +879,7 @@ export interface Series
* 3
* 4
* ]
* s.sort(true)
* s.sort({descending: true})
* shape: (4,)
* Series: 'a' [i64]
* [
Expand All @@ -890,8 +891,7 @@ export interface Series
* ```
*/
sort(): Series;
sort(reverse?: boolean): Series;
sort(options: { reverse: boolean }): Series;
sort(options: { descending?: boolean; nullsLast?: boolean }): Series;
/**
* Reduce this Series to the sum value.
* @example
Expand Down Expand Up @@ -1684,12 +1684,10 @@ export function _Series(_s: any): Series {

return wrap("slice", offset.offset, offset.length);
},
sort(reverse?) {
if (typeof reverse === "boolean") {
return wrap("sort", reverse);
}
sort(options?) {
options = { descending: false, nullsLast: false, ...(options ?? {}) };

return wrap("sort", reverse?.reverse ?? false);
return wrap("sort", options.descending, options.nullsLast);
},
sub(field) {
return dtypeWrap("Sub", field);
Expand Down
5 changes: 3 additions & 2 deletions polars/series/list.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Series, _Series } from ".";
import { exprToLitOrExpr } from "..";
import { col } from "../lazy/functions";
import { ListFunctions } from "../shared_traits";

Expand Down Expand Up @@ -49,8 +50,8 @@ export const SeriesListFunctions = (_s): ListFunctions<Series> => {
tail(n = 5) {
return this.slice(-n, n);
},
join(separator = ",") {
return wrap("join", separator);
join(options?) {
return wrap("join", options);
},
last() {
return wrap("get", -1);
Expand Down
Loading

0 comments on commit bf78f49

Please sign in to comment.