Skip to content
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

Raise ValueError if kmeans is negative #7891

Merged
merged 2 commits into from Mar 22, 2024
Merged

Conversation

radarhere
Copy link
Member

#7890 (comment) found that if kmeans if negative, im.quantize() can become stuck in an infinite loop.

Investigating, I was able to reproduce this for MEDIANCUT and MAXCOVERAGE.

This PR updates the docstring to specify that kmeans should not be negative, raises a ValueError if kmeans is negative, and to be safe, also updates the C code to not use negative kmeans either.

@hugovk
Copy link
Member

hugovk commented Mar 22, 2024

Thanks, shall we add a test that successfully calls quantize with kmeans=0, and kmeans=1 or some other positive integer?

Copy link
Member

@hugovk hugovk left a comment

Choose a reason for hiding this comment

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

Thank you!

@hugovk hugovk added the automerge Automatically merge PRs that are ready label Mar 22, 2024
@mergify mergify bot merged commit 759630f into python-pillow:main Mar 22, 2024
57 checks passed
@radarhere radarhere deleted the kmeans branch March 22, 2024 22:12
radarhere added a commit to radarhere/Pillow that referenced this pull request Mar 24, 2024
hugovk added a commit that referenced this pull request Mar 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge Automatically merge PRs that are ready
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants