code: def test_sorted_group_by_optimization(monkeypatch: Any) -> None:
      monkeypatch.setenv("POLARS_NO_STREAMING_GROUPBY", "1")
  
      df = pl.DataFrame({"a": np.random.randint(0, 5, 20)})
  
      # the sorted optimization should not randomize the
      # groups, so this is tests that we hit the sorted optimization
      for descending in [True, False]:
          sorted_implicit = (
              df.with_columns(pl.col("a").sort(descending=descending))
              .group_by("a")
              .agg(pl.count())
          )
          sorted_explicit = (
              df.group_by("a")
              .agg(pl.count())
              .sort("a", descending=descending)
          )
          assert_frame_equal(sorted_explicit, sorted_implicit)
  
imports: from __future__ import annotations
  from datetime import datetime, timedelta
  from typing import Any
  import numpy
  import pandas
  import polars
  from polars.testing import assert_frame_equal
label_desc: Use image node_id 7 for calling a global function with example usage: test_sorted_group_by_optimization(monkeypatch) without return types