Causal Fairness Analysis - from Python

import pandas as pd
import rpy2.robjects as ro
from rpy2.robjects.packages import importr
from rpy2.robjects import pandas2ri
from rpy2.robjects.vectors import StrVector
from rpy2.robjects.conversion import localconverter
compas_path = os.path.join(git_root, "scripts", "fair-prediction",
                           "compas-preprocessed.csv")

compas = pd.read_csv(compas_path)
compas.drop(compas.columns[0], axis=1, inplace=True)

with localconverter(ro.default_converter + pandas2ri.converter):
  r_compas = ro.conversion.py2rpy(compas)

faircause = importr('faircause')

fc_compas = faircause.fairness_cookbook(
  r_compas, X = "race",
  W = StrVector(["juv_fel", "juv_misd", "juv_other", "priors", "charge"]),
  Z = StrVector(["age", "sex"]),
  Y = "two_year_recid",
  x0 = 0,
  x1 = 1
)

print(ro.r.summary(fc_compas).rx2("measures"))

    WARNING: The R package "reticulate" only fixed recently
    an issue that caused a segfault when used with rpy2:
    https://github.com/rstudio/reticulate/pull/1188
    Make sure that you use a version of that package that includes
    the fix.
              measure       value          sd
ctfde       ctfde -0.05267448 0.008506597
ctfie       ctfie  0.07872395 0.008864717
ctfse       ctfse  0.03724921 0.009534149
ett           ett -0.13139843 0.006831753
expse_x0 expse_x0  0.01684047 0.001207810
expse_x1 expse_x1 -0.03331364 0.002440835
nde           nde -0.03042546 0.011378097
nie           nie  0.08806808 0.007254499
te             te -0.11849353 0.011704603
tv             tv -0.16864764 0.012047903