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
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2746,6 +2746,27 @@ def output_type(self): | |
return rules.shape_like(self.args[0], map_type.value_type) | ||
|
||
|
||
class MapValueOrDefaultForKey(ValueOp): | ||
|
||
input_type = [ | ||
rules.map(dt.any, dt.any), | ||
rules.one_of((dt.string, dt.int_), name='key'), | ||
rules.value(name='default') | ||
] | ||
|
||
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 commentThe reason will be displayed to describe this comment to others. Learn more. you can do There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
|
||
if not (default_type is dt.null or | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't the default value for There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. pushed, I don't know how to make default optional though, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's okay for this to be There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Null checking looks good here. Small nit: can you write this as Then will merge. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yep. |
||
value_type.equals(default_type)): | ||
raise ValueError("default type: {} must be the same " | ||
"as the map value_type {}".format( | ||
default_type, value_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 commentThe reason will be displayed to describe this comment to others. Learn more. You should check that the type of |
||
|
||
|
||
class MapKeys(ValueOp): | ||
|
||
input_type = [rules.map(dt.any, dt.any)] | ||
|
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 specifiedThere 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
.