Closed
Description
Checks
- I have checked that this issue has not already been reported.
- I have confirmed this bug exists on the latest version of Polars.
Reproducible example
import polars as pl
df = pl.DataFrame({"x": [[1, 2]]})
df.select(pl.col("x").list.eval(pl.exclude("")))
# PanicException: index out of bounds: the len is 0 but the index is 0
Log output

Issue description
Testing various expressions after reading the question from StackOverflow1 asking about pl.all()
usage inside list.eval()
.
It seems only pl.col("name")
is disallowed.
df.select(pl.col("x").list.eval(pl.col(pl.String)))
# PanicException: index out of bounds: the len is 0 but the index is 0
Various things seem to be allowed and end up treated the same as pl.element()
df.select(pl.col("x").list.eval(pl.exclude("im-not-here")))
df.select(pl.col("x").list.eval(pl.col(pl.Int64)))
df.select(pl.col("x").list.eval(pl.exclude("x")))
df.select(pl.col("x").list.eval(pl.nth(-1)))
# shape: (1, 1)
# ┌───────────┐
# │ x │
# │ --- │
# │ list[i64] │
# ╞═══════════╡
# │ [1, 2] │
# └───────────┘
AFAIK .pivot()
is the other place that allows pl.element()
- it seems to disallow all the cases I've tried.
(It does allow pl.all()
to be used instead of pl.element()
)
Expected behavior
No panic.
Installed versions
--------Version info---------
Polars: 1.29.0
Index type: UInt32
Platform: macOS-13.6.1-arm64-arm-64bit-Mach-O
Python: 3.13.0 (main, Oct 7 2024, 05:02:14) [Clang 15.0.0 (clang-1500.1.0.2.5)]
LTS CPU: False
----Optional dependencies----
adbc_driver_manager <not installed>
altair <not installed>
boto3 <not installed>
cloudpickle <not installed>
connectorx <not installed>
deltalake <not installed>
fastexcel 0.12.0
fsspec <not installed>
gevent <not installed>
google.auth <not installed>
great_tables 0.14.0
matplotlib <not installed>
nest_asyncio <not installed>
numpy 2.1.3
openpyxl 3.1.5
pandas 2.2.3
pyarrow 18.0.0
pydantic <not installed>
pyiceberg <not installed>
sqlalchemy <not installed>
torch <not installed>
xlsx2csv <not installed>
xlsxwriter 3.2.0