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

BUG: Fix equality behavior for Literal ops #2387

Merged
merged 3 commits into from
Sep 17, 2020

Conversation

icexelloss
Copy link
Contributor

@icexelloss icexelloss commented Sep 16, 2020

The Problem

Currently the equality method for Literal is ill defined, e.g.:

>>> a = Literal(1, datatypes.int16)
>>> b = Literal(1, datatypes.int32)
>>> a != b
False
>>> a == b
True
>>> hash(a)
1536673607048974696
>>> hash(b)
-4587729510117789678

This IMO is bad behavior because it breaks the contract of equal and hashcode (if a == b, then hash(a) must == hash(b)).

What's even worse:

>>> a = ibis.interval(hours=1).op()
>>> b = ibis.interval(seconds=1).op()
>>> a == b
True

Here a and b are totally different objects.

The Fix

The PR proposes a fix where we also checks the dtype equality in literal equality check.

This fix deals with the two problems above. However, it does change some existing behavior:

Before the PR:

a = Literal(1, datatypes.int16)                                                                                                                                                                       
b = Literal(1, datatypes.int32)

a == b # True

After the PR:

a = Literal(1, datatypes.int16)                                                                                                                                                                       
b = Literal(1, datatypes.int32)

a == b # False

I'd like to be more careful with this and hear what other people think. I think after PR behavior is more correct but might break people's code if they are relying the correct behavior. Thoughts?

@jreback jreback added the expressions Issues or PRs related to the expression API label Sep 16, 2020
@icexelloss
Copy link
Contributor Author

Related to #2386

@jreback
Copy link
Contributor

jreback commented Sep 16, 2020

hmm, this doesn't break anything. interesting. ok let's add a whatsnew note and merge it.

@jreback jreback added this to the Next Bugfix Release milestone Sep 16, 2020
@icexelloss
Copy link
Contributor Author

Thanks! Updated release notes.

@icexelloss icexelloss changed the title [BUG] Fix equality for Literal ops BUG: Fix equality for Literal ops Sep 17, 2020
@icexelloss icexelloss changed the title BUG: Fix equality for Literal ops BUG: Fix equality behavior for Literal ops Sep 17, 2020
@jreback jreback merged commit 257a2b0 into ibis-project:master Sep 17, 2020
@jreback
Copy link
Contributor

jreback commented Sep 17, 2020

thanks @icexelloss

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
expressions Issues or PRs related to the expression API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants