From f73f2f1b07a71f90e7fe041bc1d1e94d1ba4c8e6 Mon Sep 17 00:00:00 2001 From: "Malte S. Kurz" Date: Fri, 22 Dec 2023 15:38:10 +0100 Subject: [PATCH] since rpy2 3.5.12 invisible r objects are no longer returned --- vineknockoffs/_utils_kde1d.py | 12 ++++++------ vineknockoffs/_utils_knockoffs.py | 2 +- vineknockoffs/_utils_vine_copulas.py | 4 ++-- vineknockoffs/tests/_utils_py_vs_r_vinecopula.py | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/vineknockoffs/_utils_kde1d.py b/vineknockoffs/_utils_kde1d.py index f09aa62..466949e 100644 --- a/vineknockoffs/_utils_kde1d.py +++ b/vineknockoffs/_utils_kde1d.py @@ -12,39 +12,39 @@ r_kde1d_fit = robjects.r(''' - kde_fit <- function(x) { + function(x) { return(kde1d::kde1d(x)) } ''') r_kde1d_discrete_fit = robjects.r(''' - kde_fit <- function(x, levels) { + function(x, levels) { x <- ordered(x, levels=levels) return(kde1d::kde1d(x)) } ''') r_kde1d_cdf_eval = robjects.r(''' - cdf_eval <- function(kde_fit, x) { + function(kde_fit, x) { return(kde1d::pkde1d(x, kde_fit)) } ''') r_kde1d_invcdf_eval = robjects.r(''' - invcdf_eval <- function(kde_fit, x) { + function(kde_fit, x) { return(kde1d::qkde1d(x, kde_fit)) } ''') r_kde1d_discrete_invcdf_eval = robjects.r(''' - invcdf_eval <- function(kde_fit, x) { + function(kde_fit, x) { res <- kde1d::qkde1d(x, kde_fit) return(as.numeric(levels(res)[res])) } ''') r_kde1d_pdf_eval = robjects.r(''' - pdf_eval <- function(kde_fit, x) { + function(kde_fit, x) { return(kde1d::dkde1d(x, kde_fit)) } ''') diff --git a/vineknockoffs/_utils_knockoffs.py b/vineknockoffs/_utils_knockoffs.py index fc194b8..536e6b5 100644 --- a/vineknockoffs/_utils_knockoffs.py +++ b/vineknockoffs/_utils_knockoffs.py @@ -12,7 +12,7 @@ cv_glmnet_r = robjects.r(''' - cv_glmnet <- function(x, y, s) { + function(x, y, s) { fit <- glmnet::cv.glmnet(x, y) return(as.numeric(coef(fit, s=s))) } diff --git a/vineknockoffs/_utils_vine_copulas.py b/vineknockoffs/_utils_vine_copulas.py index e74a35e..9581fd9 100644 --- a/vineknockoffs/_utils_vine_copulas.py +++ b/vineknockoffs/_utils_vine_copulas.py @@ -12,7 +12,7 @@ if _has_rpy2: _has_r_tsp = robjects.r('library("TSP", quietly=TRUE, logical.return=TRUE)')[0] r_solve_tsp = robjects.r(''' - solve_tsp <- function(one_m_tau_mat) { + function(one_m_tau_mat) { hamilton = TSP::insert_dummy(TSP::TSP(one_m_tau_mat), label = "cut") sol = TSP::solve_TSP(hamilton, method = "repetitive_nn") order = TSP::cut_tour(sol, "cut") @@ -53,7 +53,7 @@ def d_vine_structure_select(u, tsp_method='r_tsp'): if not (_has_rpy2 and _has_r_tsp): raise ImportError('To determine the D-vine structure with method r_tsp the python package rpy2 and the R ' 'package TSP are required.') - permutation = r_solve_tsp(tau_mat)-1 + permutation = np.array(r_solve_tsp(tau_mat))-1 else: assert tsp_method == 'py_tsp' permutation, _ = solve_tsp_dynamic_programming(tau_mat) diff --git a/vineknockoffs/tests/_utils_py_vs_r_vinecopula.py b/vineknockoffs/tests/_utils_py_vs_r_vinecopula.py index 98d800c..a6c01a8 100644 --- a/vineknockoffs/tests/_utils_py_vs_r_vinecopula.py +++ b/vineknockoffs/tests/_utils_py_vs_r_vinecopula.py @@ -28,7 +28,7 @@ def py_copula_funs_eval(data, cop_obj, fun_type): r_copula_funs_eval = robjects.r(''' library(VineCopula) - copula_funs_eval <- function(u, v, family, par, type) { + function(u, v, family, par, type) { if (type == 'cdf'){ res = BiCopCDF(u, v, family, par)