code: def test_categorical():
      data = balanced(a=2, b=2)
      # There are more exhaustive tests for all the different coding options in
      # test_build; let's just make sure that C() and stuff works.
      t(
          "~ C(a)",
          data,
          0,
          True,
          [[1, 0], [1, 0], [1, 1], [1, 1]],
          ["Intercept", "C(a)[T.a2]"],
      )
      t(
          "~ C(a, levels=['a2', 'a1'])",
          data,
          0,
          True,
          [[1, 1], [1, 1], [1, 0], [1, 0]],
          ["Intercept", "C(a, levels=['a2', 'a1'])[T.a1]"],
      )
      t(
          "~ C(a, Treatment(reference=-1))",
          data,
          0,
          True,
          [[1, 1], [1, 1], [1, 0], [1, 0]],
          ["Intercept", "C(a, Treatment(reference=-1))[T.a1]"],
      )
  
      # Different interactions
      t(
          "a*b",
          data,
          0,
          True,
          [[1, 0, 0, 0], [1, 0, 1, 0], [1, 1, 0, 0], [1, 1, 1, 1]],
          ["Intercept", "a[T.a2]", "b[T.b2]", "a[T.a2]:b[T.b2]"],
      )
      t(
          "0 + a:b",
          data,
          0,
          True,
          [[1, 0, 0, 0], [0, 0, 1, 0], [0, 1, 0, 0], [0, 0, 0, 1]],
          ["a[a1]:b[b1]", "a[a2]:b[b1]", "a[a1]:b[b2]", "a[a2]:b[b2]"],
      )
      t(
          "1 + a + a:b",
          data,
          0,
          True,
          [[1, 0, 0, 0], [1, 0, 1, 0], [1, 1, 0, 0], [1, 1, 0, 1]],
          ["Intercept", "a[T.a2]", "a[a1]:b[T.b2]", "a[a2]:b[T.b2]"],
      )
  
      # Changing contrast with C()
      data["a"] = C(data["a"], Helmert)
      t(
          "a",
          data,
          0,
          True,
          [[1, -1], [1, -1], [1, 1], [1, 1]],
          ["Intercept", "a[H.a2]"],
      )
      t(
          "C(a, Treatment)",
          data,
          0,
          True,
          [[1, 0], [1, 0], [1, 1], [1, 1]],
          ["Intercept", "C(a, Treatment)[T.a2]"],
      )
      # That didn't affect the original object
      t(
          "a",
          data,
          0,
          True,
          [[1, -1], [1, -1], [1, 1], [1, 1]],
          ["Intercept", "a[H.a2]"],
      )
  
imports: import sys
  import __future__
  import six
  import numpy
  import pytest
  from patsy import PatsyError
  from patsy.design_info import DesignMatrix, DesignInfo
  from patsy.eval import EvalEnvironment
  from patsy.desc import ModelDesc, Term, INTERCEPT
  from patsy.categorical import C
  from patsy.contrasts import Helmert
  from patsy.user_util import balanced, LookupFactor
  from patsy.build import design_matrix_builders, build_design_matrices
  from patsy.highlevel import *
  from patsy.util import have_pandas, have_pandas_categorical, have_pandas_categorical_dtype, pandas_Categorical_from_codes
  from patsy.origin import Origin
label_desc: Use image node_id 10 for calling a global function with example usage: test_categorical() without return types