Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pola-rs
GitHub Repository: pola-rs/polars
Path: blob/main/py-polars/tests/unit/series/test_all_any.py
6939 views
1
from __future__ import annotations
2
3
import pytest
4
5
import polars as pl
6
from polars.exceptions import SchemaError
7
8
9
@pytest.mark.parametrize(
10
("data", "expected"),
11
[
12
([], False),
13
([None], False),
14
([False], False),
15
([False, None], False),
16
([True], True),
17
([True, None], True),
18
],
19
)
20
def test_any(data: list[bool | None], expected: bool) -> None:
21
assert pl.Series(data, dtype=pl.Boolean).any() is expected
22
23
24
@pytest.mark.parametrize(
25
("data", "expected"),
26
[
27
([], False),
28
([None], None),
29
([False], False),
30
([False, None], None),
31
([True], True),
32
([True, None], True),
33
],
34
)
35
def test_any_kleene(data: list[bool | None], expected: bool | None) -> None:
36
assert pl.Series(data, dtype=pl.Boolean).any(ignore_nulls=False) is expected
37
38
39
def test_any_wrong_dtype() -> None:
40
with pytest.raises(SchemaError, match="expected `Boolean`"):
41
pl.Series([0, 1, 0]).any()
42
43
44
@pytest.mark.parametrize(
45
("data", "expected"),
46
[
47
([], True),
48
([None], True),
49
([False], False),
50
([False, None], False),
51
([True], True),
52
([True, None], True),
53
],
54
)
55
def test_all(data: list[bool | None], expected: bool) -> None:
56
assert pl.Series(data, dtype=pl.Boolean).all() is expected
57
58
59
@pytest.mark.parametrize(
60
("data", "expected"),
61
[
62
([], True),
63
([None], None),
64
([False], False),
65
([False, None], False),
66
([True], True),
67
([True, None], None),
68
],
69
)
70
def test_all_kleene(data: list[bool | None], expected: bool | None) -> None:
71
assert pl.Series(data, dtype=pl.Boolean).all(ignore_nulls=False) is expected
72
73
74
def test_all_wrong_dtype() -> None:
75
with pytest.raises(SchemaError, match="expected `Boolean`"):
76
pl.Series([0, 1, 0]).all()
77
78