code: def test_add_margins():
      data = mtcars.loc[:, ["mpg", "disp", "vs", "am", "gear"]]
      n = len(data)
      all_lst = ["(all)"] * n
  
      vars = [("vs", "am"), ("gear",)]
      datax = add_margins(data, vars, True)
  
      assert datax["vs"].dtype == "category"
      assert datax["am"].dtype == "category"
      assert datax["gear"].dtype == "category"
  
      # What we expect, where each row is of
      # column length n
      #
      # mpg   disp   vs     am     gear
      # ---   ----   --     --     ----
      # *     *      *      *      *
      # *     *      (all)  (all)  *
      # *     *      *      (all)  *
      # *     *      *      *      (all)
      # *     *      (all)  (all)  (all)
      # *     *      *      (all)  (all)
  
      assert all(datax.loc[0 : n - 1, "am"] != all_lst)
      assert all(datax.loc[0 : n - 1, "vs"] != all_lst)
      assert all(datax.loc[0 : n - 1, "gear"] != all_lst)
  
      assert all(datax.loc[n : 2 * n - 1, "vs"] == all_lst)
      assert all(datax.loc[n : 2 * n - 1, "am"] == all_lst)
  
      assert all(datax.loc[2 * n : 3 * n - 1, "am"] == all_lst)
  
      assert all(datax.loc[3 * n : 4 * n - 1, "gear"] == all_lst)
  
      assert all(datax.loc[4 * n : 5 * n - 1, "am"] == all_lst)
      assert all(datax.loc[4 * n : 5 * n - 1, "vs"] == all_lst)
      assert all(datax.loc[4 * n : 5 * n - 1, "gear"] == all_lst)
  
      assert all(datax.loc[5 * n : 6 * n - 1, "am"] == all_lst)
      assert all(datax.loc[5 * n : 6 * n - 1, "gear"] == all_lst)
  
file_path: plotnine/tests/test_utils.py
imports: import itertools
  import random
  import string
  import warnings
  import numpy
  import pandas
  from plotnine._utils import _margins, add_margins, join_keys, match, ninteraction, pivot_apply, remove_missing, uniquecols
  from plotnine.data import mtcars
label_desc: Use image node_id 2 for calling a global function with example usage: test_add_margins() without return types