Skip to content

Commit f569984

Browse files
committed
Upgrading to rs-0.43
1 parent 0f36b90 commit f569984

File tree

15 files changed

+123
-152
lines changed

15 files changed

+123
-152
lines changed

.github/workflows/docs.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
- name: Install latest Rust nightly
1515
uses: dtolnay/rust-toolchain@stable
1616
with:
17-
toolchain: nightly-2024-07-26
17+
toolchain: nightly-2024-08-26
1818
components: rustfmt, clippy
1919
- name: Install ghp-import
2020
uses: actions/setup-python@v5

.github/workflows/test-js.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
- name: Install latest Rust nightly
2121
uses: dtolnay/rust-toolchain@stable
2222
with:
23-
toolchain: nightly-2024-07-26
23+
toolchain: nightly-2024-08-26
2424
components: rustfmt, clippy
2525
- name: Check yarn version
2626
run: yarn --version
@@ -46,7 +46,7 @@ jobs:
4646
- name: Install latest Rust nightly
4747
uses: dtolnay/rust-toolchain@stable
4848
with:
49-
toolchain: nightly-2024-07-26
49+
toolchain: nightly-2024-08-26
5050
components: rustfmt, clippy
5151
- name: Bun version
5252
uses: oven-sh/setup-bun@v1

Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ napi = { version = "2.16.9", default-features = false, features = [
2020
"serde-json",
2121
] }
2222
napi-derive = { version = "2.16.11", default-features = false }
23-
polars-core = { git = "https://github.com/pola-rs/polars.git", rev = "7686025ac7738607f2d4f6887e9a1313b7c8b1e2", default-features = false }
24-
polars-io = { git = "https://github.com/pola-rs/polars.git", rev = "7686025ac7738607f2d4f6887e9a1313b7c8b1e2", default-features = false }
25-
polars-lazy = { git = "https://github.com/pola-rs/polars.git", rev = "7686025ac7738607f2d4f6887e9a1313b7c8b1e2", default-features = false }
23+
polars-core = { git = "https://github.com/pola-rs/polars.git", rev = "f25ca0c14d984bc820c7910d216003edc57d1a3c", default-features = false }
24+
polars-io = { git = "https://github.com/pola-rs/polars.git", rev = "f25ca0c14d984bc820c7910d216003edc57d1a3c", default-features = false }
25+
polars-lazy = { git = "https://github.com/pola-rs/polars.git", rev = "f25ca0c14d984bc820c7910d216003edc57d1a3c", default-features = false }
2626
thiserror = "1"
2727
smartstring = { version = "1" }
2828
serde_json = { version = "1" }
@@ -158,7 +158,7 @@ features = [
158158
"http"
159159
]
160160
git = "https://github.com/pola-rs/polars.git"
161-
rev = "7686025ac7738607f2d4f6887e9a1313b7c8b1e2"
161+
rev = "f25ca0c14d984bc820c7910d216003edc57d1a3c"
162162

163163
[build-dependencies]
164164
napi-build = "2.1.3"

