From d87779d0394d034e740962f305bcb649b30b1b34 Mon Sep 17 00:00:00 2001 From: Viktor Wase Date: Sat, 13 Mar 2021 12:04:06 +0100 Subject: [PATCH] Improved error message of partial_corr when x is in covar --- pingouin/correlation.py | 3 +++ pingouin/tests/test_correlation.py | 3 +++ 2 files changed, 6 insertions(+) diff --git a/pingouin/correlation.py b/pingouin/correlation.py index 3e16cc3d..e98c30c7 100644 --- a/pingouin/correlation.py +++ b/pingouin/correlation.py @@ -719,6 +719,9 @@ def partial_corr(data=None, x=None, y=None, covar=None, x_covar=None, assert x != covar, 'x and covar must be independent' assert y != covar, 'y and covar must be independent' assert x != y, 'x and y must be independent' + if isinstance(covar, list): + assert x not in covar, 'x and covar must be independent' + assert y not in covar, 'y and covar must be independent' # Check that columns exist col = _flatten_list([x, y, covar, x_covar, y_covar]) if isinstance(covar, str): diff --git a/pingouin/tests/test_correlation.py b/pingouin/tests/test_correlation.py index 126d0248..fffdad25 100644 --- a/pingouin/tests/test_correlation.py +++ b/pingouin/tests/test_correlation.py @@ -92,6 +92,9 @@ def test_partial_corr(self): y_covar=['cv2', 'cv3'], method='spearman') with pytest.raises(ValueError): partial_corr(data=df, x='x', y='y', covar='cv2', x_covar='cv1') + with pytest.raises(AssertionError) as error_info: + partial_corr(data=df, x='cv1', y='y', covar=['cv1', 'cv2']) + assert str(error_info.value) == "x and covar must be independent" def test_rmcorr(self): """Test function rm_corr"""