Skip to content

FIX Pop unnecessary elements from metric_kwargs in datasets_pair.pyx.tp #26987

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 2 commits into from
Aug 2, 2023

Conversation

Micky774
Copy link
Contributor

@Micky774 Micky774 commented Aug 1, 2023

Reference Issues/PRs

This change was first made in #25561 by @jjerphan and @Vincent-Maladiere

What does this implement/fix? Explain your changes.

X_norm_squared and Y_norm_squared might be propagated down to DatasetsPairs via metrics_kwargs when the Euclidean specialisations can't be used. To prevent X_norm_squared and Y_norm_squared to be passed down to DistanceMetrics (whose constructors would raise a RuntimeError), we pop them here.

Any other comments?

I factored this out separately so as to simplify the new PR (#26983)

@github-actions
Copy link

github-actions bot commented Aug 1, 2023

✔️ Linting Passed

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

Generated for commit: 19d270c. Link to the linter CI: here

@Micky774
Copy link
Contributor Author

Micky774 commented Aug 2, 2023

Ping @jjerphan @OmarManzoor in case either of you are interested in reviewing

Copy link
Member

@jjerphan jjerphan left a comment

Choose a reason for hiding this comment

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

Thanks

if metric_kwargs is not None:
# Copying metric_kwargs not to pop "X_norm_squared"
# and "Y_norm_squared" where they are used
metric_kwargs = copy.copy(metric_kwargs)
Copy link
Member

Choose a reason for hiding this comment

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

quick question: does metric_kwargs can have nested objects such that calling deepcopy instead of copy could be better?

Copy link
Member

Choose a reason for hiding this comment

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

Here, we do not want to copy the objects themselves, (which is what deepcopy does), and only want to copy their reference in another dictionary (which is what copy does).

What do you think? Is this right?

Probably we could include a comment to explain the function that is used.

Copy link
Member

Choose a reason for hiding this comment

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

OK right, metric_kwargs will only be used "read-only", that makes sense.

@glemaitre glemaitre merged commit b06a7d2 into scikit-learn:main Aug 2, 2023
@Micky774 Micky774 deleted the datasets_pair_pop branch August 2, 2023 12:02
9Y5 pushed a commit to 9Y5/scikit-learn that referenced this pull request Aug 2, 2023
REDVM pushed a commit to REDVM/scikit-learn that referenced this pull request Nov 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cython module:metrics Quick Review For PRs that are quick to review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants