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

API: add .get() operation on a Map type #1376

Closed
wants to merge 5 commits into from

Conversation

jreback
Copy link
Contributor

@jreback jreback commented Mar 5, 2018

No description provided.

@jreback jreback added the feature Features or general enhancements label Mar 5, 2018
@jreback jreback added this to the 0.13 milestone Mar 5, 2018
input_type = [
rules.map(dt.any, dt.any),
rules.one_of((dt.string, dt.int_), name='key'),
rules.value(name='default')
Copy link
Member

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.

Copy link
Contributor Author

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

Copy link
Member

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.


def output_type(self):
map_type = self.args[0].type()
return rules.shape_like(self.args[0], map_type.value_type)
Copy link
Member

@cpcloud cpcloud Mar 7, 2018

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.

@cpcloud
Copy link
Member

cpcloud commented Mar 7, 2018

@jreback Can you implement this on at least one backend and add a test? Otherwise, LGTM.

@jreback
Copy link
Contributor Author

jreback commented Mar 7, 2018

we don't have any map operations implemented on any backends, they are simply abstract at this point. what were you thinking of?

@cpcloud
Copy link
Member

cpcloud commented Mar 7, 2018

@jreback hm, i thought we had some on the pandas backend, guess I was mistaken. You can ignore my comment. This LGTM. merging shortly.

@cpcloud
Copy link
Member

cpcloud commented Mar 7, 2018

Acutally, still have the comment about output_type. Will merge after that is addressed.

@jreback
Copy link
Contributor Author

jreback commented Mar 7, 2018

we could make the Map operations work on a Series actually.

@jreback
Copy link
Contributor Author

jreback commented Mar 7, 2018

fixed up. I think my way of checking null (type) is idiomatic.

def output_type(self):
map_type = self.args[0].type()
value_type = map_type.value_type
default_type = self.args[2].type()
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

value_type = map_type.value_type
default_type = self.args[2].type()

if not (default_type is dt.null or
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good point

Copy link
Contributor Author

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

value_type = map_type.value_type
default_type = self.default.type()

if not (default_type is dt.null or
Copy link
Member

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.

Copy link
Member

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.

Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yep.

@jreback
Copy link
Contributor Author

jreback commented Mar 7, 2018

pushed

Copy link
Member

@cpcloud cpcloud left a 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

@cpcloud cpcloud closed this in 1127162 Mar 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Features or general enhancements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants