code: def test_train_subset_models():
      x = [
          "loan_amount",
          "loan_to_value_ratio",
          "no_intro_rate_period",
          "intro_rate_period",
          "property_value",
          "income",
          "debt_to_income_ratio",
          "term_360",
          "conforming",
      ]
  
      y = "high_priced"
  
      train = h2o.import_file(
          "https://raw.githubusercontent.com/h2oai/article-information-2019/master/data/output/hmda_train.csv"
      )
      test = h2o.import_file(
          "https://raw.githubusercontent.com/h2oai/article-information-2019/master/data/output/hmda_test.csv"
      )
      train = train[
          ~train["black"].isna()[0]
          & ~train["hispanic"].isna()[0]
          & ~train["male"].isna()[0]
          & ~train["agegte62"].isna()[0],
          :,
      ]
      test = test[
          ~test["black"].isna()[0]
          & ~test["hispanic"].isna()[0]
          & ~test["male"].isna()[0]
          & ~test["agegte62"].isna()[0],
          :,
      ]
      protected_columns = ["ethnic", "sex"]
      reference = ["white", "M"]
      favorable_class = "0"
      for d in [train, test]:
          d[:, y] = d[:, y].asfactor()
          d[d["black"] == 1, "ethnic"] = "black"
          d[d["asian"] == 1, "ethnic"] = "asian"
          d[d["white"] == 1, "ethnic"] = "white"
          d[d["amind"] == 1, "ethnic"] = "amind"
          d[d["hipac"] == 1, "ethnic"] = "hipac"
          d[d["hispanic"] == 1, "ethnic"] = "hispanic"
          d["sex"] = "NA"
          d[d["female"] == 1, "sex"] = "F"
          d[d["male"] == 1, "sex"] = "M"
          d["ethnic"] = d["ethnic"].asfactor()
          d["sex"] = d["sex"].asfactor()
  
      ig = H2OInfogram(protected_columns=["ethnic", "sex"])
      ig.train(x, y, training_frame=train)
  
      # GBM
      da = ig.train_subset_models(
          H2OGradientBoostingEstimator,
          y,
          train,
          test,
          protected_columns,
          reference,
          favorable_class,
      )
      assert da.nrows == 9
      assert (da[:, "air_min"] > 0.7).all()
      assert (da[:, "air_max"] < 1.2).all()
      assert (
          (da[:, "air_min"] > 0.8) & (da[:, "air_max"] < 1.25)
      ).any()  # four-fifths rule
      assert (
          (da[:, "cair"] > 0.8) & (da[:, "cair"] < 1.25)
      ).any()  # four-fifths rule
  
      # AutoML
      da = ig.train_subset_models(
          H2OAutoML,
          y,
          train,
          test,
          protected_columns,
          reference,
          favorable_class,
          max_models=2,
      )
      assert da.nrows == 2 * 9 + 9  # models + SEs
      # some SEs tend to be more unfair than base models, so I relaxed the condition here
      assert (
          (da[:, "air_min"] > 0.8) & (da[:, "air_max"] < 1.25)
      ).any()  # four-fifths rule
      assert (
          (da[:, "cair"] > 0.8) & (da[:, "cair"] < 1.25)
      ).any()  # four-fifths rule
  
      # GRID
      da = ig.train_subset_models(
          H2OGridSearch,
          y,
          train,
          test,
          protected_columns,
          reference,
          favorable_class,
          model=H2OGradientBoostingEstimator(),
          hyper_params=dict(ntrees=[1, 3, 5]),
      )
      assert da.nrows == 3 * 9
      assert (da[:, "air_min"] > 0.7).all()
      assert (da[:, "air_max"] < 1.2).all()
      assert (
          (da[:, "air_min"] > 0.8) & (da[:, "air_max"] < 1.25)
      ).any()  # four-fifths rule
      assert ((da[:, "cair"] > 0.8) & (da[:, "cair"] < 1.25)).any()
  
file_path: h2o-3/h2o-py/tests/testdir_misc/pyunit_fairness_grid.py
imports: import os
  import sys
  import h2o
  from tests import pyunit_utils, test_plot_result_saving
  from h2o.automl import H2OAutoML
  from h2o.estimators import *
  from h2o.grid import *
label_desc: Use image node_id 1 for calling a global function with example usage: test_train_subset_models() without return types