Skip to content

Commit

Permalink
Merge pull request #160 from sappelhoff/safetyfirst
Browse files Browse the repository at this point in the history
[BUGFIX] Add safety check for `tail` argument in corr func
  • Loading branch information
raphaelvallat authored Feb 25, 2021
2 parents 0c3bf73 + c189281 commit 708d084
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
9 changes: 9 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@
What's new
##########

v0.3.11 (unreleased)
--------------------

**Bugfixes**

a. Passing a wrong ``tail`` argument to :py:func:`pingouin.correlation.corr` now *always* raises an error (see `PR 160 <https://github.com/raphaelvallat/pingouin/pull/160>`_).
In previous versions of ``pingouin``, using any ``method`` other than ``"pearson"`` and a wrong ``tail`` argument such as ``"two-tailed"`` or ``"both"``
(instead of the correct ``"two-sided"``) may have resulted in silently returning a one-sided p-value.

v0.3.10 (February 2021)
-----------------------

Expand Down
4 changes: 3 additions & 1 deletion pingouin/correlation.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,8 @@ def corr(x, y, tail='two-sided', method='pearson', **kwargs):
y = np.asarray(y)
assert x.ndim == y.ndim == 1, 'x and y must be 1D array.'
assert x.size == y.size, 'x and y must have the same length.'
_msg = 'tail must be "two-sided" or "one-sided".'
assert tail in ['two-sided', 'one-sided'], _msg

# Remove rows with missing values
x, y = remove_na(x, y, paired=True)
Expand All @@ -529,7 +531,7 @@ def corr(x, y, tail='two-sided', method='pearson', **kwargs):
elif method == 'skipped':
r, pval, outliers = skipped(x, y, **kwargs)
else:
raise ValueError('Method not recognized.')
raise ValueError(f'Method "{method}" not recognized.')

if np.isnan(r):
# Correlation failed -- new in version v0.3.4, instead of raising an
Expand Down

0 comments on commit 708d084

Please sign in to comment.