Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't return NaN values for empty clusters #4

Merged
merged 2 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "polars-tdigest"
version = "0.1.3"
version = "0.1.4"
edition = "2021"

[lib]
Expand Down
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions src/expressions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,13 @@ fn tdigest(inputs: &[Series]) -> PolarsResult<Series> {
_ => 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)
Expand Down
Loading