code: def test_nested_cache_composition() -> None:
      # very artificial example/test, but validates the behaviour
      # of nested StringCache scopes, which we want to play well
      # with each other when composing more complex pipelines.
  
      assert pl.using_string_cache() is False
  
      # function representing a composable stage of a pipeline; it implements
      # an inner scope for the case where it is called by itself, but when
      # called as part of a larger series of ops it should not invalidate
      # the string cache (eg: the outermost scope should be respected).
      def create_lazy(data: dict) -> pl.LazyFrame:  # type: ignore[type-arg]
          with pl.StringCache():
              df = pl.DataFrame(
                  {"a": ["foo", "bar", "ham"], "b": [1, 2, 3]}
              )
              lf = df.with_columns(
                  pl.col("a").cast(pl.Categorical)
              ).lazy()
  
          # confirm that scope-exit does NOT invalidate the
          # cache yet, as an outer context is still active
          assert pl.using_string_cache() is True
          return lf
  
      # this outer scope should be respected
      with pl.StringCache():
          lf1 = create_lazy(
              {"a": ["foo", "bar", "ham"], "b": [1, 2, 3]}
          )
          lf2 = create_lazy(
              {"a": ["spam", "foo", "eggs"], "c": [3, 2, 2]}
          )
  
          res = lf1.join(lf2, on="a", how="inner").collect().rows()
          assert sorted(res) == [
              ("bar", 2, 2),
              ("foo", 1, 1),
              ("ham", 3, 3),
          ]
  
      # no other scope active; NOW we expect the cache to have been invalidated
      assert pl.using_string_cache() is False
  
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 19 for calling a global function with example usage: test_nested_cache_composition() and returns: lf