-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
182 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/target | ||
**/*.rs.bk | ||
Cargo.lock | ||
bin/ | ||
pkg/ | ||
node_modules/ | ||
wasm-pack.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
[package] | ||
name = "polars" | ||
version = "0.0.1" | ||
authors = ["Ritchie Vink"] | ||
edition = "2018" | ||
repository = "https://github.com/ritchie46/polars" | ||
license = "MIT" | ||
documentation = "https://ritchie46.github.io/polars-book/" | ||
homepage = "https://github.com/ritchie46/polars" | ||
|
||
[lib] | ||
crate-type = ["cdylib", "rlib"] | ||
|
||
[features] | ||
|
||
[dependencies] | ||
wasm-bindgen = "0.2.34" | ||
|
||
wee_alloc = { version = "0.4.5" } | ||
|
||
[dependencies.polars-core] | ||
path = "../polars/polars-core" | ||
default-features = false | ||
features = [ | ||
"strings", | ||
"temporal", | ||
"performant", | ||
] | ||
|
||
[dev-dependencies] | ||
wasm-bindgen-test = "0.3.13" | ||
|
||
[profile.release] | ||
# Tell `rustc` to optimize for small code size. | ||
opt-level = "s" | ||
|
||
[workspace] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
build-dev: | ||
wasm-pack build --dev --target nodejs | ||
|
||
build-prod: | ||
wasm-pack build --target nodejs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
const pl = require("./pkg") | ||
const assert = require("assert") | ||
|
||
let s = new pl.Series("a", [1, 2, 3]) | ||
assert(s.mean() === 2) | ||
console.log(s.mean()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
mod series; | ||
use wasm_bindgen::prelude::*; | ||
|
||
#[global_allocator] | ||
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
use polars_core::prelude::{ | ||
Series as PSeries, Utf8Chunked, NewChunkedArray, Float64Chunked, IntoSeries | ||
}; | ||
use std::ops::{BitAnd, BitOr}; | ||
use wasm_bindgen::prelude::*; | ||
|
||
#[wasm_bindgen] | ||
pub struct Series { | ||
series: PSeries, | ||
} | ||
|
||
impl From<PSeries> for Series { | ||
fn from(series: PSeries) -> Self { | ||
Self { series } | ||
} | ||
} | ||
|
||
#[wasm_bindgen] | ||
impl Series { | ||
#[wasm_bindgen(constructor)] | ||
pub fn new(name: &str, values: Box<[JsValue]>) -> Series { | ||
let first = &values[0]; | ||
if first.as_f64().is_some() { | ||
let series = Float64Chunked::new_from_opt_iter(name, values.iter().map(|v| v.as_f64())).into_series(); | ||
Series { | ||
series | ||
} | ||
} else if first.as_string().is_some() { | ||
let series = Utf8Chunked::new_from_opt_iter(name, values.iter().map(|v| v.as_string())).into_series(); | ||
Series { | ||
series | ||
} | ||
} else { | ||
unimplemented!() | ||
} | ||
} | ||
|
||
pub fn rechunk(&mut self, in_place: bool) -> Option<Series> { | ||
let series = self.series.rechunk(); | ||
if in_place { | ||
self.series = series; | ||
None | ||
} else { | ||
Some(series.into()) | ||
} | ||
} | ||
|
||
pub fn bitand(&self, other: &Series) -> Self { | ||
let s = self | ||
.series | ||
.bool() | ||
.expect("boolean") | ||
.bitand(other.series.bool().expect("boolean")) | ||
.into_series(); | ||
s.into() | ||
} | ||
|
||
pub fn bitor(&self, other: &Series) -> Self { | ||
let s = self | ||
.series | ||
.bool() | ||
.expect("boolean") | ||
.bitor(other.series.bool().expect("boolean")) | ||
.into_series(); | ||
s.into() | ||
} | ||
|
||
pub fn cum_sum(&self, reverse: bool) -> Self { | ||
self.series.cum_sum(reverse).into() | ||
} | ||
|
||
pub fn cum_max(&self, reverse: bool) -> Self { | ||
self.series.cum_max(reverse).into() | ||
} | ||
|
||
pub fn cum_min(&self, reverse: bool) -> Self { | ||
self.series.cum_min(reverse).into() | ||
} | ||
|
||
pub fn chunk_lengths(&self) -> Vec<usize> { | ||
self.series.chunk_lengths().clone() | ||
} | ||
|
||
pub fn name(&self) -> String { | ||
self.series.name().into() | ||
} | ||
|
||
pub fn rename(&mut self, name: &str) { | ||
self.series.rename(name); | ||
} | ||
|
||
pub fn mean(&self) -> Option<f64> { | ||
self.series.mean() | ||
} | ||
|
||
pub fn n_chunks(&self) -> usize { | ||
self.series.n_chunks() | ||
} | ||
|
||
pub fn limit(&self, num_elements: usize) -> Self { | ||
let series = self.series.limit(num_elements); | ||
series.into() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
//! Test suite for the Web and headless browsers. | ||
|
||
#![cfg(target_arch = "wasm32")] | ||
|
||
extern crate wasm_bindgen_test; | ||
use wasm_bindgen_test::*; | ||
|
||
wasm_bindgen_test_configure!(run_in_browser); | ||
|
||
#[wasm_bindgen_test] | ||
fn pass() { | ||
assert_eq!(1 + 1, 2); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,7 @@ features = [ | |
"random", | ||
"object", | ||
"ipc", | ||
"csv-file", | ||
"pretty_fmt", | ||
"mimalloc", | ||
"performant", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters