code: def test_incremental():
      # incr_dbuilder(s)
      # stateful transformations
      datas = [
          {"a": ["a2", "a2", "a2"], "x": [1, 2, 3]},
          {"a": ["a2", "a2", "a1"], "x": [4, 5, 6]},
      ]
      x = np.asarray([1, 2, 3, 4, 5, 6])
      sin_center_x = np.sin(x - np.mean(x))
      x_col = sin_center_x - np.mean(sin_center_x)
  
      def data_iter_maker():
          return iter(datas)
  
      builders = incr_dbuilders(
          "1 ~ a + center(np.sin(center(x)))", data_iter_maker
      )
      lhs, rhs = build_design_matrices(builders, datas[1])
      assert lhs.design_info.column_names == ["Intercept"]
      assert rhs.design_info.column_names == [
          "Intercept",
          "a[T.a2]",
          "center(np.sin(center(x)))",
      ]
      assert np.allclose(lhs, [[1], [1], [1]])
      assert np.allclose(
          rhs, np.column_stack(([1, 1, 1], [1, 1, 0], x_col[3:]))
      )
  
      builder = incr_dbuilder(
          "~ a + center(np.sin(center(x)))", data_iter_maker
      )
      (rhs,) = build_design_matrices([builder], datas[1])
      assert rhs.design_info.column_names == [
          "Intercept",
          "a[T.a2]",
          "center(np.sin(center(x)))",
      ]
      assert np.allclose(lhs, [[1], [1], [1]])
      assert np.allclose(
          rhs, np.column_stack(([1, 1, 1], [1, 1, 0], x_col[3:]))
      )
  
      pytest.raises(PatsyError, incr_dbuilder, "x ~ x", data_iter_maker)
      pytest.raises(PatsyError, incr_dbuilders, "x", data_iter_maker)
  
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 12 for calling a global function with example usage: test_incremental() and returns: iter