Skip to content

Commit

Permalink
Upgrading to rs-0.43.1 (#267)
Browse files Browse the repository at this point in the history
Upgrading to rs-0.43.1
  • Loading branch information
Bidek56 authored Sep 16, 2024
1 parent 5fade25 commit 690dbc3
Show file tree
Hide file tree
Showing 17 changed files with 509 additions and 187 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: Install latest Rust nightly
uses: dtolnay/rust-toolchain@stable
with:
toolchain: nightly-2024-07-26
toolchain: nightly-2024-08-26
components: rustfmt, clippy
- name: Install ghp-import
uses: actions/setup-python@v5
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test-js.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Install latest Rust nightly
uses: dtolnay/rust-toolchain@stable
with:
toolchain: nightly-2024-07-26
toolchain: nightly-2024-08-26
components: rustfmt, clippy
- name: Check yarn version
run: yarn --version
Expand All @@ -46,7 +46,7 @@ jobs:
- name: Install latest Rust nightly
uses: dtolnay/rust-toolchain@stable
with:
toolchain: nightly-2024-07-26
toolchain: nightly-2024-08-26
components: rustfmt, clippy
- name: Bun version
uses: oven-sh/setup-bun@v1
Expand Down
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ napi = { version = "2.16.9", default-features = false, features = [
"serde-json",
] }
napi-derive = { version = "2.16.11", default-features = false }
polars-core = { git = "https://github.com/pola-rs/polars.git", rev = "7686025ac7738607f2d4f6887e9a1313b7c8b1e2", default-features = false }
polars-io = { git = "https://github.com/pola-rs/polars.git", rev = "7686025ac7738607f2d4f6887e9a1313b7c8b1e2", default-features = false }
polars-lazy = { git = "https://github.com/pola-rs/polars.git", rev = "7686025ac7738607f2d4f6887e9a1313b7c8b1e2", default-features = false }
polars-core = { git = "https://github.com/pola-rs/polars.git", rev = "54218e7e35e3defd4b0801e820c56eea6b91e525", default-features = false }
polars-io = { git = "https://github.com/pola-rs/polars.git", rev = "54218e7e35e3defd4b0801e820c56eea6b91e525", default-features = false }
polars-lazy = { git = "https://github.com/pola-rs/polars.git", rev = "54218e7e35e3defd4b0801e820c56eea6b91e525", default-features = false }
thiserror = "1"
smartstring = { version = "1" }
serde_json = { version = "1" }
Expand Down Expand Up @@ -162,7 +162,7 @@ features = [
"azure"
]
git = "https://github.com/pola-rs/polars.git"
rev = "7686025ac7738607f2d4f6887e9a1313b7c8b1e2"
rev = "54218e7e35e3defd4b0801e820c56eea6b91e525"

[build-dependencies]
napi-build = "2.1.3"
Expand Down
6 changes: 3 additions & 3 deletions __tests__/dataframe.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1862,8 +1862,8 @@ describe("create", () => {
bool: pl.Bool,
date: pl.Date,
date_nulls: pl.Date,
datetime: pl.Datetime("ms"),
datetime_nulls: pl.Datetime("ms"),
datetime: pl.Datetime("ms", ""),
datetime_nulls: pl.Datetime("ms", ""),
string: pl.String,
string_nulls: pl.String,
categorical: pl.Categorical,
Expand Down Expand Up @@ -1983,7 +1983,7 @@ describe("create", () => {
expect(df.toRecords()).toEqual(expected);
expect(df.schema).toStrictEqual({
num: pl.Float64,
date: pl.Datetime("ms"),
date: pl.Datetime("ms", ""),
string: pl.String,
});
});
Expand Down
8 changes: 5 additions & 3 deletions __tests__/expr.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,11 @@ describe("expr", () => {
expect(actual).toFrameEqual(expected);
});
test("exp", () => {
const df = pl.DataFrame({ a: [1.0] });
const actual = df.select(pl.col("a").exp());
const expected = pl.DataFrame({ a: [Math.E] });
const df = pl.DataFrame({ a: [1] });
const actual = df.select(pl.col("a").exp().round(6));
const expected = pl.DataFrame({
a: [Math.round(Math.E * 1_000_000) / 1_000_000],
});
expect(actual).toFrameEqual(expected);
});
test("explode", () => {
Expand Down
41 changes: 32 additions & 9 deletions __tests__/series.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,13 +217,13 @@ describe("series", () => {

describe("create series", () => {
it.each`
values | dtype | type
${["foo", "bar", "baz"]} | ${pl.String} | ${"string"}
${[1, 2, 3]} | ${pl.Float64} | ${"number"}
${[1n, 2n, 3n]} | ${pl.UInt64} | ${"bigint"}
${[true, false]} | ${pl.Bool} | ${"boolean"}
${[]} | ${pl.Float64} | ${"empty"}
${[new Date(Date.now())]} | ${pl.Datetime("ms")} | ${"Date"}
values | dtype | type
${["foo", "bar", "baz"]} | ${pl.String} | ${"string"}
${[1, 2, 3]} | ${pl.Float64} | ${"number"}
${[1n, 2n, 3n]} | ${pl.UInt64} | ${"bigint"}
${[true, false]} | ${pl.Bool} | ${"boolean"}
${[]} | ${pl.Float64} | ${"empty"}
${[new Date(Date.now())]} | ${pl.Datetime("ms", "")} | ${"Date"}
`('defaults to $dtype for "$type"', ({ values, dtype }) => {
const name = chance.string();
const s = pl.Series(name, values);
Expand Down Expand Up @@ -588,12 +588,35 @@ describe("series", () => {
expect(actual).toFrameEqual(expected);
});
it("series:valueCounts", () => {
const actual = pl.Series("a", [1, 2, 2, 3]).valueCounts(true);
const expected = pl.DataFrame({
let actual = pl.Series("a", [1, 2, 2, 3]).valueCounts(true);
let expected = pl.DataFrame({
a: [2, 1, 3],
count: [2, 1, 1],
});
expect(actual).toFrameEqual(expected);

actual = pl
.Series("a", [1, 2, 2, 3])
.valueCounts(true, true, undefined, true);
expected = pl.DataFrame({
a: [2, 1, 3],
proportion: [0.5, 0.25, 0.25],
});
expect(actual).toFrameEqual(expected);

actual = pl.Series("a", [1, 2, 2, 3]).valueCounts(true, true, "foo", false);
expected = pl.DataFrame({
a: [2, 1, 3],
foo: [2, 1, 1],
});
expect(actual).toFrameEqual(expected);

actual = pl.Series("a", [1, 2, 2, 3]).valueCounts(true, true, "foo", true);
expected = pl.DataFrame({
a: [2, 1, 3],
foo: [0.5, 0.25, 0.25],
});
expect(actual).toFrameEqual(expected);
});
it("set: expected matches actual", () => {
const expected = pl.Series([99, 2, 3]);
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,14 @@
"@napi-rs/cli": "^2.18.4",
"@types/chance": "^1.1.6",
"@types/jest": "^29.5.12",
"@types/node": "^22.5.3",
"@types/node": "^22.5.4",
"chance": "^1.1.12",
"jest": "^29.7.0",
"source-map-support": "^0.5.21",
"ts-jest": "^29.2.5",
"ts-node": "^10.9.2",
"typedoc": "^0.26.6",
"typescript": "5.5.4"
"typedoc": "^0.26.7",
"typescript": "5.6.2"
},
"packageManager": "[email protected]",
"workspaces": [
Expand Down
2 changes: 1 addition & 1 deletion polars/series/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1801,7 +1801,7 @@ export function _Series(_s: any): Series {
name?: string,
normalize?: boolean,
) {
name = name ?? normalize ? "proportion" : "count";
name = name ?? (normalize ? "proportion" : "count");
return _DataFrame(
unwrap(
"valueCounts",
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1 +1 @@
nightly-2024-07-26
nightly-2024-08-26
53 changes: 21 additions & 32 deletions src/conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ use polars_io::RowIndex;
use std::any::Any;
use std::collections::HashMap;

use smartstring::alias::String as SmartString;

#[derive(Debug)]
pub struct Wrap<T: ?Sized>(pub T);

Expand Down Expand Up @@ -50,7 +48,7 @@ impl ToSeries for Array {
let av: Wrap<AnyValue> = self.get(i).unwrap().unwrap_or(Wrap(AnyValue::Null));
v.push(av.0);
}
Series::new("", v)
Series::new(PlSmallStr::EMPTY, v)
}
}

Expand All @@ -64,7 +62,7 @@ impl ToSeries for JsUnknown {
let av = AnyValue::from_js(unknown).unwrap();
v.push(av);
}
Series::new("", v)
Series::new(PlSmallStr::EMPTY, v)
}
}

Expand Down Expand Up @@ -174,7 +172,7 @@ impl FromNapiValue for Wrap<StringChunked> {
unsafe fn from_napi_value(env: sys::napi_env, napi_val: sys::napi_value) -> JsResult<Self> {
let arr = Array::from_napi_value(env, napi_val)?;
let len = arr.len() as usize;
let mut builder = StringChunkedBuilder::new("", len);
let mut builder = StringChunkedBuilder::new(PlSmallStr::EMPTY, len);
for i in 0..len {
match arr.get::<String>(i as u32) {
Ok(val) => match val {
Expand All @@ -192,7 +190,7 @@ impl FromNapiValue for Wrap<BooleanChunked> {
unsafe fn from_napi_value(env: sys::napi_env, napi_val: sys::napi_value) -> JsResult<Self> {
let arr = Array::from_napi_value(env, napi_val)?;
let len = arr.len() as usize;
let mut builder = BooleanChunkedBuilder::new("", len);
let mut builder = BooleanChunkedBuilder::new(PlSmallStr::EMPTY, len);
for i in 0..len {
match arr.get::<bool>(i as u32) {
Ok(val) => match val {
Expand All @@ -211,7 +209,7 @@ impl FromNapiValue for Wrap<Float32Chunked> {
unsafe fn from_napi_value(env: sys::napi_env, napi_val: sys::napi_value) -> JsResult<Self> {
let arr = Array::from_napi_value(env, napi_val)?;
let len = arr.len() as usize;
let mut builder = PrimitiveChunkedBuilder::<Float32Type>::new("", len);
let mut builder = PrimitiveChunkedBuilder::<Float32Type>::new(PlSmallStr::EMPTY, len);
for i in 0..len {
match arr.get::<f64>(i as u32) {
Ok(val) => match val {
Expand All @@ -234,7 +232,7 @@ macro_rules! impl_chunked {
) -> JsResult<Self> {
let arr = Array::from_napi_value(env, napi_val)?;
let len = arr.len() as usize;
let mut builder = PrimitiveChunkedBuilder::<$type>::new("", len);
let mut builder = PrimitiveChunkedBuilder::<$type>::new(PlSmallStr::EMPTY, len);
for i in 0..len {
match arr.get::<$native>(i as u32) {
Ok(val) => match val {
Expand All @@ -258,7 +256,7 @@ impl FromNapiValue for Wrap<ChunkedArray<UInt64Type>> {
unsafe fn from_napi_value(env: sys::napi_env, napi_val: sys::napi_value) -> JsResult<Self> {
let arr = Array::from_napi_value(env, napi_val)?;
let len = arr.len() as usize;
let mut builder = PrimitiveChunkedBuilder::<UInt64Type>::new("", len);
let mut builder = PrimitiveChunkedBuilder::<UInt64Type>::new(PlSmallStr::EMPTY, len);
for i in 0..len {
match arr.get::<BigInt>(i as u32) {
Ok(val) => match val {
Expand Down Expand Up @@ -631,11 +629,7 @@ impl FromNapiValue for Wrap<DataType> {
match ty {
ValueType::Object => {
let obj = Object::from_napi_value(env, napi_val)?;
let variant = if let Some(variant) = obj.get::<_, String>("variant")? {
variant
} else {
"".into()
};
let variant = obj.get::<_, String>("variant")?.map_or("".into(), |v| v);

let dtype = match variant.as_ref() {
"Int8" => DataType::Int8,
Expand Down Expand Up @@ -688,7 +682,7 @@ impl FromNapiValue for Wrap<DataType> {
let obj = Object::from_napi_value(env, napi_dt)?;
let name = obj.get::<_, String>("name")?.unwrap();
let dt = obj.get::<_, Wrap<DataType>>("dtype")?.unwrap();
let fld = Field::new(&name, dt.0);
let fld = Field::new(name.into(), dt.0);
fldvec.push(fld);
}
DataType::Struct(fldvec)
Expand Down Expand Up @@ -725,7 +719,7 @@ impl FromNapiValue for Wrap<Schema> {
let napi_val = Object::to_napi_value(env, value)?;
let dtype = Wrap::<DataType>::from_napi_value(env, napi_val)?;

Ok(Field::new(key, dtype.0))
Ok(Field::new(key.into(), dtype.0))
})
.collect::<Result<Schema>>()?,
))
Expand Down Expand Up @@ -806,11 +800,7 @@ impl FromNapiValue for Wrap<SortOptions> {
unsafe fn from_napi_value(env: sys::napi_env, napi_val: sys::napi_value) -> napi::Result<Self> {
let obj = Object::from_napi_value(env, napi_val)?;
let descending = obj.get::<_, bool>("descending")?.unwrap();
let nulls_last = if let Some(nulls_last) = obj.get::<_, bool>("nulls_last")? {
nulls_last
} else {
obj.get::<_, bool>("nullsLast")?.unwrap_or(false)
};
let nulls_last = obj.get::<_, bool>("nulls_last")?.map_or(obj.get::<_, bool>("nullsLast")?.unwrap_or(false), |n| n);
let multithreaded = obj.get::<_, bool>("multithreaded")?.unwrap();
let maintain_order: bool = obj.get::<_, bool>("maintain_order")?.unwrap();
let options = SortOptions {
Expand Down Expand Up @@ -957,8 +947,7 @@ impl ToNapiValue for Wrap<DataType> {
let mut inner_arr = env_ctx.create_array(2)?;

inner_arr.set(0, tu.to_ascii())?;
inner_arr.set(1, tz)?;

inner_arr.set(1, tz.as_ref().map_or("", |s| s.as_str()))?;
obj.set("variant", "Datetime")?;
obj.set("inner", inner_arr)?;
Object::to_napi_value(env, obj)
Expand All @@ -974,7 +963,7 @@ impl ToNapiValue for Wrap<DataType> {
let mut js_flds = env_ctx.create_array(flds.len() as u32)?;
for (idx, fld) in flds.iter().enumerate() {
let name = fld.name().clone();
let dtype = Wrap(fld.data_type().clone());
let dtype = Wrap(fld.dtype().clone());
let mut fld_obj = env_ctx.create_object()?;
fld_obj.set("name", name.to_string())?;
fld_obj.set("dtype", dtype)?;
Expand Down Expand Up @@ -1016,11 +1005,11 @@ impl ToNapiValue for Wrap<DataType> {
impl FromNapiValue for Wrap<NullValues> {
unsafe fn from_napi_value(env: sys::napi_env, napi_val: sys::napi_value) -> JsResult<Self> {
if let Ok(s) = String::from_napi_value(env, napi_val) {
Ok(Wrap(NullValues::AllColumnsSingle(s)))
Ok(Wrap(NullValues::AllColumnsSingle(s.into())))
} else if let Ok(s) = Vec::<String>::from_napi_value(env, napi_val) {
Ok(Wrap(NullValues::AllColumns(s)))
Ok(Wrap(NullValues::AllColumns(s.into_iter().map(PlSmallStr::from_string).collect())))
} else if let Ok(s) = HashMap::<String, String>::from_napi_value(env, napi_val) {
let null_values: Vec<(String, String)> = s.into_iter().collect();
let null_values = s.into_iter().map(|a| (PlSmallStr::from_string(a.0), PlSmallStr::from_string(a.1))).collect::<Vec<(PlSmallStr, PlSmallStr)>>();
Ok(Wrap(NullValues::Named(null_values)))
} else {
Err(
Expand All @@ -1034,10 +1023,10 @@ impl FromNapiValue for Wrap<NullValues> {
impl ToNapiValue for Wrap<NullValues> {
unsafe fn to_napi_value(env: sys::napi_env, val: Self) -> napi::Result<sys::napi_value> {
match val.0 {
NullValues::AllColumnsSingle(s) => String::to_napi_value(env, s),
NullValues::AllColumns(arr) => Vec::<String>::to_napi_value(env, arr),
NullValues::AllColumnsSingle(s) => String::to_napi_value(env, s.to_string()),
NullValues::AllColumns(arr) => Vec::<String>::to_napi_value(env, arr.iter().map(|x| x.to_string()).collect()),
NullValues::Named(obj) => {
let o: HashMap<String, String> = obj.into_iter().collect();
let o: HashMap<String, String> = obj.into_iter().map(|s| (s.0.to_string(), s.1.to_string())).collect::<HashMap<String, String>>();
HashMap::<String, String>::to_napi_value(env, o)
}
}
Expand Down Expand Up @@ -1242,12 +1231,12 @@ pub(crate) fn parse_fill_null_strategy(
Ok(parsed)
}

pub(crate) fn strings_to_smartstrings<I, S>(container: I) -> Vec<SmartString>
pub(crate) fn strings_to_pl_smallstr<I, S>(container: I) -> Vec<PlSmallStr>
where
I: IntoIterator<Item = S>,
S: AsRef<str>,
{
container.into_iter().map(|s| s.as_ref().into()).collect()
container.into_iter().map(|s| PlSmallStr::from_str(s.as_ref())).collect()
}

pub(crate) fn strings_to_selector<I, S>(container: I) -> Vec<Selector>
Expand Down
Loading

0 comments on commit 690dbc3

Please sign in to comment.