Skip to content

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
@radarhere radarhere force-pushed the ifdrational_eq_float branch from 7655175 to 7bfaffd Compare May 9, 2021 23:38
@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.

3 participants