Skip to content

Commit 9a65b9d

Browse files
Using rs-0.40 (pola-rs#211)
* Upgrading to rs-0.4.0 and new toolchain * Fixing read_csv and other errors * Addressing PR comments * Refactoring arguments for read_csv to DF * Upgrading yarn * Enabling corepack * Moving corepack up before setup * Update src/dataframe.rs Co-authored-by: Cory Grinstead <[email protected]> * Uncommenting skipped test * Adding toDummies * Adding nodeLinker --------- Co-authored-by: Cory Grinstead <[email protected]>
1 parent 8944375 commit 9a65b9d

22 files changed

+1373
-2232
lines changed

.github/workflows/docs.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
- name: Install latest Rust nightly
1515
uses: dtolnay/rust-toolchain@stable
1616
with:
17-
toolchain: nightly-2024-04-15
17+
toolchain: nightly-2024-05-14
1818
components: rustfmt, clippy
1919
- name: Install ghp-import
2020
uses: actions/setup-python@v5

.github/workflows/test-js.yaml

+6-3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ jobs:
1010
node: ["18", "20"]
1111
steps:
1212
- uses: actions/checkout@v4
13+
- name: Enable Corepack
14+
run: corepack enable
1315
- uses: actions/setup-node@v4
1416
with:
1517
node-version: ${{ matrix.node }}
@@ -18,9 +20,10 @@ jobs:
1820
- name: Install latest Rust nightly
1921
uses: dtolnay/rust-toolchain@stable
2022
with:
21-
toolchain: nightly-2024-04-15
23+
toolchain: nightly-2024-05-14
2224
components: rustfmt, clippy
23-
- run: yarn --version
25+
- name: Check yarn version
26+
run: yarn --version
2427
- name: Install Node Dependencies
2528
run: yarn install
2629
- name: Build Binary
@@ -43,7 +46,7 @@ jobs:
4346
- name: Install latest Rust nightly
4447
uses: dtolnay/rust-toolchain@stable
4548
with:
46-
toolchain: nightly-2024-04-15
49+
toolchain: nightly-2024-05-14
4750
components: rustfmt, clippy
4851
- name: Bun version
4952
uses: oven-sh/setup-bun@v1

.nvmrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
16
1+
20

.yarn/releases/yarn-3.6.1.cjs

-874
This file was deleted.

.yarnrc.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
nodeLinker: node-modules
2-
3-
yarnPath: .yarn/releases/yarn-3.6.1.cjs
1+
compressionLevel: mixed
2+
enableGlobalCache: false
3+
nodeLinker: node-modules

Cargo.toml

+6-6
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ crate-type = ["cdylib", "lib"]
1515
[dependencies]
1616
ahash = "0.8.11"
1717
bincode = "1.3.3"
18-
napi = { version = "2.16.4", default-features = false, features = [
18+
napi = { version = "2.16.6", default-features = false, features = [
1919
"napi8",
2020
"serde-json",
2121
] }
22-
napi-derive = { version = "2.16.3", default-features = false }
23-
polars-core = { git = "https://github.com/pola-rs/polars.git", rev = "4c57688d204fad3d0d5e4586ecd0405ead7baeb2", default-features = false }
24-
polars-io = { git = "https://github.com/pola-rs/polars.git", rev = "4c57688d204fad3d0d5e4586ecd0405ead7baeb2", default-features = false }
25-
polars-lazy = { git = "https://github.com/pola-rs/polars.git", rev = "4c57688d204fad3d0d5e4586ecd0405ead7baeb2", default-features = false }
22+
napi-derive = { version = "2.16.5", default-features = false }
23+
polars-core = { git = "https://github.com/pola-rs/polars.git", rev = "7bc70141f4dad7863a2026849522551abb274f00", default-features = false }
24+
polars-io = { git = "https://github.com/pola-rs/polars.git", rev = "7bc70141f4dad7863a2026849522551abb274f00", default-features = false }
25+
polars-lazy = { git = "https://github.com/pola-rs/polars.git", rev = "7bc70141f4dad7863a2026849522551abb274f00", default-features = false }
2626
thiserror = "1"
2727
smartstring = { version = "1" }
2828
serde_json = { version = "1" }
@@ -160,7 +160,7 @@ features = [
160160
"azure"
161161
]
162162
git = "https://github.com/pola-rs/polars.git"
163-
rev = "4c57688d204fad3d0d5e4586ecd0405ead7baeb2"
163+
rev = "7bc70141f4dad7863a2026849522551abb274f00"
164164

165165
[build-dependencies]
166166
napi-build = "2.1.3"

__tests__/dataframe.test.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,8 @@ describe("dataframe", () => {
5757
describe: ["mean", "std", "min", "max", "median"],
5858
a: [2, 1, 1, 3, 2],
5959
b: [null, null, "a", "c", null],
60-
c: [0.6666666666666666, 0.5773502588272095, 0, 1, 1],
60+
c: [0.6666666666666666, 0.5773502691896258, 0, 1, 1],
6161
});
62-
6362
expect(actual).toFrameEqual(expected);
6463
});
6564
test("drop", () => {
@@ -1504,8 +1503,9 @@ describe("join", () => {
15041503
const expected = pl.DataFrame({
15051504
foo: [1, 2, 3, null],
15061505
bar: [6, 7, 8, null],
1507-
ham: ["a", "b", "c", "d"],
1506+
ham: ["a", "b", "c", null],
15081507
apple: ["x", null, null, "y"],
1508+
ham_right: ["a", null, null, "d"],
15091509
foo_right: [1, null, null, 10],
15101510
});
15111511
expect(actual).toFrameEqual(expected);

__tests__/lazyframe.test.ts

+7-6
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ describe("lazyframe", () => {
3636
})
3737
.lazy();
3838
let actual = df.describeOptimizedPlan().replace(/\s+/g, " ");
39-
const expected = `DF ["foo", "bar"]; PROJECT */2 COLUMNS; SELECTION: "None"`;
39+
const expected = `DF ["foo", "bar"]; PROJECT */2 COLUMNS; SELECTION: None`;
4040
expect(actual).toEqual(expected);
4141
actual = df.describePlan().replace(/\s+/g, " ");
4242
expect(actual).toEqual(expected);
@@ -601,11 +601,12 @@ describe("lazyframe", () => {
601601
})
602602
.collectSync();
603603
const expected = pl.DataFrame({
604-
foo: [1, 2, 3, null],
605-
bar: [6, 7, 8, null],
606-
ham: ["a", "b", "c", "d"],
607-
apple: ["x", null, null, "y"],
608-
fooright: [1, null, null, 10],
604+
foo: [1, null, 2, 3],
605+
bar: [6, null, 7, 8],
606+
ham: ["a", null, "b", "c"],
607+
apple: ["x", "y", null, null],
608+
hamright: ["a", "d", null, null],
609+
fooright: [1, 10, null, null],
609610
});
610611
expect(actual).toFrameEqualIgnoringOrder(expected);
611612
});

__tests__/serde.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ describe("serde", () => {
1212
expect(actual).toFrameEqual(expected);
1313
});
1414

15-
test.skip("lazyframe:bincode", () => {
15+
test("lazyframe:bincode", () => {
1616
const df = pl.scanCSV(csvpath);
1717
const buf = df.serialize("bincode");
1818
const deserde = pl.LazyDataFrame.deserialize(buf, "bincode");

__tests__/series.test.ts

+15
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,21 @@ describe("series", () => {
664664
new Uint8Array([1, 2, 3, 5]),
665665
);
666666
});
667+
test("toDummies", () => {
668+
const s = pl.Series("a", [1, 2, 3]);
669+
let actual = s.toDummies();
670+
let expected = pl.DataFrame(
671+
{ "a_1.0": [1, 0, 0], "a_2.0": [0, 1, 0], "a_3.0": [0, 0, 1] },
672+
{ schema: { "a_1.0": pl.UInt8, "a_2.0": pl.UInt8, "a_3.0": pl.UInt8 } },
673+
);
674+
expect(actual).toFrameEqual(expected);
675+
actual = s.toDummies(":", true);
676+
expected = pl.DataFrame(
677+
{ "a:2.0": [0, 1, 0], "a:3.0": [0, 0, 1] },
678+
{ schema: { "a:2.0": pl.UInt8, "a:3.0": pl.UInt8 } },
679+
);
680+
expect(actual).toFrameEqual(expected);
681+
});
667682
});
668683
describe("comparators & math", () => {
669684
test("add/plus", () => {

package.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -54,20 +54,20 @@
5454
"precommit": "yarn lint && yarn test"
5555
},
5656
"devDependencies": {
57-
"@biomejs/biome": "^1.7.0",
58-
"@napi-rs/cli": "^2.18.2",
57+
"@biomejs/biome": "^1.7.3",
58+
"@napi-rs/cli": "^2.18.3",
5959
"@types/chance": "^1.1.6",
6060
"@types/jest": "^29.5.12",
61-
"@types/node": "^20.12.7",
61+
"@types/node": "^20.12.12",
6262
"chance": "^1.1.11",
6363
"jest": "^29.7.0",
6464
"source-map-support": "^0.5.21",
65-
"ts-jest": "^29.1.2",
65+
"ts-jest": "^29.1.3",
6666
"ts-node": "^10.9.2",
6767
"typedoc": "^0.25.13",
6868
"typescript": "5.4.5"
6969
},
70-
"packageManager": "yarn@4.0.2",
70+
"packageManager": "yarn@4.2.2",
7171
"workspaces": [
7272
"benches"
7373
]

polars/lazy/expr/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -932,7 +932,7 @@ export const _Expr = (_expr: any): Expr => {
932932
throw new Error("window size is required");
933933
}
934934
const callOpts = {
935-
windowSize: `${windowSize}i`,
935+
windowSize: windowSize,
936936
weights: opts?.["weights"] ?? weights,
937937
minPeriods: opts?.["minPeriods"] ?? minPeriods ?? windowSize,
938938
center: opts?.["center"] ?? center ?? false,
@@ -1459,7 +1459,7 @@ export const _Expr = (_expr: any): Expr => {
14591459
"rollingQuantile",
14601460
val.quantile,
14611461
val.interpolation ?? "nearest",
1462-
`${windowSize}i`,
1462+
windowSize,
14631463
val?.["weights"] ?? weights ?? null,
14641464
val?.["minPeriods"] ?? minPeriods ?? windowSize,
14651465
val?.["center"] ?? center ?? false,

polars/lazy/expr/string.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ export const ExprStringFunctions = (_expr: any): StringNamespace => {
375375
return wrap("strJsonDecode", dtype, inferSchemaLength);
376376
},
377377
jsonPathMatch(pat: string) {
378-
return wrap("strJsonPathMatch", pat);
378+
return wrap("strJsonPathMatch", [pat]);
379379
},
380380
lengths() {
381381
return wrap("strLengths");

polars/series/index.ts

+37
Original file line numberDiff line numberDiff line change
@@ -1040,6 +1040,40 @@ export interface Series
10401040
*/
10411041
toTypedArray(): any;
10421042

1043+
/**
1044+
* Get dummy/indicator variables.
1045+
* @param separator: str = "_",
1046+
* @param dropFirst: bool = False
1047+
*
1048+
* @example
1049+
* const s = pl.Series("a", [1, 2, 3])
1050+
>>> s.toDummies()
1051+
shape: (3, 3)
1052+
┌─────┬─────┬─────┐
1053+
│ a_1 ┆ a_2 ┆ a_3 │
1054+
│ --- ┆ --- ┆ --- │
1055+
│ u8 ┆ u8 ┆ u8 │
1056+
╞═════╪═════╪═════╡
1057+
│ 1 ┆ 0 ┆ 0 │
1058+
│ 0 ┆ 1 ┆ 0 │
1059+
│ 0 ┆ 0 ┆ 1 │
1060+
└─────┴─────┴─────┘
1061+
1062+
>>> s.toDummies(":", true)
1063+
shape: (3, 2)
1064+
┌─────┬─────┐
1065+
│ a:2 ┆ a:3 │
1066+
│ --- ┆ --- │
1067+
│ u8 ┆ u8 │
1068+
╞═════╪═════╡
1069+
│ 0 ┆ 0 │
1070+
│ 1 ┆ 0 │
1071+
│ 0 ┆ 1 │
1072+
└─────┴─────┘
1073+
*
1074+
*/
1075+
toDummies(separator?: string, dropFirst?: boolean): DataFrame;
1076+
10431077
/**
10441078
* _Returns a Javascript object representation of Series_
10451079
* Often this is much faster than the iterator, or `values` method
@@ -1715,6 +1749,9 @@ export function _Series(_s: any): Series {
17151749
}
17161750
throw new Error("data contains nulls, unable to convert to TypedArray");
17171751
},
1752+
toDummies(separator = "_", dropFirst = false) {
1753+
return _DataFrame(_s.toDummies(separator, dropFirst));
1754+
},
17181755
toFrame() {
17191756
return _DataFrame(new pli.JsDataFrame([_s]));
17201757
},

polars/series/string.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ export const SeriesStringFunctions = (_s: any): StringNamespace => {
328328
return wrap("strJsonDecode", dtype, inferSchemaLength);
329329
},
330330
jsonPathMatch(pat: string) {
331-
return wrap("strJsonPathMatch", pat);
331+
return wrap("strJsonPathMatch", [pat]);
332332
},
333333
lengths() {
334334
return wrap("strLengths");

rust-toolchain

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
nightly-2024-04-15
1+
nightly-2024-05-14

src/conversion.rs

+6-27
Original file line numberDiff line numberDiff line change
@@ -498,41 +498,20 @@ impl FromNapiValue for Wrap<u64> {
498498

499499
#[napi(object)]
500500
pub struct JsRollingOptions {
501-
pub window_size: String,
501+
pub window_size: i16,
502502
pub weights: Option<Vec<f64>>,
503503
pub min_periods: i64,
504504
pub center: bool,
505505
pub ddof: Option<u8>,
506506
}
507507

508-
impl From<JsRollingOptions> for RollingOptionsImpl<'static> {
508+
impl From<JsRollingOptions> for RollingOptionsFixedWindow {
509509
fn from(o: JsRollingOptions) -> Self {
510-
RollingOptionsImpl {
511-
window_size: Duration::parse(&o.window_size),
510+
RollingOptionsFixedWindow {
511+
window_size: o.window_size as usize,
512512
weights: o.weights,
513513
min_periods: o.min_periods as usize,
514514
center: o.center,
515-
by: None,
516-
tu: None,
517-
tz: None,
518-
closed_window: None,
519-
fn_params: Some(Arc::new(RollingVarParams {
520-
ddof: o.ddof.unwrap_or(1),
521-
}) as Arc<dyn Any + Send + Sync>),
522-
..Default::default()
523-
}
524-
}
525-
}
526-
527-
impl From<JsRollingOptions> for RollingOptions {
528-
fn from(o: JsRollingOptions) -> Self {
529-
RollingOptions {
530-
window_size: Duration::parse(&o.window_size),
531-
weights: o.weights,
532-
min_periods: o.min_periods as usize,
533-
center: o.center,
534-
by: None,
535-
closed_window: None,
536515
fn_params: Some(Arc::new(RollingVarParams {
537516
ddof: o.ddof.unwrap_or(1),
538517
}) as Arc<dyn Any + Send + Sync>),
@@ -550,7 +529,7 @@ pub struct JsRowCount {
550529
impl From<JsRowCount> for RowIndex {
551530
fn from(o: JsRowCount) -> Self {
552531
RowIndex {
553-
name: o.name,
532+
name: o.name.into(),
554533
offset: o.offset,
555534
}
556535
}
@@ -832,7 +811,7 @@ impl FromNapiValue for Wrap<JoinType> {
832811
let parsed = match s.as_ref() {
833812
"inner" => JoinType::Inner,
834813
"left" => JoinType::Left,
835-
"outer" => JoinType::Outer { coalesce: true },
814+
"outer" => JoinType::Outer,
836815
"semi" => JoinType::Semi,
837816
"anti" => JoinType::Anti,
838817
"cross" => JoinType::Cross,

0 commit comments

Comments
 (0)