code: def test_list_to_struct() -> None:
      df = pl.DataFrame({"a": [[1, 2, 3], [1, 2]]})
      assert df.select(
          [pl.col("a").list.to_struct()]
      ).to_series().to_list() == [
          {"field_0": 1, "field_1": 2, "field_2": 3},
          {"field_0": 1, "field_1": 2, "field_2": None},
      ]
  
      df = pl.DataFrame({"a": [[1, 2], [1, 2, 3]]})
      assert df.select(
          [
              pl.col("a").list.to_struct(
                  fields=lambda idx: f"col_name_{idx}"
              )
          ]
      ).to_series().to_list() == [
          {"col_name_0": 1, "col_name_1": 2},
          {"col_name_0": 1, "col_name_1": 2},
      ]
  
      df = pl.DataFrame({"a": [[1, 2], [1, 2, 3]]})
      assert df.select(
          [pl.col("a").list.to_struct(n_field_strategy="max_width")]
      ).to_series().to_list() == [
          {"field_0": 1, "field_1": 2, "field_2": None},
          {"field_0": 1, "field_1": 2, "field_2": 3},
      ]
  
      # set upper bound
      df = pl.DataFrame({"lists": [[1, 1, 1], [0, 1, 0], [1, 0, 0]]})
      assert df.lazy().select(
          pl.col("lists").list.to_struct(upper_bound=3)
      ).unnest("lists").sum().collect().columns == [
          "field_0",
          "field_1",
          "field_2",
      ]
  
imports: from __future__ import annotations
  from dataclasses import dataclass
  from datetime import datetime, time
  from typing import TYPE_CHECKING
  import pandas
  import pyarrow
  import pytest
  import polars
  import polars.selectors
  from polars.testing import assert_frame_equal, assert_series_equal
label_desc: Use image node_id 15 for calling a global function with example usage: test_list_to_struct() without return types