code: def test_categorize():
      # rename y to y_ to avoid pandas future warning about ambiguous
      # levels
      pdf = frames4[0]
      if pyarrow_strings_enabled():
          # we explicitly provide meta, so it has to have pyarrow strings
          pdf = to_pyarrow_string(pdf)
      meta = clear_known_categories(pdf).rename(columns={"y": "y_"})
      dsk = {("unknown", i): df for (i, df) in enumerate(frames3)}
      if not dd._dask_expr_enabled():
          ddf = (
              dd.DataFrame(
                  dsk,
                  "unknown",
                  make_meta(
                      meta,
                      parent_meta=frames[0],
                  ),
                  [None] * 4,
              )
              .repartition(npartitions=10)
              .rename(columns={"y": "y_"})
          )
      else:
          pdf = (
              pd.concat(dsk.values())
              .rename(columns={"y": "y_"})
              .astype({"w": "category", "y_": "category"})
          )
          pdf.index = pdf.index.astype("category")
          ddf = dd.from_pandas(pdf, npartitions=4, sort=False)
          ddf["w"] = ddf.w.cat.as_unknown()
          ddf["y_"] = ddf.y_.cat.as_unknown()
          ddf.index = ddf.index.cat.as_unknown()
  
      ddf = ddf.assign(w=ddf.w.cat.set_categories(["x", "y", "z"]))
      assert ddf.w.cat.known
      assert not ddf.y_.cat.known
      assert not ddf.index.cat.known
      df = ddf.compute()
  
      for index in [None, True, False]:
          known_index = index is not False
          # By default categorize object and unknown cat columns
          ddf2 = ddf.categorize(index=index)
          assert ddf2.y_.cat.known
          assert ddf2.v.cat.known
          assert ddf2.index.cat.known == known_index
          assert_eq(
              ddf2,
              df.astype({"v": "category"}),
              check_categorical=False,
          )
  
          # Specifying split_every works
          ddf2 = ddf.categorize(index=index, split_every=2)
          assert ddf2.y_.cat.known
          assert ddf2.v.cat.known
          assert ddf2.index.cat.known == known_index
          assert_eq(
              ddf2,
              df.astype({"v": "category"}),
              check_categorical=False,
          )
  
          # Specifying one column doesn't affect others
          ddf2 = ddf.categorize("v", index=index)
          assert not ddf2.y_.cat.known
          assert ddf2.v.cat.known
          assert ddf2.index.cat.known == known_index
          assert_eq(
              ddf2,
              df.astype({"v": "category"}),
              check_categorical=False,
          )
  
          ddf2 = ddf.categorize("y_", index=index)
          assert ddf2.y_.cat.known
          if not dd._dask_expr_enabled():
              assert ddf2.v.dtype == get_string_dtype()
          else:
              assert ddf.v.dtype == object
          assert ddf2.index.cat.known == known_index
          assert_eq(ddf2, df)
  
      ddf_known_index = ddf.categorize(columns=[], index=True)
      assert ddf_known_index.index.cat.known
      assert_eq(ddf_known_index, df)
  
      # Specifying known categorical or no columns is a no-op:
      assert ddf.categorize(["w"], index=False) is ddf
      assert ddf.categorize([], index=False) is ddf
      assert ddf_known_index.categorize(["w"]) is ddf_known_index
      assert ddf_known_index.categorize([]) is ddf_known_index
  
      # Bad split_every fails
      with pytest.raises(ValueError):
          ddf.categorize(split_every=1)
  
      with pytest.raises(ValueError):
          ddf.categorize(split_every="foo")
  
imports: from __future__ import annotations
  import contextlib
  import operator
  import warnings
  import numpy
  import pandas
  import pytest
  import dask
  import dask.dataframe
  from dask.dataframe import _compat
  from dask.dataframe._compat import PANDAS_GE_150, PANDAS_GE_200, PANDAS_GE_210, tm
  from dask.dataframe._pyarrow import to_pyarrow_string
  from dask.dataframe.core import _concat
  from dask.dataframe.utils import assert_eq, clear_known_categories, get_string_dtype, make_meta, pyarrow_strings_enabled
label_desc: Use image node_id 3 for calling a global function with example usage: test_categorize() without return types