-
Notifications
You must be signed in to change notification settings - Fork 590
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
API: add .get() operation on a Map type #1376
Conversation
| input_type = [ | ||
| rules.map(dt.any, dt.any), | ||
| rules.one_of((dt.string, dt.int_), name='key'), | ||
| rules.value(name='default') |
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.
This really should be the concrete type of the values. Not sure if we can figure this out when we validate this. I think we could, but I don't think there's a rules API for dealing with this.
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.
this should just be dt.any, but .value doesn't like a type specified
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.
This is fine, but see my comment below about output_type.
ibis/expr/operations.py
Outdated
|
|
||
| def output_type(self): | ||
| map_type = self.args[0].type() | ||
| return rules.shape_like(self.args[0], map_type.value_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.
You should check that the type of default is null or equivalent to map value type.
|
@jreback Can you implement this on at least one backend and add a test? Otherwise, LGTM. |
|
we don't have any map operations implemented on any backends, they are simply abstract at this point. what were you thinking of? |
|
@jreback hm, i thought we had some on the pandas backend, guess I was mistaken. You can ignore my comment. This LGTM. merging shortly. |
|
Acutally, still have the comment about |
|
we could make the Map operations work on a Series actually. |
|
fixed up. I think my way of checking null (type) is idiomatic. |
ibis/expr/operations.py
Outdated
| def output_type(self): | ||
| map_type = self.args[0].type() | ||
| value_type = map_type.value_type | ||
| default_type = self.args[2].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.
you can do self.default.type() here which is a bit more readable.
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.
done
ibis/expr/operations.py
Outdated
| value_type = map_type.value_type | ||
| default_type = self.args[2].type() | ||
|
|
||
| if not (default_type is dt.null or |
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.
Shouldn't the default value for default be NULL
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.
good point
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.
pushed, I don't know how to make default optional though, rules.value doesn't like this
ibis/expr/operations.py
Outdated
| value_type = map_type.value_type | ||
| default_type = self.default.type() | ||
|
|
||
| if not (default_type is dt.null or |
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.
It's okay for this to be null since that would be the default return value if a key doesn't exist and default is not provided.
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.
Oh whoops, nevermind. This is correct.
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.
Null checking looks good here.
Small nit: can you write this as if default_type is not dt.null and value_type != default_type. It's a little easier to read IMO.
Then will merge.
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.
yep.
|
pushed |
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.
LGTM, merging on green
No description provided.