code: def test_list_concat_rolling_window() -> None:
      # inspired by:
      # https://stackoverflow.com/questions/70377100/use-the-rolling-function-of-polars-to-get-a-list-of-all-values-in-the-rolling-wi
      # this tests if it works without specifically creating list dtype upfront. note that
      # the given answer is preferred over this snippet as that reuses the list array when
      # shifting
      df = pl.DataFrame(
          {
              "A": [1.0, 2.0, 9.0, 2.0, 13.0],
          }
      )
      out = df.with_columns(
          [pl.col("A").shift(i).alias(f"A_lag_{i}") for i in range(3)]
      ).select(
          [
              pl.concat_list(
                  [f"A_lag_{i}" for i in range(3)][::-1]
              ).alias("A_rolling")
          ]
      )
      assert out.shape == (5, 1)
  
      s = out.to_series()
      assert s.dtype == pl.List
      assert s.to_list() == [
          [None, None, 1.0],
          [None, 1.0, 2.0],
          [1.0, 2.0, 9.0],
          [2.0, 9.0, 2.0],
          [9.0, 2.0, 13.0],
      ]
  
      # this test proper null behavior of concat list
      out = (
          df.with_columns(
              pl.col("A").reshape((-1, 1))
          )  # first turn into a list
          .with_columns(
              [
                  pl.col("A").shift(i).alias(f"A_lag_{i}")
                  for i in range(3)  # slice the lists to a lag
              ]
          )
          .select(
              [
                  pl.all(),
                  pl.concat_list(
                      [f"A_lag_{i}" for i in range(3)][::-1]
                  ).alias("A_rolling"),
              ]
          )
      )
      assert out.shape == (5, 5)
  
      l64 = pl.List(pl.Float64)
      assert out.schema == {
          "A": l64,
          "A_lag_0": l64,
          "A_lag_1": l64,
          "A_lag_2": l64,
          "A_rolling": l64,
      }
  
imports: from __future__ import annotations
  from datetime import date, datetime
  from typing import TYPE_CHECKING
  import pytest
  import polars
  from polars.testing import assert_frame_equal, assert_series_equal
label_desc: Use image node_id 14 for calling a global function with example usage: test_list_concat_rolling_window() without return types