Skip to content

fix: use standard linear interpolation for Percentile#93

Merged
montanaflynn merged 1 commit intomasterfrom
fix/issue-92-percentile-interpolation
Mar 11, 2026
Merged

fix: use standard linear interpolation for Percentile#93
montanaflynn merged 1 commit intomasterfrom
fix/issue-92-percentile-interpolation

Conversation

@montanaflynn
Copy link
Copy Markdown
Owner

Summary

  • Replaces the non-standard percentile algorithm with the NIST Linear Interpolation Between Closest Ranks method
  • Now matches Excel PERCENTILE, Google Sheets, NumPy (default), and other standard tools
  • Adds test case from the issue to prevent regression

Algorithm

rank = (p / 100) * (n - 1)
result = data[k] + f * (data[k+1] - data[k])

Where k is the integer part and f is the fractional part of rank.

Reference: https://www.itl.nist.gov/div898/handbook/prc/section2/prc262.htm

Test plan

  • All existing tests updated and passing
  • Added TestPercentile_Issue92 with the exact values from the issue report
  • Verified results match Excel, Google Sheets, and NumPy

Fixes #92

The previous algorithm used a non-standard formula that produced
incorrect results. This switches to the NIST linear interpolation
method, matching Excel PERCENTILE, Google Sheets, and NumPy.

Fixes #92
@montanaflynn montanaflynn merged commit e317bbb into master Mar 11, 2026
2 checks passed
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 11, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (8743180) to head (5aaeda5).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff            @@
##            master       #93   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           28        28           
  Lines          908       905    -3     
=========================================
- Hits           908       905    -3     

☔ 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.

@montanaflynn montanaflynn deleted the fix/issue-92-percentile-interpolation branch March 24, 2026 22:41
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.

Percentile values seem wrong

1 participant