-
-
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: Fix
is_not_null
for Struct columns (#13921)
- Loading branch information
Showing
3 changed files
with
89 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from __future__ import annotations | ||
|
||
from hypothesis import given | ||
|
||
import polars as pl | ||
from polars.testing import assert_frame_equal, assert_series_equal | ||
from polars.testing.parametric import series | ||
|
||
|
||
@given(s=series(null_probability=0.5)) | ||
def test_drop_nulls_parametric(s: pl.Series) -> None: | ||
result = s.drop_nulls() | ||
assert result.len() == s.len() - s.null_count() | ||
|
||
filter_result = s.filter(s.is_not_null()) | ||
assert_series_equal(result, filter_result) | ||
|
||
|
||
def test_df_drop_nulls_struct() -> None: | ||
df = pl.DataFrame( | ||
{ | ||
"x": [ | ||
{"a": 1, "b": 2}, | ||
{"a": 1, "b": None}, | ||
{"a": None, "b": 2}, | ||
{"a": None, "b": None}, | ||
] | ||
} | ||
) | ||
|
||
result = df.drop_nulls() | ||
|
||
expected = df.head(3) | ||
assert_frame_equal(result, expected) |
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,54 @@ | ||
from __future__ import annotations | ||
|
||
from hypothesis import given | ||
|
||
import polars as pl | ||
from polars.testing import assert_frame_equal, assert_series_equal | ||
from polars.testing.parametric import series | ||
|
||
|
||
@given(s=series(null_probability=0.5)) | ||
def test_is_null_parametric(s: pl.Series) -> None: | ||
is_null = s.is_null() | ||
is_not_null = s.is_not_null() | ||
|
||
assert is_null.null_count() == 0 | ||
assert_series_equal(is_null, ~is_not_null) | ||
|
||
|
||
def test_is_null_struct() -> None: | ||
df = pl.DataFrame( | ||
{ | ||
"x": [ | ||
{"a": 1, "b": 2}, | ||
{"a": 1, "b": None}, | ||
{"a": None, "b": 2}, | ||
{"a": None, "b": None}, | ||
] | ||
} | ||
) | ||
|
||
result = df.select( | ||
null=pl.col("x").is_null(), | ||
not_null=pl.col("x").is_not_null(), | ||
) | ||
|
||
expected = pl.DataFrame( | ||
{ | ||
"null": [False, False, False, True], | ||
"not_null": [True, True, True, False], | ||
} | ||
) | ||
assert_frame_equal(result, expected) | ||
|
||
|
||
def test_is_null_null() -> None: | ||
s = pl.Series([None, None]) | ||
|
||
result = s.is_null() | ||
expected = pl.Series([True, True]) | ||
assert_series_equal(result, expected) | ||
|
||
result = s.is_not_null() | ||
expected = pl.Series([False, False]) | ||
assert_series_equal(result, expected) |