From 553a1a5166945830afd3c381e883c0d02508db91 Mon Sep 17 00:00:00 2001 From: Evgenii Kuznetcov Date: Fri, 4 Oct 2024 13:49:14 +0200 Subject: [PATCH 1/2] Don't return NaN values for empty clusters --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/expressions.rs | 8 ++++++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6d090a0..874871f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -947,7 +947,7 @@ dependencies = [ [[package]] name = "polars-tdigest" -version = "0.1.3" +version = "0.1.4" dependencies = [ "jemallocator", "ordered-float 4.2.0", diff --git a/Cargo.toml b/Cargo.toml index e194541..cbf83c0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "polars-tdigest" -version = "0.1.3" +version = "0.1.4" edition = "2021" [lib] diff --git a/src/expressions.rs b/src/expressions.rs index e7a32ce..a405f9c 100644 --- a/src/expressions.rs +++ b/src/expressions.rs @@ -176,9 +176,13 @@ fn tdigest(inputs: &[Series]) -> PolarsResult { _ => polars_bail!(InvalidOperation: "only supported for numerical types"), }; - let t_global = TDigest::merge_digests(chunks); + let mut td_global = TDigest::merge_digests(chunks); + if td_global.is_empty() { + // Default value for TDigest contains NaNs that cause problems during serialization/deserailization + td_global = TDigest::new(Vec::new(), 100.0, 0.0, 0.0, 0.0, 0) + } - let td_json = serde_json::to_string(&t_global).unwrap(); + let td_json = serde_json::to_string(&td_global).unwrap(); let file = Cursor::new(&td_json); let df = JsonReader::new(file) From d478f1c1d34c9d7bf1c763291d78415085a1033b Mon Sep 17 00:00:00 2001 From: Evgenii Kuznetcov Date: Mon, 7 Oct 2024 11:58:31 +0200 Subject: [PATCH 2/2] Update readme --- README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/README.md b/README.md index d8e939d..d9cfe02 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,20 @@ Install [Rust](https://rustup.rs/). In order to build the package, please run `maturin develop`. If you want to test performance, run `maturin develop --release`. +## Developing using cargo + +Cargo commands (e.g. `cargo build`, `cargo test`) don't work out of the box. +In order to use cargo instead of maturin for local development, remove `extension-module` from `cargo.toml`: +replace +``` +pyo3 = { version = "0.21.2", features = ["extension-module", "abi3-py38"] } +``` +with + +``` +pyo3 = { version = "0.21.2", features = ["abi3-py38"] } +``` + ## Commit / Release Before committing and pushing your work, make sure to run