code: def test_group_by_iteration() -> None:
      df = pl.DataFrame(
          {
              "foo": ["a", "b", "a", "b", "b", "c"],
              "bar": [1, 2, 3, 4, 5, 6],
              "baz": [6, 5, 4, 3, 2, 1],
          }
      )
      expected_names = ["a", "b", "c"]
      expected_rows = [
          [("a", 1, 6), ("a", 3, 4)],
          [("b", 2, 5), ("b", 4, 3), ("b", 5, 2)],
          [("c", 6, 1)],
      ]
      for i, (group, data) in enumerate(
          df.group_by("foo", maintain_order=True)
      ):
          assert group == expected_names[i]
          assert data.rows() == expected_rows[i]
  
      # Grouped by ALL columns should give groups of a single row
      result = list(df.group_by(["foo", "bar", "baz"]))
      assert len(result) == 6
  
      # Iterating over groups should also work when grouping by expressions
      result2 = list(
          df.group_by(["foo", pl.col("bar") * pl.col("baz")])
      )
      assert len(result2) == 5
  
      # Single column, alias in group_by
      df = pl.DataFrame({"foo": [1, 2, 3, 4, 5, 6]})
      gb = df.group_by(
          (pl.col("foo") // 2).alias("bar"), maintain_order=True
      )
      result3 = [(group, df.rows()) for group, df in gb]
      expected3 = [
          (0, [(1,)]),
          (1, [(2,), (3,)]),
          (2, [(4,), (5,)]),
          (3, [(6,)]),
      ]
      assert result3 == expected3
  
imports: from __future__ import annotations
  from collections import OrderedDict
  from datetime import datetime, timedelta
  from typing import Any
  import pytest
  import polars
  from polars.testing import assert_frame_equal, assert_series_equal
label_desc: Use image node_id 7 for calling a global function with example usage: test_group_by_iteration() without return types