-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
9 changed files
with
222 additions
and
2 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,6 @@ | ||
/target | ||
**/*.rs.bk | ||
Cargo.lock | ||
bin/ | ||
pkg/ | ||
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,48 @@ | ||
[package] | ||
name = "polars" | ||
version = "0.1.0" | ||
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] | ||
default = ["console_error_panic_hook"] | ||
|
||
[dependencies] | ||
wasm-bindgen = "0.2" | ||
# The `console_error_panic_hook` crate provides better debugging of panics by | ||
# logging them with `console.error`. This is great for development, but requires | ||
# all the `std::fmt` and `std::panicking` infrastructure, so isn't great for | ||
# code size when deploying. | ||
console_error_panic_hook = { version = "0.1.6", optional = true } | ||
|
||
# `wee_alloc` is a tiny allocator for wasm that is only ~1K in code size | ||
# compared to the default allocator's ~10K. It is slower than the default | ||
# allocator, however. | ||
# | ||
# Unfortunately, `wee_alloc` requires nightly Rust when targeting wasm for now. | ||
wee_alloc = { version = "0.4.5", optional = true } | ||
|
||
[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,3 @@ | ||
|
||
build: | ||
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,20 @@ | ||
mod series; | ||
mod utils; | ||
|
||
use wasm_bindgen::prelude::*; | ||
|
||
// When the `wee_alloc` feature is enabled, use `wee_alloc` as the global | ||
// allocator. | ||
#[cfg(feature = "wee_alloc")] | ||
#[global_allocator] | ||
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT; | ||
|
||
#[wasm_bindgen] | ||
extern "C" { | ||
fn alert(s: &str); | ||
} | ||
|
||
#[wasm_bindgen] | ||
pub fn greet() { | ||
alert("Hello, {{project-name}}!"); | ||
} |
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,119 @@ | ||
use polars_core::prelude::*; | ||
use std::ops::{BitAnd, BitOr}; | ||
use wasm_bindgen::prelude::*; | ||
|
||
#[wasm_bindgen(js_name = Series)] | ||
pub struct JsSeries { | ||
series: Series, | ||
} | ||
|
||
impl From<Series> for JsSeries { | ||
fn from(series: Series) -> Self { | ||
Self { series } | ||
} | ||
} | ||
|
||
#[wasm_bindgen] | ||
impl JsSeries { | ||
#[wasm_bindgen(constructor, js_name = newFlt)] | ||
pub fn new_flt(name: &str, values: &[f64]) -> Self { | ||
Self { | ||
series: Series::new(name, values), | ||
} | ||
} | ||
|
||
#[wasm_bindgen(constructor, js_name = newInt)] | ||
pub fn new_int(name: &str, values: &[i64]) -> Self { | ||
Self { | ||
series: Series::new(name, values), | ||
} | ||
} | ||
|
||
#[wasm_bindgen(constructor, js_name = newStr)] | ||
pub fn new_str(name: &str, values: Box<[JsValue]>) -> Self { | ||
let ca: Utf8Chunked = NewChunkedArray::<_, String>::new_from_iter( | ||
name, | ||
values.iter().map(|v| v.as_string().unwrap()), | ||
); | ||
Self { series: ca.into() } | ||
} | ||
|
||
#[wasm_bindgen(method)] | ||
pub fn rechunk(&mut self, in_place: bool) -> Option<JsSeries> { | ||
let series = self.series.rechunk(); | ||
if in_place { | ||
self.series = series; | ||
None | ||
} else { | ||
Some(series.into()) | ||
} | ||
} | ||
|
||
#[wasm_bindgen(method)] | ||
pub fn bitand(&self, other: &JsSeries) -> Self { | ||
let s = self | ||
.series | ||
.bool() | ||
.expect("boolean") | ||
.bitand(other.series.bool().expect("boolean")) | ||
.into_series(); | ||
s.into() | ||
} | ||
|
||
#[wasm_bindgen(method)] | ||
pub fn bitor(&self, other: &JsSeries) -> Self { | ||
let s = self | ||
.series | ||
.bool() | ||
.expect("boolean") | ||
.bitor(other.series.bool().expect("boolean")) | ||
.into_series(); | ||
s.into() | ||
} | ||
|
||
#[wasm_bindgen(method)] | ||
pub fn cum_sum(&self, reverse: bool) -> Self { | ||
self.series.cum_sum(reverse).into() | ||
} | ||
|
||
#[wasm_bindgen(method)] | ||
pub fn cum_max(&self, reverse: bool) -> Self { | ||
self.series.cum_max(reverse).into() | ||
} | ||
|
||
#[wasm_bindgen(method)] | ||
pub fn cum_min(&self, reverse: bool) -> Self { | ||
self.series.cum_min(reverse).into() | ||
} | ||
|
||
#[wasm_bindgen(method)] | ||
pub fn chunk_lengths(&self) -> Vec<usize> { | ||
self.series.chunk_lengths().clone() | ||
} | ||
|
||
#[wasm_bindgen(method)] | ||
pub fn name(&self) -> String { | ||
self.series.name().into() | ||
} | ||
|
||
#[wasm_bindgen(method)] | ||
pub fn rename(&mut self, name: &str) { | ||
self.series.rename(name); | ||
} | ||
|
||
#[wasm_bindgen(method)] | ||
pub fn mean(&self) -> Option<f64> { | ||
self.series.mean() | ||
} | ||
|
||
#[wasm_bindgen(method)] | ||
pub fn n_chunks(&self) -> usize { | ||
self.series.n_chunks() | ||
} | ||
|
||
#[wasm_bindgen(method)] | ||
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,10 @@ | ||
pub fn set_panic_hook() { | ||
// When the `console_error_panic_hook` feature is enabled, we can call the | ||
// `set_panic_hook` function at least once during initialization, and then | ||
// we will get better error messages if our code ever panics. | ||
// | ||
// For more details see | ||
// https://github.com/rustwasm/console_error_panic_hook#readme | ||
#[cfg(feature = "console_error_panic_hook")] | ||
console_error_panic_hook::set_once(); | ||
} |
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", | ||
|