-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(rust, python): fix nan aggregation in groupby (#10287)
- Loading branch information
Showing
4 changed files
with
119 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import polars as pl | ||
|
||
|
||
def test_nan_in_groupby_agg() -> None: | ||
df = pl.DataFrame( | ||
{ | ||
"key": ["a", "a", "a", "a"], | ||
"value": [18.58, 18.78, float("nan"), 18.63], | ||
"bar": [0, 0, 0, 0], | ||
} | ||
) | ||
|
||
assert df.groupby("bar", "key").agg(pl.col("value").max())["value"].item() == 18.78 | ||
assert df.groupby("bar", "key").agg(pl.col("value").min())["value"].item() == 18.58 | ||
|
||
|
||
def test_nan_aggregations() -> None: | ||
df = pl.DataFrame({"a": [1.0, float("nan"), 2.0, 3.0], "b": [1, 1, 1, 1]}) | ||
|
||
aggs = [ | ||
pl.col("a").max().alias("max"), | ||
pl.col("a").min().alias("min"), | ||
pl.col("a").nan_max().alias("nan_max"), | ||
pl.col("a").nan_min().alias("nan_min"), | ||
] | ||
|
||
assert ( | ||
str(df.select(aggs).to_dict(False)) | ||
== "{'max': [3.0], 'min': [1.0], 'nan_max': [nan], 'nan_min': [nan]}" | ||
) | ||
assert ( | ||
str(df.groupby("b").agg(aggs).to_dict(False)) | ||
== "{'b': [1], 'max': [3.0], 'min': [1.0], 'nan_max': [nan], 'nan_min': [nan]}" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters