Skip to content

Rich display fails for polars data frame with pl.List(pl.Enum) cols. #5562

@miccoli

Description

@miccoli

Describe the bug

Rich display of a data frame with pl.List(pl.Enum) cols fails with Rust panic.

With reference to the example below, cell-2 prints on the console

thread '<unnamed>' panicked at crates/polars-arrow/src/array/struct_/mod.rs:122:56:
called `Result::unwrap()` on an `Err` value: ComputeError(ErrString("The children DataTypes of a StructArray must equal the children data types.\n                         However, the field 0 has data type LargeList(Field { name: \"item\", dtype: Dictionary(UInt32, Utf8View, false), is_nullable: true, metadata: Some({\"_PL_ENUM_VALUES\": \"1;A1;B1;C\"}) }) but the value has data type LargeList(Field { name: \"item\", dtype: Dictionary(UInt32, Utf8View, false), is_nullable: true, metadata: None })"))
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

thread '<unnamed>' panicked at crates/polars-arrow/src/array/struct_/mod.rs:122:56:
called `Result::unwrap()` on an `Err` value: ComputeError(ErrString("The children DataTypes of a StructArray must equal the children data types.\n                         However, the field 0 has data type LargeList(Field { name: \"item\", dtype: Dictionary(UInt32, Utf8View, false), is_nullable: true, metadata: Some({\"_PL_ENUM_VALUES\": \"1;A1;B1;C\"}) }) but the value has data type LargeList(Field { name: \"item\", dtype: Dictionary(UInt32, Utf8View, false), is_nullable: true, metadata: None })"))

cell-3 fails with

PanicException
called `Result::unwrap()` on an `Err` value: ComputeError(ErrString("The children DataTypes of a StructArray must equal the children data types.\n However, the field 1 has data type LargeList(Field { name: \"item\", dtype: Dictionary(UInt32, Utf8View, false), is_nullable: true, metadata: Some({\"_PL_ENUM_VALUES\": \"1;A1;B1;C\"}) }) but the value has data type LargeList(Field { name: \"item\", dtype: Dictionary(UInt32, Utf8View, false), is_nullable: true, metadata: None })"))

See the console area for a traceback.

and again in the console

thread '<unnamed>' panicked at crates/polars-arrow/src/array/struct_/mod.rs:122:56:
called `Result::unwrap()` on an `Err` value: ComputeError(ErrString("The children DataTypes of a StructArray must equal the children data types.\n                         However, the field 1 has data type LargeList(Field { name: \"item\", dtype: Dictionary(UInt32, Utf8View, false), is_nullable: true, metadata: Some({\"_PL_ENUM_VALUES\": \"1;A1;B1;C\"}) }) but the value has data type LargeList(Field { name: \"item\", dtype: Dictionary(UInt32, Utf8View, false), is_nullable: true, metadata: None })"))

thread '<unnamed>' panicked at crates/polars-arrow/src/array/struct_/mod.rs:122:56:
called `Result::unwrap()` on an `Err` value: ComputeError(ErrString("The children DataTypes of a StructArray must equal the children data types.\n                         However, the field 1 has data type LargeList(Field { name: \"item\", dtype: Dictionary(UInt32, Utf8View, false), is_nullable: true, metadata: Some({\"_PL_ENUM_VALUES\": \"1;A1;B1;C\"}) }) but the value has data type LargeList(Field { name: \"item\", dtype: Dictionary(UInt32, Utf8View, false), is_nullable: true, metadata: None })"))

plus the following traceback:

Traceback (most recent call last):
  File "/Users/miccoli/Library/Caches/uv/archive-v0/Ck-eqMWEHKlm2XOA3iosB/lib/python3.13/site-packages/marimo/_plugins/ui/_impl/tables/polars_table.py", line 119, in to_json_str
    return sanitize_json_bigint(result.write_json())
                                ~~~~~~~~~~~~~~~~~^^
  File "/Users/miccoli/Library/Caches/uv/archive-v0/Ck-eqMWEHKlm2XOA3iosB/lib/python3.13/site-packages/polars/dataframe/frame.py", line 2819, in write_json
    return write_json_to_string()
  File "/Users/miccoli/Library/Caches/uv/archive-v0/Ck-eqMWEHKlm2XOA3iosB/lib/python3.13/site-packages/polars/dataframe/frame.py", line 2814, in write_json_to_string
    self._df.write_json(buf)
    ~~~~~~~~~~~~~~~~~~~^^^^^
pyo3_runtime.PanicException: called `Result::unwrap()` on an `Err` value: ComputeError(ErrString("The children DataTypes of a StructArray must equal the children data types.\n                         However, the field 1 has data type LargeList(Field { name: \"item\", dtype: Dictionary(UInt32, Utf8View, false), is_nullable: true, metadata: Some({\"_PL_ENUM_VALUES\": \"1;A1;B1;C\"}) }) but the value has data type LargeList(Field { name: \"item\", dtype: Dictionary(UInt32, Utf8View, false), is_nullable: true, metadata: None })"))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/miccoli/Library/Caches/uv/archive-v0/Ck-eqMWEHKlm2XOA3iosB/lib/python3.13/site-packages/marimo/_runtime/executor.py", line 139, in execute_cell
    return eval(cell.last_expr, glbls)
  File "/var/folders/51/sgqmvwtd3l7_k0y96fqxngmw0000gn/T/marimo_6514/__marimo__cell_bkHC_.py", line 2, in <module>
    mo.ui.table(df)
    ~~~~~~~~~~~^^^^
  File "/Users/miccoli/Library/Caches/uv/archive-v0/Ck-eqMWEHKlm2XOA3iosB/lib/python3.13/site-packages/marimo/_plugins/ui/_impl/table.py", line 561, in __init__
    search_result = self._search(
        SearchTableArgs(
    ...<5 lines>...
        )
    )
  File "/Users/miccoli/Library/Caches/uv/archive-v0/Ck-eqMWEHKlm2XOA3iosB/lib/python3.13/site-packages/marimo/_plugins/ui/_impl/table.py", line 1006, in _search
    data=clamp_rows_and_columns(self._manager),
         ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^
  File "/Users/miccoli/Library/Caches/uv/archive-v0/Ck-eqMWEHKlm2XOA3iosB/lib/python3.13/site-packages/marimo/_plugins/ui/_impl/table.py", line 993, in clamp_rows_and_columns
    return data.to_json_str(self._format_mapping)
           ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/miccoli/Library/Caches/uv/archive-v0/Ck-eqMWEHKlm2XOA3iosB/lib/python3.13/site-packages/marimo/_plugins/ui/_impl/tables/polars_table.py", line 147, in to_json_str
    return sanitize_json_bigint(result.write_json())
                                ~~~~~~~~~~~~~~~~~^^
  File "/Users/miccoli/Library/Caches/uv/archive-v0/Ck-eqMWEHKlm2XOA3iosB/lib/python3.13/site-packages/polars/dataframe/frame.py", line 2819, in write_json
    return write_json_to_string()
  File "/Users/miccoli/Library/Caches/uv/archive-v0/Ck-eqMWEHKlm2XOA3iosB/lib/python3.13/site-packages/polars/dataframe/frame.py", line 2814, in write_json_to_string
    self._df.write_json(buf)
    ~~~~~~~~~~~~~~~~~~~^^^^^
pyo3_runtime.PanicException: called `Result::unwrap()` on an `Err` value: ComputeError(ErrString("The children DataTypes of a StructArray must equal the children data types.\n                         However, the field 1 has data type LargeList(Field { name: \"item\", dtype: Dictionary(UInt32, Utf8View, false), is_nullable: true, metadata: Some({\"_PL_ENUM_VALUES\": \"1;A1;B1;C\"}) }) but the value has data type LargeList(Field { name: \"item\", dtype: Dictionary(UInt32, Utf8View, false), is_nullable: true, metadata: None })"))

Will you submit a PR?

  • Yes

Environment

{
  "marimo": "0.14.10",
  "OS": "Darwin",
  "OS Version": "24.5.0",
  "Processor": "arm",
  "Python Version": "3.13.3",
  "Binaries": {
    "Browser": "138.0.7204.93",
    "Node": "v24.3.0"
  },
  "Dependencies": {
    "click": "8.2.1",
    "docutils": "0.21.2",
    "itsdangerous": "2.2.0",
    "jedi": "0.19.2",
    "markdown": "3.8.2",
    "narwhals": "1.46.0",
    "packaging": "25.0",
    "psutil": "7.0.0",
    "pygments": "2.19.2",
    "pymdown-extensions": "10.16",
    "pyyaml": "6.0.2",
    "starlette": "0.47.1",
    "tomlkit": "0.13.3",
    "typing-extensions": "missing",
    "uvicorn": "0.35.0",
    "websockets": "15.0.1"
  },
  "Optional Dependencies": {
    "polars": "1.31.0",
    "loro": "1.5.2"
  },
  "Experimental Flags": {}
}

Code to reproduce

# /// script
# requires-python = ">=3.13"
# dependencies = [
#     "marimo",
#     "polars==1.31.0",
# ]
# ///

import marimo

__generated_with = "0.14.10"
app = marimo.App(width="medium")


@app.cell
def _():
    import marimo as mo
    import polars as pl

    enum = pl.Enum(categories=["A", "B", "C"])
    df = pl.DataFrame({"a": [["A", "B", "C"]]}, schema={"a": pl.List(enum)})
    return df, mo


@app.cell
def _(df, mo):
    # mo.plain works as expected
    mo.plain(df)
    return


@app.cell
def _(df):
    # bare df fails
    df
    return


@app.cell
def _(df, mo):
    # PanicException
    mo.ui.table(df)
    return


if __name__ == "__main__":
    app.run()

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions