Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pola-rs
GitHub Repository: pola-rs/polars
Path: blob/main/py-polars/tests/unit/operations/test_drop_nulls.py
6939 views
1
from __future__ import annotations
2
3
from hypothesis import given
4
5
import polars as pl
6
from polars.testing import assert_frame_equal, assert_series_equal
7
from polars.testing.parametric import series
8
9
10
@given(
11
s=series(
12
allow_null=True,
13
excluded_dtypes=[
14
pl.Struct, # See: https://github.com/pola-rs/polars/issues/3462
15
],
16
)
17
)
18
def test_drop_nulls_parametric(s: pl.Series) -> None:
19
result = s.drop_nulls()
20
assert result.len() == s.len() - s.null_count()
21
22
filter_result = s.filter(s.is_not_null())
23
assert_series_equal(result, filter_result)
24
25
26
def test_df_drop_nulls_struct() -> None:
27
df = pl.DataFrame(
28
{"x": [{"a": 1, "b": 2}, {"a": 1, "b": None}, {"a": None, "b": 2}, None]}
29
)
30
31
result = df.drop_nulls()
32
33
expected = df.head(3)
34
assert_frame_equal(result, expected)
35
36