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

Convert to float for comparison with float in IFDRational __eq__ #5412

Merged
merged 2 commits into from Jun 28, 2021

Conversation

radarhere
Copy link
Member

@radarhere radarhere commented Apr 17, 2021

This one is up for debate.

Consider this behaviour.

>>> 7 / 5
1.4
>>> from PIL.TiffImagePlugin import IFDRational
>>> IFDRational(7, 5) == 1.4
False

I feel like this is unexpected. Why is this happening? Well,

>>> IFDRational(7, 5)._val
Fraction(7, 5)
>>> from fractions import Fraction
>>> Fraction(7, 5) == 1.4
False

So despite the fact that

>>> float(Fraction(7, 5)) == 1.4
True

Fraction(7, 5) is not equal to 1.4.

This isn't the case for all values.

>>> Fraction(5, 4) == 1.25
True

This PR 'fixes' this behaviour in IFDRational by casting Fraction to float when comparing in IFDRational.__eq__().

As I said, open for debate.

@radarhere radarhere added the TIFF label Apr 17, 2021
@hugovk hugovk merged commit 9f28e4b into python-pillow:master Jun 28, 2021
@radarhere radarhere deleted the ifdrational_eq_float branch June 28, 2021 22:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants