Thanks to visit codestin.com
Credit goes to github.com

Skip to content

MNT Move entropy to private function #31294

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Jun 13, 2025
Merged

Conversation

lucyleeow
Copy link
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

Copy link

github-actions bot commented May 2, 2025

✔️ 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
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
Copy link
Member

@jeremiedbb jeremiedbb left a comment

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.

@jeremiedbb
Copy link
Member

LGTM otherwise

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

ogrisel commented May 28, 2025

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.

@@ -1312,3 +1307,12 @@ def entropy(labels):
# Always convert the result as a Python scalar (on CPU) instead of a device
# specific scalar array.
return float(-xp.sum((pi / pi_sum) * (xp.log(pi) - log(pi_sum))))


# TODO(1.10): Remove
Copy link
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 ?

"`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
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
Member Author

Thanks @ogrisel done!

Copy link
Member

@jeremiedbb jeremiedbb left a comment

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

Copy link
Member

@jeremiedbb jeremiedbb left a comment

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 :)

Copy link
Member

@glemaitre glemaitre left a comment

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
Member Author

@glemaitre good point. Done.

Copy link
Member

@glemaitre glemaitre left a comment

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
36 checks passed
@lucyleeow lucyleeow deleted the doc_entropy branch June 13, 2025 20:30
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