Skip to content

MNT Move entropy to private function - #31294

Merged
glemaitre merged 14 commits into
scikit-learn:mainfrom
lucyleeow:doc_entropy
Jun 13, 2025
Merged

glemaitre merged 14 commits into
scikit-learn:mainfrom
lucyleeow:doc_entropy

Conversation

@lucyleeow

Copy link
Copy Markdown
Member

Reference Issues/PRs

Related to #31282

What does this implement/fix? Explain your changes.

entropy is not a API documented function (on purpose) so removing reference to it.

Any other comments?

cc @thomasjpfan

@github-actions

github-actions Bot commented May 2, 2025 •

Copy link
Copy Markdown

✔️ Linting Passed

All linting checks passed. Your pull request is in excellent shape! ☀️

Generated for commit: 7d07e09. Link to the linter CI: here

@jeremiedbb

Copy link
Copy Markdown
Member

Indded it's a private function that was never documented. Can you take the opportunity of this PR to remove param validation from this function and making it explicitely private with a leading underscore ?

@lucyleeow lucyleeow changed the title DOC Remove reference to entropy API MNT Move entropy to private function May 7, 2025

@jeremiedbb jeremiedbb left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm +1 to rename it with the leading underscore without deprecation since it was not documented.

However, the fact that it was exposed in the plublic sklearn.metrics.cluster namespace and had param validation suggests that it was unclear for us that it really was a private function. So I'd understand if others would rather go with a deprecation. Let's wait for more opinions.

Comment thread sklearn/metrics/cluster/__init__.py Resolved
@jeremiedbb

Copy link
Copy Markdown
Member

LGTM otherwise

@lucyleeow lucyleeow added the Needs Decision Requires decision label May 7, 2025
@ogrisel

ogrisel commented May 28, 2025 •

Copy link
Copy Markdown
Member

I think it does not cost us much to add a public stub that issues a deprecation warning for 2 releases and a TODO comment to remove it afterwards.

The deprecation message could make it clear that this undocumented function was never meant to be exposed as public API in the first place.

return float(-xp.sum((pi / pi_sum) * (xp.log(pi) - log(pi_sum))))


# TODO(1.10): Remove

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I am assuming this won't make it into 1.7, so deprecate 1.8 / remove 1.10 ?

Comment thread sklearn/metrics/cluster/_supervised.py Outdated
"`entropy` is deprecated in 1.8 and will become a private function only from 1.10."
)
def entropy(labels):
"""Public version of `_entropy`. To be deprecated."""

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I didn't add a full docstring because I don't think we ever created an API entry for it.

@lucyleeow

Copy link
Copy Markdown
Member Author

Thanks @ogrisel done!

@jeremiedbb jeremiedbb left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Okay to deprecate it the usual way. Just a couple of comments

Comment thread sklearn/metrics/cluster/_supervised.py Resolved
Comment thread sklearn/metrics/cluster/__init__.py Resolved

@jeremiedbb jeremiedbb left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM. I just copied the whole docstring into the public function to make the CI happy :)

@glemaitre glemaitre left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I just miss a changelog entry since it affect public API.

@lucyleeow

Copy link
Copy Markdown
Member Author

@glemaitre good point. Done.

@glemaitre glemaitre left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM. Thanks @lucyleeow

@glemaitre
glemaitre merged commit d4d4af8 into scikit-learn:main Jun 13, 2025
@lucyleeow
lucyleeow deleted the doc_entropy branch June 13, 2025 20:30
@jeremiedbb jeremiedbb mentioned this pull request Jul 15, 2025
13 tasks done
@jeremiedbb jeremiedbb mentioned this pull request Sep 3, 2025
13 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants