code: def test_categorical_sort_order(monkeypatch: Any) -> None:
      # create the categorical ordering first
      pl.Series(["foo", "bar", "baz"], dtype=pl.Categorical)
      df = pl.DataFrame(
          {
              "n": [0, 0, 0],
              # use same categories in different order
              "x": pl.Series(
                  ["baz", "bar", "foo"], dtype=pl.Categorical
              ),
          }
      )
  
      assert df.sort(["n", "x"])["x"].to_list() == ["foo", "bar", "baz"]
      assert df.with_columns(
          pl.col("x").cat.set_ordering("lexical")
      ).sort(["n", "x"])["x"].to_list() == ["bar", "baz", "foo"]
      monkeypatch.setenv("POLARS_ROW_FMT_SORT", "1")
      assert df.sort(["n", "x"])["x"].to_list() == ["foo", "bar", "baz"]
      assert df.with_columns(
          pl.col("x").cat.set_ordering("lexical")
      ).sort(["n", "x"])["x"].to_list() == ["bar", "baz", "foo"]
      assert df.with_columns(
          pl.col("x").cast(pl.Categorical("lexical"))
      ).sort(["n", "x"])["x"].to_list() == ["bar", "baz", "foo"]
  
imports: from __future__ import annotations
  import contextlib
  import io
  import operator
  from typing import TYPE_CHECKING, Any, Callable, Literal
  import pytest
  import polars
  from polars import StringCache
  from polars.exceptions import CategoricalRemappingWarning, StringCacheMismatchError
  from polars.testing import assert_frame_equal, assert_series_equal
label_desc: Use image node_id 24 for calling a global function with example usage: test_categorical_sort_order(monkeypatch) without return types