Skip to content

Conversation

@AlexanderJCS
Copy link
Contributor

Before this change, _correl_pvalue would create a division by zero warning when r==1.

Simply adding the condition near the top of the function:

    if np.isclose(r**2, 1):  # Avoid divide by zero error
        return 0.0  # Since p value approaches 0 as r approaches 1, just return 0

Fixes this. This assumes that n >= 2 since p would be undefined if n < 2, but I did not account for this case since it seems that the function already assumes that n >= 2.

Please let me know if you want me to make any other changes.

@codecov
Copy link

codecov bot commented Jul 12, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.54%. Comparing base (c939d2d) to head (c1070de).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #474   +/-   ##
=======================================
  Coverage   98.54%   98.54%           
=======================================
  Files          19       19           
  Lines        3360     3362    +2     
  Branches      492      493    +1     
=======================================
+ Hits         3311     3313    +2     
  Misses         26       26           
  Partials       23       23           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Owner

@raphaelvallat raphaelvallat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @AlexanderJCS — apologies for the long delay. One request to update the tests to make sure this line is covered by the tests. Thanks


if np.isclose(r**2, 1): # Avoid divide by zero error
return 0.0 # Since p value approaches 0 as r approaches 1, just return 0

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add a test in https://github.com/raphaelvallat/pingouin/blob/main/tests/test_correlation.py test_corr function:

stats = corr(x, x, method="percbend")  # calls _correl_pvalue
assert np.isclose(stats.at["percbend", "r"], 1)
assert np.isclose(stats.at["percbend", "p_val"], 0)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Raphael, I added these lines in the test_corr(self) function under the perfect correlation test for the pearson method.

@AlexanderJCS
Copy link
Contributor Author

AlexanderJCS commented Jul 25, 2025

@raphaelvallat The edge case is covered by the correlation test. Please let me know if there's anything else you would like me to change.

@AlexanderJCS
Copy link
Contributor Author

Hi @raphaelvallat, any updates on the status of this PR?

Copy link
Owner

@raphaelvallat raphaelvallat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved and merging now, thanks!

@raphaelvallat raphaelvallat merged commit cfaa5db into raphaelvallat:main Aug 30, 2025
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants