Skip to content

Commit

Permalink
Merge pull request #161 from ViktorWase/master
Browse files Browse the repository at this point in the history
Improved error message of partial_corr when x is in covar
  • Loading branch information
raphaelvallat authored Mar 13, 2021
2 parents 708d084 + d87779d commit 91b1847
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pingouin/correlation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
3 changes: 3 additions & 0 deletions pingouin/tests/test_correlation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down

0 comments on commit 91b1847

Please sign in to comment.