__tests__/dataframe.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1862,8 +1862,8 @@ describe("create", () => {
18621862
bool: pl.Bool,
18631863
date: pl.Date,
18641864
date_nulls: pl.Date,
1865-
datetime: pl.Datetime("ms"),
1866-
datetime_nulls: pl.Datetime("ms"),
1865+
datetime: pl.Datetime("ms", ""),
1866+
datetime_nulls: pl.Datetime("ms", ""),
18671867
string: pl.String,
18681868
string_nulls: pl.String,
18691869
categorical: pl.Categorical,
@@ -1983,7 +1983,7 @@ describe("create", () => {
19831983
expect(df.toRecords()).toEqual(expected);
19841984
expect(df.schema).toStrictEqual({
19851985
num: pl.Float64,
1986-
date: pl.Datetime("ms"),
1986+
date: pl.Datetime("ms", ""),
19871987
string: pl.String,
19881988
});
19891989
});

__tests__/series.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -217,13 +217,13 @@ describe("series", () => {
217217

218218
describe("create series", () => {
219219
it.each`
220-
values | dtype | type
221-
${["foo", "bar", "baz"]} | ${pl.String} | ${"string"}
222-
${[1, 2, 3]} | ${pl.Float64} | ${"number"}
223-
${[1n, 2n, 3n]} | ${pl.UInt64} | ${"bigint"}
224-
${[true, false]} | ${pl.Bool} | ${"boolean"}
225-
${[]} | ${pl.Float64} | ${"empty"}
226-
${[new Date(Date.now())]} | ${pl.Datetime("ms")} | ${"Date"}
220+
values | dtype | type
221+
${["foo", "bar", "baz"]} | ${pl.String} | ${"string"}
222+
${[1, 2, 3]} | ${pl.Float64} | ${"number"}
223+
${[1n, 2n, 3n]} | ${pl.UInt64} | ${"bigint"}
224+
${[true, false]} | ${pl.Bool} | ${"boolean"}
225+
${[]} | ${pl.Float64} | ${"empty"}
226+
${[new Date(Date.now())]} | ${pl.Datetime("ms", "")} | ${"Date"}
227227
`('defaults to $dtype for "$type"', ({ values, dtype }) => {
228228
const name = chance.string();
229229
const s = pl.Series(name, values);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
"ts-jest": "^29.2.5",
6666
"ts-node": "^10.9.2",
6767
"typedoc": "^0.26.6",
68-
"typescript": "5.5.4"
68+
"typescript": "5.6.2"
6969
},
7070
"packageManager": "[email protected]",
7171
"workspaces": [

rust-toolchain

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
nightly-2024-07-26
1+
nightly-2024-08-26

src/conversion.rs

Lines changed: 21 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ use polars_io::RowIndex;
99
use std::any::Any;
1010
use std::collections::HashMap;
1111

12-
use smartstring::alias::String as SmartString;
13-
1412
#[derive(Debug)]
1513
pub struct Wrap<T: ?Sized>(pub T);
1614

@@ -50,7 +48,7 @@ impl ToSeries for Array {
5048
let av: Wrap<AnyValue> = self.get(i).unwrap().unwrap_or(Wrap(AnyValue::Null));
5149
v.push(av.0);
5250
}
53-
Series::new("", v)
51+
Series::new(PlSmallStr::EMPTY, v)
5452
}
5553
}
5654

@@ -64,7 +62,7 @@ impl ToSeries for JsUnknown {
6462
let av = AnyValue::from_js(unknown).unwrap();
6563
v.push(av);
6664
}
67-
Series::new("", v)
65+
Series::new(PlSmallStr::EMPTY, v)
6866
}
6967
}
7068

@@ -174,7 +172,7 @@ impl FromNapiValue for Wrap<StringChunked> {
174172
unsafe fn from_napi_value(env: sys::napi_env, napi_val: sys::napi_value) -> JsResult<Self> {
175173
let arr = Array::from_napi_value(env, napi_val)?;
176174
let len = arr.len() as usize;
177-
let mut builder = StringChunkedBuilder::new("", len);
175+
let mut builder = StringChunkedBuilder::new(PlSmallStr::EMPTY, len);
178176
for i in 0..len {
179177
match arr.get::<String>(i as u32) {
180178
Ok(val) => match val {
@@ -192,7 +190,7 @@ impl FromNapiValue for Wrap<BooleanChunked> {
192190
unsafe fn from_napi_value(env: sys::napi_env, napi_val: sys::napi_value) -> JsResult<Self> {
193191
let arr = Array::from_napi_value(env, napi_val)?;
194192
let len = arr.len() as usize;
195-
let mut builder = BooleanChunkedBuilder::new("", len);
193+
let mut builder = BooleanChunkedBuilder::new(PlSmallStr::EMPTY, len);
196194
for i in 0..len {
197195
match arr.get::<bool>(i as u32) {
198196
Ok(val) => match val {
@@ -211,7 +209,7 @@ impl FromNapiValue for Wrap<Float32Chunked> {
211209
unsafe fn from_napi_value(env: sys::napi_env, napi_val: sys::napi_value) -> JsResult<Self> {
212210
let arr = Array::from_napi_value(env, napi_val)?;
213211
let len = arr.len() as usize;
214-
let mut builder = PrimitiveChunkedBuilder::<Float32Type>::new("", len);
212+
let mut builder = PrimitiveChunkedBuilder::<Float32Type>::new(PlSmallStr::EMPTY, len);
215213
for i in 0..len {
216214
match arr.get::<f64>(i as u32) {
217215
Ok(val) => match val {
@@ -234,7 +232,7 @@ macro_rules! impl_chunked {
234232
) -> JsResult<Self> {
235233
let arr = Array::from_napi_value(env, napi_val)?;
236234
let len = arr.len() as usize;
237-
let mut builder = PrimitiveChunkedBuilder::<$type>::new("", len);
235+
let mut builder = PrimitiveChunkedBuilder::<$type>::new(PlSmallStr::EMPTY, len);
238236
for i in 0..len {
239237
match arr.get::<$native>(i as u32) {
240238
Ok(val) => match val {
@@ -258,7 +256,7 @@ impl FromNapiValue for Wrap<ChunkedArray<UInt64Type>> {
258256
unsafe fn from_napi_value(env: sys::napi_env, napi_val: sys::napi_value) -> JsResult<Self> {
259257
let arr = Array::from_napi_value(env, napi_val)?;
260258
let len = arr.len() as usize;
261-
let mut builder = PrimitiveChunkedBuilder::<UInt64Type>::new("", len);
259+
let mut builder = PrimitiveChunkedBuilder::<UInt64Type>::new(PlSmallStr::EMPTY, len);
262260
for i in 0..len {
263261
match arr.get::<BigInt>(i as u32) {
264262
Ok(val) => match val {
@@ -631,11 +629,7 @@ impl FromNapiValue for Wrap<DataType> {
631629
match ty {
632630
ValueType::Object => {
633631
let obj = Object::from_napi_value(env, napi_val)?;
634-
let variant = if let Some(variant) = obj.get::<_, String>("variant")? {
635-
variant
636-
} else {
637-
"".into()
638-
};
632+
let variant = obj.get::<_, String>("variant")?.map_or("".into(), |v| v);
639633

640634
let dtype = match variant.as_ref() {
641635
"Int8" => DataType::Int8,
@@ -688,7 +682,7 @@ impl FromNapiValue for Wrap<DataType> {
688682
let obj = Object::from_napi_value(env, napi_dt)?;
689683
let name = obj.get::<_, String>("name")?.unwrap();
690684
let dt = obj.get::<_, Wrap<DataType>>("dtype")?.unwrap();
691-
let fld = Field::new(&name, dt.0);
685+
let fld = Field::new(name.into(), dt.0);
692686
fldvec.push(fld);
693687
}
694688
DataType::Struct(fldvec)
@@ -725,7 +719,7 @@ impl FromNapiValue for Wrap<Schema> {
725719
let napi_val = Object::to_napi_value(env, value)?;
726720
let dtype = Wrap::<DataType>::from_napi_value(env, napi_val)?;
727721

728-
Ok(Field::new(key, dtype.0))
722+
Ok(Field::new(key.into(), dtype.0))
729723
})
730724
.collect::<Result<Schema>>()?,
731725
))
@@ -806,11 +800,7 @@ impl FromNapiValue for Wrap<SortOptions> {
806800
unsafe fn from_napi_value(env: sys::napi_env, napi_val: sys::napi_value) -> napi::Result<Self> {
807801
let obj = Object::from_napi_value(env, napi_val)?;
808802
let descending = obj.get::<_, bool>("descending")?.unwrap();
809-
let nulls_last = if let Some(nulls_last) = obj.get::<_, bool>("nulls_last")? {
810-
nulls_last
811-
} else {
812-
obj.get::<_, bool>("nullsLast")?.unwrap_or(false)
813-
};
803+
let nulls_last = obj.get::<_, bool>("nulls_last")?.map_or(obj.get::<_, bool>("nullsLast")?.unwrap_or(false), |n| n);
814804
let multithreaded = obj.get::<_, bool>("multithreaded")?.unwrap();
815805
let maintain_order: bool = obj.get::<_, bool>("maintain_order")?.unwrap();
816806
let options = SortOptions {
@@ -957,8 +947,7 @@ impl ToNapiValue for Wrap<DataType> {
957947
let mut inner_arr = env_ctx.create_array(2)?;
958948

959949
inner_arr.set(0, tu.to_ascii())?;
960-
inner_arr.set(1, tz)?;
961-
950+
inner_arr.set(1, tz.as_ref().map_or("", |s| s.as_str()))?;
962951
obj.set("variant", "Datetime")?;
963952
obj.set("inner", inner_arr)?;
964953
Object::to_napi_value(env, obj)
@@ -974,7 +963,7 @@ impl ToNapiValue for Wrap<DataType> {
974963
let mut js_flds = env_ctx.create_array(flds.len() as u32)?;
975964
for (idx, fld) in flds.iter().enumerate() {
976965
let name = fld.name().clone();
977-
let dtype = Wrap(fld.data_type().clone());
966+
let dtype = Wrap(fld.dtype().clone());
978967
let mut fld_obj = env_ctx.create_object()?;
979968
fld_obj.set("name", name.to_string())?;
980969
fld_obj.set("dtype", dtype)?;
@@ -1016,11 +1005,11 @@ impl ToNapiValue for Wrap<DataType> {
10161005
impl FromNapiValue for Wrap<NullValues> {
10171006
unsafe fn from_napi_value(env: sys::napi_env, napi_val: sys::napi_value) -> JsResult<Self> {
10181007
if let Ok(s) = String::from_napi_value(env, napi_val) {
1019-
Ok(Wrap(NullValues::AllColumnsSingle(s)))
1008+
Ok(Wrap(NullValues::AllColumnsSingle(s.into())))
10201009
} else if let Ok(s) = Vec::<String>::from_napi_value(env, napi_val) {
1021-
Ok(Wrap(NullValues::AllColumns(s)))
1010+
Ok(Wrap(NullValues::AllColumns(s.into_iter().map(PlSmallStr::from_string).collect())))
10221011
} else if let Ok(s) = HashMap::<String, String>::from_napi_value(env, napi_val) {
1023-
let null_values: Vec<(String, String)> = s.into_iter().collect();
1012+
let null_values = s.into_iter().map(|a| (PlSmallStr::from_string(a.0), PlSmallStr::from_string(a.1))).collect::<Vec<(PlSmallStr, PlSmallStr)>>();
10241013
Ok(Wrap(NullValues::Named(null_values)))
10251014
} else {
10261015
Err(
@@ -1034,10 +1023,10 @@ impl FromNapiValue for Wrap<NullValues> {
10341023
impl ToNapiValue for Wrap<NullValues> {
10351024
unsafe fn to_napi_value(env: sys::napi_env, val: Self) -> napi::Result<sys::napi_value> {
10361025
match val.0 {
1037-
NullValues::AllColumnsSingle(s) => String::to_napi_value(env, s),
1038-
NullValues::AllColumns(arr) => Vec::<String>::to_napi_value(env, arr),
1026+
NullValues::AllColumnsSingle(s) => String::to_napi_value(env, s.to_string()),
1027+
NullValues::AllColumns(arr) => Vec::<String>::to_napi_value(env, arr.iter().map(|x| x.to_string()).collect()),
10391028
NullValues::Named(obj) => {
1040-
let o: HashMap<String, String> = obj.into_iter().collect();
1029+
let o: HashMap<String, String> = obj.into_iter().map(|s| (s.0.to_string(), s.1.to_string())).collect::<HashMap<String, String>>();
10411030
HashMap::<String, String>::to_napi_value(env, o)
10421031
}
10431032
}
@@ -1242,12 +1231,12 @@ pub(crate) fn parse_fill_null_strategy(
12421231
Ok(parsed)
12431232
}
12441233

1245-
pub(crate) fn strings_to_smartstrings<I, S>(container: I) -> Vec<SmartString>
1234+
pub(crate) fn strings_to_pl_smallstr<I, S>(container: I) -> Vec<PlSmallStr>
12461235
where
12471236
I: IntoIterator<Item = S>,
12481237
S: AsRef<str>,
12491238
{
1250-
container.into_iter().map(|s| s.as_ref().into()).collect()
1239+
container.into_iter().map(|s| PlSmallStr::from_str(s.as_ref())).collect()
12511240
}
12521241

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

0 commit comments

Comments
 (0)