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

Add value checking for location #625 #626

Merged
merged 7 commits into from Jun 27, 2017
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 14 additions & 2 deletions folium/map.py
Expand Up @@ -60,6 +60,19 @@
'https://rawgit.com/python-visualization/folium/master/folium/templates/leaflet.awesome.rotate.css'), # noqa
]

def _format_lat_lon(values):

Choose a reason for hiding this comment

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

E302 expected 2 blank lines, found 1

Copy link
Member

Choose a reason for hiding this comment

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

How about naming it _validate_location?

"""Validates and formats location values before setting"""
if type(values) not in [list, tuple]:
raise TypeError("Location is not a list, expecting ex: location=[45.523, -122.675]")

if len(values) != 2:
raise ValueError("Location should have two values, [lat, lon]")

try:
values = [float(val) for val in values]
except:
raise ValueError("Location values should be numeric, {} is not a number".format(val))
Copy link
Member

Choose a reason for hiding this comment

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

👍

return value

Choose a reason for hiding this comment

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

F821 undefined name 'value'


class LegacyMap(MacroElement):
"""Create a Map with Folium and Leaflet.js
Expand Down Expand Up @@ -170,7 +183,7 @@ def __init__(self, location=None, width='100%', height='100%',
self.location = [0, 0]
self.zoom_start = min_zoom
else:
self.location = location
self.location = _format_lat_lon(location)

Choose a reason for hiding this comment

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

F821 undefined name '_format_lat_lon'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just as I pushed this I realized this mistake... sigh

self.zoom_start = zoom_start

Figure().add_child(self)
Expand Down Expand Up @@ -337,7 +350,6 @@ def render(self, **kwargs):

super(LegacyMap, self).render(**kwargs)


class GlobalSwitches(Element):
def __init__(self, prefer_canvas=False, no_touch=False, disable_3d=False):
super(GlobalSwitches, self).__init__()
Expand Down