Skip to content

Casting from string to list of enums fails. #27336

@gab23r

Description

@gab23r

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

I notice this bug while working on another PR.
This test fails:

So I guess it was supported to be supported one day.

import polars as pl

print(pl.Series(["cat1"]).cast(pl.List(pl.Enum(["cat1"]))))
# shape: (1,)
# Series: '' [list[u8]]
# [
# 	[null]
# ]

Log output

Issue description

Casting to List of Enum return null values.

Expected behavior

No null in the result

Installed versions

Details
--------Version info---------
Polars:              1.40.0
Index type:          UInt32
Platform:            macOS-15.4.1-arm64-arm-64bit
Python:              3.12.8 (v3.12.8:2dc476bcb91, Dec  3 2024, 14:43:19) [Clang 13.0.0 (clang-1300.0.29.30)]
Runtime:             rt32

----Optional dependencies----
Azure CLI            <not installed>
adbc_driver_manager  1.11.0
altair               6.0.0
azure.identity       1.25.3
boto3                1.42.84
cloudpickle          3.1.2
connectorx           0.4.5
deltalake            1.5.0
fastexcel            0.19.0
fsspec               2026.3.0
gevent               26.4.0
google.auth          2.49.2
great_tables         0.21.0
matplotlib           3.10.8
numpy                2.4.4
openpyxl             3.1.5
pandas               3.0.2
polars_cloud         0.6.0
pyarrow              23.0.1
pydantic             2.13.1
pyiceberg            0.11.1
sqlalchemy           2.0.49
torch                <not installed>
xlsx2csv             0.8.6
xlsxwriter           3.2.9```

</details>

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingneeds triageAwaiting prioritization by a maintainerpythonRelated to Python Polars

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions