Path: blob/main/py-polars/tests/unit/operations/test_has_nulls.py
6939 views
from hypothesis import given12import polars as pl3from polars.testing import assert_frame_equal4from polars.testing.parametric import dataframes, series567@given(s=series(allow_null=False))8def test_has_nulls_series_no_nulls(s: pl.Series) -> None:9assert s.has_nulls() is False101112@given(df=dataframes(allow_null=False))13def test_has_nulls_expr_no_nulls(df: pl.DataFrame) -> None:14result = df.select(pl.all().has_nulls())15assert result.select(pl.any_horizontal(df.columns)).item() is False161718@given(19s=series(20excluded_dtypes=[21pl.Struct, # https://github.com/pola-rs/polars/issues/346222]23)24)25def test_has_nulls_series_parametric(s: pl.Series) -> None:26result = s.has_nulls()27assert result == (s.null_count() > 0)28assert result == s.is_null().any()293031@given(32lf=dataframes(33excluded_dtypes=[34pl.Struct, # https://github.com/pola-rs/polars/issues/346235],36lazy=True,37)38)39def test_has_nulls_expr_parametric(lf: pl.LazyFrame) -> None:40result = lf.select(pl.all().has_nulls())4142assert_frame_equal(result, lf.select(pl.all().null_count() > 0))43assert_frame_equal(result, lf.select(pl.all().is_null().any()))444546def test_has_nulls_series() -> None:47s = pl.Series([1, 2, None])48assert s.has_nulls() is True49assert s[:2].has_nulls() is False505152def test_has_nulls_expr() -> None:53lf = pl.LazyFrame({"a": [1, 2, None], "b": ["x", "y", "z"]})54result = lf.select(pl.all().has_nulls())55expected = pl.LazyFrame({"a": [True], "b": [False]})56assert_frame_equal(result, expected)575859