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 map get with compatible types #1643

Closed
wants to merge 7 commits into from

Conversation

cpcloud
Copy link
Member

@cpcloud cpcloud commented Oct 1, 2018

No description provided.

@cpcloud cpcloud added this to the Next Release milestone Oct 1, 2018
@cpcloud cpcloud requested a review from kszucs October 1, 2018 22:35
@cpcloud cpcloud added the expressions Issues or PRs related to the expression API label Oct 1, 2018

def test_map_get_with_compatible_value_float():
t = ibis.literal({'A': 1000, 'B': 2000})
v = t.get('C', 3.0)
Copy link
Member Author

Choose a reason for hiding this comment

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

Hm, so this doesn't seem correct to me actually. Computing the precedence is too generic. We only want to be able to upcast within the same numeric kind not across types. non numeric types must be exactly equal.

Copy link
Member

Choose a reason for hiding this comment

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

IMHO We should be strict in this case, I'd expect

  • t.get('C', 3.0) -> int(3) instead of 3.0
  • t.get('C', '3') -> int(3) instead of '3'

So default_type must be castable to value_type rather than using highest_precedence because it allows upcasting to both direction.

Copy link
Member

Choose a reason for hiding this comment

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

See my comment below.

# otherwise the result type is the value type since the user
# did not provide a default value
result_type = value_type
return rlz.shape_like(tuple(self.args), result_type)
Copy link
Member

Choose a reason for hiding this comment

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

How about

dtype = self.arg.type()

if not self.default.type().castable(dtype):
    raise IbisTypeError(...)

return rlz.shape_like(self.args, dtype)

?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think castable may still be too generic. I don't think that providing a float as the default for get on a map with integer value type should work. We may need some kind of map_get_compatible that is similar to castable, or maybe a strict_castable that is equivalent to castable but specializes on numeric types.

Copy link
Member

Choose a reason for hiding this comment

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

We can introduce another flag into the overloaded castable functions

Copy link
Member Author

@cpcloud cpcloud Oct 20, 2018

Choose a reason for hiding this comment

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

Actually, it looks like castable does exactly what I want.

@cpcloud cpcloud closed this in ec13ef6 Oct 28, 2018
@cpcloud cpcloud deleted the map-get-bug branch October 28, 2018 14:21
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.

None yet

2 participants