-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
added message when key_on not found in geojson #1144
added message when key_on not found in geojson #1144
Conversation
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.
Thanks @evwhiz for making this PR! I added some comments, hope you can have a look. Let us know if you have questions or if we can help.
folium/features.py
Outdated
@@ -1095,6 +1095,9 @@ def get_by_key(obj, key): | |||
|
|||
def color_scale_fun(x): | |||
key_of_x = get_by_key(x, key_on) | |||
if not key_of_x: | |||
if len(key_on) > 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.
In what case will key_on
be an empty string? And why don't we want to raise an error in that case? If key_on
is indeed an empty string it will still fail, so good to raise an error I would say.
folium/features.py
Outdated
@@ -1095,6 +1095,9 @@ def get_by_key(obj, key): | |||
|
|||
def color_scale_fun(x): | |||
key_of_x = get_by_key(x, key_on) | |||
if not key_of_x: | |||
if len(key_on) > 0: | |||
raise("key_on value not found in geojson") |
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 don't know if this is the right syntax. I would suggest to raise it with raise ValueError('my message')
. A value error, because the type of key_on
is right (it's a string), but its value is wrong.
folium/features.py
Outdated
@@ -1095,6 +1095,9 @@ def get_by_key(obj, key): | |||
|
|||
def color_scale_fun(x): | |||
key_of_x = get_by_key(x, key_on) | |||
if not key_of_x: | |||
if len(key_on) > 0: | |||
raise("key_on value not found in geojson") |
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.
Would be really helpful if we could include some information in the error message on what's wrong with the data. You could for example show the key_on
value in the error message. Something like 'wrong value: {}'.format(value)
.
b971b2f
to
495f2da
Compare
@Conengmo can you take a second look at 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 looks good! I'll merge it.
Thanks @evwhiz! Sorry it took me a while to get back to this. |
This address #918 and raises a TypeError "key_on value not found in geojson" when key_on is given, but not found in the geojson file.