Skip to content

Commit

Permalink
test: add test for non-1 step in String slicing (#8797)
Browse files Browse the repository at this point in the history
  • Loading branch information
NickCrews authored Apr 18, 2024
1 parent c0c508e commit 8f61c14
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
3 changes: 2 additions & 1 deletion ibis/expr/types/strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ def __getitem__(self, key: slice | int | ir.IntegerScalar) -> StringValue:

if isinstance(key, slice):
start, stop, step = key.start, key.stop, key.step
if step is not None and not isinstance(step, ir.Expr) and step != 1:

if isinstance(step, ir.Expr) or (step is not None and step != 1):
raise ValueError("Step can only be 1")
if start is not None and not isinstance(start, ir.Expr) and start < 0:
raise ValueError(
Expand Down
12 changes: 12 additions & 0 deletions ibis/tests/expr/test_value_exprs.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,18 @@ def test_cast_same_type_noop(table):
assert i.cast("int8") is i


def test_string_slice_step(table):
s = ibis.literal("abcde")
s[1:3]
s[1:3:1]
with pytest.raises(ValueError):
s[1:3:2]
with pytest.raises(ValueError):
s[1 : 3 : ibis.literal(1)]
with pytest.raises(ValueError):
s[1 : 3 : ibis.literal(2)]


@pytest.mark.parametrize("type", ["int8", "int32", "double", "float32"])
def test_string_to_number(table, type):
casted = table.g.cast(type)
Expand Down

0 comments on commit 8f61c14

Please sign in to comment.