Polars
Usage
Importing
// esm
import pl from 'nodejs-polars';
// require
const pl = require('nodejs-polars');
Series
> const fooSeries = pl.Series("foo", [1, 2, 3])
> fooSeries.sum()
6
// a lot operations support both positional and named arguments
// you can see the full specs in the docs or the type definitions
> fooSeries.sort(true)
> fooSeries.sort({reverse: true})
shape: (3,)
Series: 'foo' [f64]
[
3
2
1
]
> fooSeries.toArray()
[1, 2, 3]
// Series are 'Iterables' so you can use javascript iterable syntax on them
> [...fooSeries]
[1, 2, 3]
> fooSeries[0]
1
DataFrame
>const df = pl.DataFrame(
... {
... A: [1, 2, 3, 4, 5],
... fruits: ["banana", "banana", "apple", "apple", "banana"],
... B: [5, 4, 3, 2, 1],
... cars: ["beetle", "audi", "beetle", "beetle", "beetle"],
... }
... )
> df.sort("fruits").select(
... "fruits",
... "cars",
... pl.lit("fruits").alias("literal_string_fruits"),
... pl.col("B").filter(pl.col("cars").eq(lit("beetle"))).sum(),
... pl.col("A").filter(pl.col("B").gt(2)).sum().over("cars").alias("sum_A_by_cars"),
... pl.col("A").sum().over("fruits").alias("sum_A_by_fruits"),
... pl.col("A").reverse().over("fruits").flatten().alias("rev_A_by_fruits")
... )
shape: (5, 8)
ββββββββββββ¬βββββββββββ¬βββββββββββββββ¬ββββββ¬ββββββββββββββ¬ββββββββββββββ¬ββββββββββββββ
β fruits β cars β literal_stri β B β sum_A_by_ca β sum_A_by_fr β rev_A_by_fr β
β --- β --- β ng_fruits β --- β rs β uits β uits β
β str β str β --- β i64 β --- β --- β --- β
β β β str β β i64 β i64 β i64 β
ββββββββββββͺβββββββββββͺβββββββββββββββͺββββββͺββββββββββββββͺββββββββββββββͺββββββββββββββ‘
β "apple" β "beetle" β "fruits" β 11 β 4 β 7 β 4 β
ββββββββββββΌβββββββββββΌβββββββββββββββΌββββββΌββββββββββββββΌββββββββββββββΌββββββββββββββ€
β "apple" β "beetle" β "fruits" β 11 β 4 β 7 β 3 β
ββββββββββββΌβββββββββββΌβββββββββββββββΌββββββΌββββββββββββββΌββββββββββββββΌββββββββββββββ€
β "banana" β "beetle" β "fruits" β 11 β 4 β 8 β 5 β
ββββββββββββΌβββββββββββΌβββββββββββββββΌββββββΌββββββββββββββΌββββββββββββββΌββββββββββββββ€
β "banana" β "audi" β "fruits" β 11 β 2 β 8 β 2 β
ββββββββββββΌβββββββββββΌβββββββββββββββΌββββββΌββββββββββββββΌββββββββββββββΌββββββββββββββ€
β "banana" β "beetle" β "fruits" β 11 β 4 β 8 β 1 β
ββββββββββββ΄βββββββββββ΄βββββββββββββββ΄ββββββ΄ββββββββββββββ΄ββββββββββββββ΄ββββββββββββββ
> df["cars"] // or df.getColumn("cars")
shape: (5,)
Series: 'cars' [str]
[
"beetle"
"beetle"
"beetle"
"audi"
"beetle"
]
Node setup
Install the latest polars version with:
$ yarn add nodejs-polars # yarn
$ npm i -s nodejs-polars # npm
Releases happen quite often (weekly / every few days) at the moment, so updating polars regularly to get the latest bugfixes / features might not be a bad idea.
Minimum Requirements
- Node version
>=16
- Rust version
>=1.59
- Only needed for development
Documentation
Want to know about all the features Polars supports? Read the docs!
Python
- Installation guide:
$ pip3 install polars
- Python documentation
- User guide
Rust
Node
- Installation guide:
$ yarn install nodejs-polars
- Node documentation
- User guide
Contribution
Want to contribute? Read our contribution guideline.
[Node]: compile polars from source
If you want a bleeding edge release or maximal performance you should compile polars from source.
- Install the latest Rust compiler
- Run
npm|yarn install
- Choose any of:
- Fastest binary, very long compile times:
$ cd nodejs-polars && yarn build && yarn build:ts # this will generate a /bin directory with the compiles TS code, as well as the rust binary
- Debugging, fastest compile times but slow & large binary:
$ cd nodejs-polars && yarn build:debug && yarn build:ts # this will generate a /bin directory with the compiles TS code, as well as the rust binary
- Fastest binary, very long compile times:
Acknowledgements
Development of Polars is proudly powered by