Skip to content

Commit 376489f

Browse files
committed
fixup! Use 'strtobool' instead of comparing with a string.
1 parent 711a6c9 commit 376489f

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

pyiceberg/expressions/literals.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
TimestamptzType,
4747
TimeType,
4848
UUIDType,
49-
strtobool,
5049
)
5150
from pyiceberg.utils.datetime import (
5251
date_str_to_days,
@@ -589,7 +588,7 @@ def _(self, type_var: DecimalType) -> Literal[Decimal]:
589588
def _(self, type_var: BooleanType) -> Literal[bool]:
590589
value_upper = self.value.upper()
591590
if value_upper in ["TRUE", "FALSE"]:
592-
return BooleanLiteral(strtobool(value_upper))
591+
return BooleanLiteral(value_upper == "TRUE")
593592
else:
594593
raise ValueError(f"Could not convert {self.value} into a {type_var}")
595594

tests/expressions/test_literals.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -385,17 +385,23 @@ def test_string_to_decimal_literal() -> None:
385385

386386

387387
def test_string_to_boolean_literal() -> None:
388-
assert literal(True) == literal("true").to(BooleanType())
389-
assert literal(True) == literal("True").to(BooleanType())
390-
assert literal(False) == literal("false").to(BooleanType())
391-
assert literal(False) == literal("False").to(BooleanType())
388+
assert literal("true").to(BooleanType()) == literal(True)
389+
assert literal("True").to(BooleanType()) == literal(True)
390+
assert literal("false").to(BooleanType()) == literal(False)
391+
assert literal("False").to(BooleanType()) == literal(False)
392+
assert literal("TRUE").to(BooleanType()) == literal(True)
393+
assert literal("FALSE").to(BooleanType()) == literal(True)
392394

393395

394-
def test_invalid_string_to_boolean_literal() -> None:
395-
invalid_boolean_str = literal("unknown")
396+
@pytest.mark.parametrize(
397+
"val",
398+
["unknown", "off", "on", "0", "1", "y", "yes", "n", "no", "t", "f"],
399+
)
400+
def test_invalid_string_to_boolean_literal(val: Any) -> None:
401+
invalid_boolean_str = literal(val)
396402
with pytest.raises(ValueError) as e:
397403
_ = invalid_boolean_str.to(BooleanType())
398-
assert "Could not convert unknown into a boolean" in str(e.value)
404+
assert f"Could not convert {val} into a boolean" in str(e.value)
399405

400406

401407
# MISC

0 commit comments

Comments
 (0)