Skip to content

test(python): Add test for list slice input #22283

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
38 changes: 38 additions & 0 deletions py-polars/tests/unit/operations/namespaces/list/test_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -1076,3 +1076,41 @@ def test_list_shift_unequal_lengths_22018() -> None:

def test_list_shift_self_broadcast() -> None:
assert pl.Series("a", [[1, 2]]).list.shift(pl.Series([1, 2, 1])).len() == 3


def test_list_slice_input_validation_22025() -> None:
df = pl.DataFrame(
[
pl.Series(
"a",
[
["a"],
["eb", "d"],
],
pl.List(pl.String),
),
pl.Series("b", ["blah", "blah"]),
]
)

with pytest.raises(
TypeError,
match="unexpected value while building Series of type String; found value of type Int64: 2",
):
df.select(pl.col.a.list.slice(0, [2, 2, "a"])) # type: ignore[arg-type]

with pytest.raises(
SchemaError,
match=re.escape(
"expected integer type input to list.slice(), got list[i64] instead"
),
):
df.select(pl.col.a.list.slice(0, [0, 0]))

with pytest.raises(
SchemaError,
match=re.escape(
"expected integer type input to list.slice(), got list[i64] instead"
),
):
df.select(pl.col.a.list.slice([0, 0], 0))
Loading