Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dataframely/columns/_mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def validation_rules(self, expr: pl.Expr) -> dict[str, pl.Expr]:
result["min_exclusive"] = expr > self.min_exclusive # type: ignore
if self.max is not None:
result["max"] = expr <= self.max # type: ignore
if self.max_exclusive:
if self.max_exclusive is not None:
result["max_exclusive"] = expr < self.max_exclusive # type: ignore
return result

Expand Down
28 changes: 28 additions & 0 deletions tests/column_types/test_integer.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,34 @@ def test_validate_max(column_type: type[_BaseInteger], inclusive: bool) -> None:
assert_frame_equal(actual, expected)


@pytest.mark.parametrize("column_type", INTEGER_COLUMN_TYPES)
@pytest.mark.parametrize("inclusive", [True, False])
def test_validate_min_zero(column_type: type[_BaseInteger], inclusive: bool) -> None:
"""Specific edge case where the minimum is `0`, which can lead to python bugs if we
use `if value` instead of `if value is not None` somewhere."""
key = "min" if inclusive else "min_exclusive"
kwargs = {key: 0}
column = column_type(**kwargs) # type: ignore
lf = pl.LazyFrame({"a": [-1]})
actual = evaluate_rules(lf, rules_from_exprs(column.validation_rules(pl.col("a"))))
expected = pl.LazyFrame({key: [False]})
assert_frame_equal(actual, expected)


@pytest.mark.parametrize("column_type", INTEGER_COLUMN_TYPES)
@pytest.mark.parametrize("inclusive", [True, False])
def test_validate_max_zero(column_type: type[_BaseInteger], inclusive: bool) -> None:
"""Specific edge case where the maximum is `0`, which can lead to python bugs if we
use `if value` instead of `if value is not None` somewhere."""
key = "max" if inclusive else "max_exclusive"
kwargs = {key: 0}
column = column_type(**kwargs) # type: ignore
lf = pl.LazyFrame({"a": [1]})
actual = evaluate_rules(lf, rules_from_exprs(column.validation_rules(pl.col("a"))))
expected = pl.LazyFrame({key: [False]})
assert_frame_equal(actual, expected)


@pytest.mark.parametrize("column_type", INTEGER_COLUMN_TYPES)
@pytest.mark.parametrize("min_inclusive", [True, False])
@pytest.mark.parametrize("max_inclusive", [True, False])
Expand Down
Loading