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

fix: Preserve NULLs for is_not_nan #15889

Merged
merged 4 commits into from Apr 26, 2024
Merged

fix: Preserve NULLs for is_not_nan #15889

merged 4 commits into from Apr 26, 2024

Conversation

nameexhaustion
Copy link
Collaborator

@nameexhaustion nameexhaustion commented Apr 25, 2024

Fixes #15862.

As an aside, float-specific functions on non-floats also currently don't preserve NULLs:

Non-float
import polars as pl

df = pl.Series("a", [1, None]).to_frame()

v = df.with_columns(
    **{
        x: getattr(pl.col("a"), x)().alias(x)
        for x in ["is_nan", "is_not_nan", "is_finite", "is_infinite"]
    }
)

print(v)

shape: (2, 5)
┌──────┬────────┬────────────┬───────────┬─────────────┐
│ ais_nanis_not_nanis_finiteis_infinite │
│ ---------------         │
│ i64boolboolboolbool        │
╞══════╪════════╪════════════╪═══════════╪═════════════╡
│ 1falsetruetruefalse       │
│ nullfalsetruetruefalse       │
└──────┴────────┴────────────┴───────────┴─────────────┘

@github-actions github-actions bot added fix Bug fix python Related to Python Polars rust Related to Rust Polars labels Apr 25, 2024
@nameexhaustion nameexhaustion marked this pull request as ready for review April 25, 2024 13:35
@nameexhaustion nameexhaustion marked this pull request as draft April 25, 2024 13:43
Copy link

codspeed-hq bot commented Apr 25, 2024

CodSpeed Performance Report

Merging #15889 will not alter performance

Comparing nameexhaustion:nan (89fa1dd) with main (66c9aa4)

Summary

✅ 13 untouched benchmarks

@nameexhaustion nameexhaustion marked this pull request as ready for review April 25, 2024 14:33
@ritchie46
Copy link
Member

Thank you @nameexhaustion!

@@ -966,7 +966,7 @@ impl Expr {
// we take the not branch so that self is truthy value of `when -> then -> otherwise`
// and that ensure we keep the name of `self`

when(self.clone().is_not_nan())
when(self.clone().is_not_nan().or(self.clone().is_null()))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can save a negate + allocation if we say & ca.is_not_null(). In that case we can use the validity mask directly and convert that to boolean array.

@nameexhaustion
Copy link
Collaborator Author

not sure what's going on with code coverage but I'll give it one more try

libunwind: stepWithCompactEncoding - invalid compact unwind encoding
warning: /Users/runner/work/polars/polars/target/polars-41273-14359842420759467167_2.profraw: invalid instrumentation profile data (file header is corrupt)
error: no profile can be merged
error: failed to merge profile data: process didn't exit successfully: `/Users/runner/.rustup/toolchains/nightly-[20](https://github.com/pola-rs/polars/actions/runs/8841603756/job/24278957655?pr=15889#step:13:21)24-04-15-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/bin/llvm-profdata merge -sparse -f /Users/runner/work/polars/polars/target/polars-profraw-list -o /Users/runner/work/polars/polars/target/polars.profdata` (exit status: 1)

@ritchie46 ritchie46 merged commit bd201e1 into pola-rs:main Apr 26, 2024
22 of 24 checks passed
@ritchie46
Copy link
Member

libunwind: stepWithCompactEncoding - invalid compact unwind encoding

Yeah, it is broken on every PR. :/

@nameexhaustion nameexhaustion deleted the nan branch April 26, 2024 09:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix Bug fix python Related to Python Polars rust Related to Rust Polars
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Asymmetry between is_nan and is_not_nan
2 participants