GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GH-95861: Add support for Spearman's rank correlation coefficient by rhettinger · Pull Request #95863 · python/cpython

Conversation

@rhettinger

@rhettinger rhettinger commented Aug 10, 2022 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Still need to think about whether by_rank is the best name for the flag.

  • Issue: Add Spearman correlation support to statistics.correlation() #95861

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@rhettinger rhettinger added type-feature A feature request or enhancement stdlib Standard Library Python modules in the Lib/ directory 3.12 only security fixes labels Aug 10, 2022
@rhettinger
rhettinger requested a review from stevendaprano August 10, 2022 22:42
@bedevere-bot bedevere-bot added the awaiting core review label Aug 10, 2022
@stevendaprano

stevendaprano commented Aug 13, 2022

Copy link
Copy Markdown
Member

See my early comment on #95861

I think we should make _rank public, and remove the "by_rank" parameter to correlation, moving that functionality into a thin wrapper function spearman. Otherwise this is good work, thank you.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

stevendaprano
stevendaprano reviewed Aug 13, 2022
View reviewed changes
Comment thread Lib/statistics.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

stevendaprano
stevendaprano suggested changes Aug 13, 2022
View reviewed changes

@stevendaprano stevendaprano left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

If you categorically disagree with my suggestion to make rank public and move spearman into its own named function, I will accept this (you've done the hard work writing the code and I do like the feature). But I do strongly request that we keep to the design of separate named functions rather than overloading the one function with a flag.

If you categorically want to keep the single correlation function, then we could future-proof it and make the type of correlation more explicit with an enumerated flag rather than a bool:

def correlation(x, y, /, kind='pearson'):
    if kind == 'spearman':
        x = _rank(x)
        y = _rank(y)
   elif kind != 'pearson':
       raise ValueError('unsupported correlation kind')

If we ever add another sort of correlation (say, Kendall tau) is would be awkward to handle a second bool flag.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bedevere-bot bedevere-bot removed the awaiting core review label Aug 13, 2022
@bedevere-bot

bedevere-bot commented Aug 13, 2022

Copy link
Copy Markdown

When you're done making the requested changes, leave the comment: I have made the requested changes; please review again.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot bedevere-bot added the awaiting changes label Aug 13, 2022
@rhettinger

rhettinger commented Aug 13, 2022

Copy link
Copy Markdown
Contributor Author

Thank you for responding quickly and thoughtfully.

I added some comments to the issue to help us get to a good meeting of the minds on the API.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@rhettinger rhettinger changed the title GH-95861: Add support for Pearson's correlation coefficient GH-95861: Add support for Spearman's rank correlation coefficient Aug 14, 2022
rhettinger added 9 commits August 18, 2022 12:43
@rhettinger
Add support for earson's correlation coefficient
8750d9c
@rhettinger
Add doctest. Remove unused "reversed" argument. Rename "ranked" to "b…
cb52524
…y_rank".
@rhettinger
Add docs
102a4c5
@rhettinger
Add test
97bfe04
@rhettinger
Remove use of underscorde in doctest.
bd3da1c
@rhettinger
Update the dispatch table
d0260bf
@rhettinger
Prepare _rank() to be made public in the future.
95a2176
@rhettinger
Replace flag with a "method" keyword argument for future proofing.
222699e
@rhettinger
Neaten up the docstring for _rank().
873e240
@rhettinger
rhettinger force-pushed the spearman branch from 51685a5 to 873e240 Compare August 18, 2022 17:43
@rhettinger
rhettinger merged commit 29c8f80 into python:main Aug 18, 2022
@bedevere-bot bedevere-bot removed the awaiting changes label Aug 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

1 more reviewer
@stevendaprano stevendaprano stevendaprano requested changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

3.12 only security fixes stdlib Standard Library Python modules in the Lib/ directory type-feature A feature request or enhancement

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@rhettinger @stevendaprano @bedevere-bot
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.