-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cannot accept `Vec<T>` so we need to assign `Series`
- Loading branch information
Showing
11 changed files
with
146 additions
and
38 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
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
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
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,35 @@ | ||
use polars_core::prelude::DataFrame as PDataFrame; | ||
use polars_core::prelude::Series as PSeries; | ||
use super::{ | ||
JsPolarsError, | ||
series::*, | ||
}; | ||
use wasm_bindgen::prelude::*; | ||
use wasm_bindgen::JsCast; | ||
|
||
#[wasm_bindgen] | ||
pub struct DataFrame { | ||
df: PDataFrame, | ||
} | ||
|
||
impl From<PDataFrame> for DataFrame { | ||
fn from(df: PDataFrame) -> Self { | ||
Self { df } | ||
} | ||
} | ||
|
||
|
||
#[wasm_bindgen] | ||
impl DataFrame { | ||
|
||
#[wasm_bindgen(constructor)] | ||
pub fn new() -> Self { | ||
PDataFrame::new_no_checks(vec![]).into() | ||
} | ||
|
||
pub fn assign(&self, series: Series) -> Result<DataFrame, JsValue> { | ||
let mut df = self.df.clone(); | ||
df.with_column(series.series).map_err(JsPolarsError::from)?; | ||
Ok(df.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 |
---|---|---|
@@ -1,4 +1,36 @@ | ||
mod series; | ||
mod dataframe; | ||
|
||
use wasm_bindgen::prelude::*; | ||
use polars_core::error::PolarsError; | ||
|
||
#[wasm_bindgen] | ||
extern "C" { | ||
#[wasm_bindgen(js_namespace = console)] | ||
fn log(s: &str); | ||
} | ||
|
||
#[macro_export] | ||
macro_rules! console_log { | ||
// Note that this is using the `log` function imported above during | ||
// `bare_bones` | ||
($($t:tt)*) => (log(&format_args!($($t)*).to_string())) | ||
} | ||
|
||
#[global_allocator] | ||
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT; | ||
|
||
|
||
pub struct JsPolarsError(PolarsError); | ||
|
||
impl From<PolarsError> for JsPolarsError { | ||
fn from(e: PolarsError) -> Self { | ||
Self(e) | ||
} | ||
} | ||
|
||
impl From<JsPolarsError> for JsValue { | ||
fn from(e: JsPolarsError) -> Self { | ||
format!("{:?}", e.0).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
This file was deleted.
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
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
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
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