code: def check_cox(rossi, x, stratify_by, formula):
      if stratify_by:
          cph_py = CoxPHFitter(strata=stratify_by)
      else:
          cph_py = CoxPHFitter()
  
      for col in stratify_by:
          rossi[col] = rossi[col].astype("category")
  
      cph_py.fit(rossi, duration_col="week", event_col="arrest")
      cph_py.print_summary()
      rossi_h2o = h2o.H2OFrame(rossi)
  
      for col in stratify_by:
          rossi_h2o[col] = rossi_h2o[col].asfactor()
  
      cph_h2o = H2OCoxProportionalHazardsEstimator(
          stop_column="week", stratify_by=stratify_by
      )
      cph_h2o.train(x=x, y="arrest", training_frame=rossi_h2o)
  
      assert cph_h2o.model_id != ""
      assert cph_h2o.model_id != ""
      assert cph_h2o.formula() == formula, (
          "Expected formula to be '"
          + formula
          + "' but it was "
          + cph_h2o.formula()
      )
  
      predH2O = cph_h2o.predict(test_data=rossi_h2o)
      assert len(predH2O) == len(rossi)
      metrics_h2o = cph_h2o.model_performance(rossi_h2o)
      concordance_py = concordance_for_lifelines(cph_py)
      assert abs(concordance_py - metrics_h2o.concordance()) < 0.001
      hazard_h2o_as_pandas = (
          cph_h2o.baseline_hazard_frame.as_data_frame(use_pandas=True)
      )
  
      hazard_py = cph_py.baseline_hazard_
  
      for col_name in hazard_py.columns:
          hazard_py.rename(
              columns={col_name: str(col_name)}, inplace=True
          )
  
      hazard_py_reordered_columns = hazard_py.reset_index(
          drop=True
      ).sort_index(axis=1)
      hazard_h2o_reordered_columns = (
          hazard_h2o_as_pandas.drop("t", axis="columns")
          .reset_index(drop=True)
          .sort_index(axis=1)
      )
  
      hazard_py_reordered_columns = fix_py_result_for_older_lifelines(
          hazard_py_reordered_columns
      )
  
      print("h2o:")
      print(hazard_h2o_as_pandas.reset_index(drop=True))
  
      print("lifelines:")
      print(hazard_py_reordered_columns.reset_index(drop=True))
  
      assert_frame_equal(
          hazard_py_reordered_columns,
          hazard_h2o_reordered_columns,
          check_dtype=False,
          check_index_type=False,
          check_column_type=False,
      )
  
      survival_h2o_as_pandas = (
          cph_h2o.baseline_survival_frame.as_data_frame(use_pandas=True)
      )
  
      survival_py = cph_py.baseline_survival_
  
      for col_name in survival_py.columns:
          survival_py.rename(
              columns={col_name: str(col_name)}, inplace=True
          )
  
      survival_py_reordered_columns = survival_py.reset_index(
          drop=True
      ).sort_index(axis=1)
      survival_h2o_reordered_columns = (
          survival_h2o_as_pandas.drop("t", axis="columns")
          .reset_index(drop=True)
          .sort_index(axis=1)
      )
  
      survival_py_reordered_columns = fix_py_result_for_older_lifelines(
          survival_py_reordered_columns
      )
  
      print("h2o:")
      print(survival_h2o_as_pandas.reset_index(drop=True))
  
      print("lifelines:")
      print(survival_py_reordered_columns.reset_index(drop=True))
  
      assert_frame_equal(
          survival_py_reordered_columns,
          survival_h2o_reordered_columns,
          check_dtype=False,
          check_index_type=False,
          check_column_type=False,
      )
  
file_path: h2o-3/h2o-py/tests/testdir_algos/coxph/pyunit_coxph_concordance_survival.py
imports: import sys
  import h2o
  from lifelines import CoxPHFitter
  from lifelines.datasets import load_rossi
  from pandas.testing import assert_frame_equal
  from tests import pyunit_utils
  from h2o.estimators.coxph import H2OCoxProportionalHazardsEstimator
label_desc: Use image node_id 5 for calling a global function with example usage: check_cox(rossi, x, stratify_by, formula) without return types