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
Conversation
ibis/expr/tests/test_value_exprs.py
Outdated
|
||
def test_map_get_with_compatible_value_float(): | ||
t = ibis.literal({'A': 1000, 'B': 2000}) | ||
v = t.get('C', 3.0) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 of3.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.
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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)
?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
No description provided.