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: Return nulls for is_finite, is_infinite, and is_nan when dtype is pl.Null #21253

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mcrumiller
Copy link
Contributor

@mcrumiller mcrumiller commented Feb 13, 2025

Closes #21238.

Not sure if this is desired behavior, but it was an easy fix, so if so, here's the PR.

import polars as pl

pl.Series("a", [None, None]).is_nan()  # also is_finite and is_infinite
# shape: (2,)
# Series: 'a' [bool]
# [
#         null
#         null
# ]

@mcrumiller mcrumiller changed the title Fix: Return nulls for is_finite, is_infinite, and is_nan when dtype is pl.Null fix: Return nulls for is_finite, is_infinite, and is_nan when dtype is pl.Null Feb 13, 2025
@github-actions github-actions bot added fix Bug fix python Related to Python Polars rust Related to Rust Polars and removed title needs formatting labels Feb 13, 2025
Copy link

codecov bot commented Feb 13, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 79.87%. Comparing base (515c1b8) to head (3d81723).
Report is 5 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #21253      +/-   ##
==========================================
+ Coverage   79.80%   79.87%   +0.07%     
==========================================
  Files        1596     1596              
  Lines      228468   228471       +3     
  Branches     2607     2607              
==========================================
+ Hits       182318   182489     +171     
+ Misses      45554    45386     -168     
  Partials      596      596              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@mcrumiller mcrumiller marked this pull request as ready for review February 14, 2025 00:06
@ritchie46
Copy link
Member

If the nulls propagate in floats, it should return null. Otherwise it should return false.

If there is propagation, we must ensure this happens for the other dtypes as well.

@mcrumiller
Copy link
Contributor Author

@ritchie46 nulls do propagate:

>>> import polars as pl
>>> pl.Series([1.0, None]).is_finite()
shape: (2,)
Series: '' [bool]
[
        true
        null
]
>>> pl.Series([1.0, None]).is_infinite()
shape: (2,)
Series: '' [bool]
[
        false
        null
]
>>> pl.Series([1.0, None]).is_nan()
shape: (2,)
Series: '' [bool]
[
        false
        null
]

So this is the correct behavior.

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.

polars.Expr.is_infinite behavior with null dtype column.
2 participants