-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Added ability to use remote geo_path #602
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
Conversation
folium/folium.py
Outdated
@@ -251,7 +252,10 @@ def choropleth(self, geo_path=None, geo_str=None, data_out='data.json', | |||
|
|||
# Create GeoJson object | |||
if geo_path: | |||
geo_data = open(geo_path) | |||
if geo_path.lower().startswith(('http','ftp','https')): |
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.
E231 missing whitespace after ','
W291 trailing whitespace
folium/folium.py
Outdated
geo_data = open(geo_path) | ||
if geo_path.lower().startswith(('http','ftp','https')): | ||
geo_data = requests.get(geo_path).json() | ||
else: |
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.
W291 trailing whitespace
folium/folium.py
Outdated
@@ -251,7 +252,10 @@ def choropleth(self, geo_path=None, geo_str=None, data_out='data.json', | |||
|
|||
# Create GeoJson object | |||
if geo_path: | |||
geo_data = open(geo_path) | |||
if geo_path.lower().startswith(('http', 'ftp', 'https')): |
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.
Probably should include the colon, too; someone could have a file that starts with any of these sequences.
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.
Maybe it is an overkill but how about something like:
def scheme_validator(url):
parsed = urlparse(url)
if parsed.scheme in ['http', 'ftp', 'https']:
return True
return False
to validade the scheme?
I am fine with the extra dependency. We could use a
The PR is fine. You can add a simple test that just tries to use this. See https://github.com/python-visualization/folium/blob/master/tests/test_folium.py#L282 for an example (but yours will probably be much simpler than that.) Please add:
and this should be good to go. |
Cool, I will try to get the test written in the next few days. I will modify the Will modify docs and reqs accordingly. |
…swith on URL checking.
folium/folium.py
Outdated
@@ -251,7 +252,10 @@ def choropleth(self, geo_path=None, geo_str=None, data_out='data.json', | |||
|
|||
# Create GeoJson object | |||
if geo_path: | |||
geo_data = open(geo_path) | |||
if geo_path.lower().startswith(('http:', 'ftp':, 'https:')): |
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.
E231 missing whitespace after ':'
E999 SyntaxError: invalid syntax
tests/test_folium.py
Outdated
@@ -21,6 +21,8 @@ | |||
from six import PY3 | |||
import branca.element | |||
|
|||
import requests |
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.
F401 'requests' imported but unused
tests/test_folium.py
Outdated
self.map = folium.Map(zoom_start=4) | ||
|
||
# Adding remote GeoJSON as additional layer. | ||
path = 'https://raw.githubusercontent.com/python-visualization/folium/master/examples/data/us-states.json' |
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.
E501 line too long (114 > 100 characters)
tests/test_folium.py
Outdated
@@ -27,6 +27,11 @@ | |||
|
|||
rootpath = os.path.abspath(os.path.dirname(__file__)) | |||
|
|||
# For testing remote requests | |||
remote_url = '/'.join([ | |||
'https://raw.githubusercontent.com', |
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.
E101 indentation contains mixed spaces and tabs
W191 indentation contains tabs
tests/test_folium.py
Outdated
# For testing remote requests | ||
remote_url = '/'.join([ | ||
'https://raw.githubusercontent.com', | ||
'python-visualization/folium/master', |
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.
W191 indentation contains tabs
tests/test_folium.py
Outdated
remote_url = '/'.join([ | ||
'https://raw.githubusercontent.com', | ||
'python-visualization/folium/master', | ||
'examples/data/us-states.json']) |
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.
W191 indentation contains tabs
Right, think I've managed to tidy everything up -- that stickler really is a stickler (but I can appreciate that). Have added a simple test that tries to remotely access one of the example JSON files packaged with Folium from GitHub and checks that the map extent matches its expectations. |
Please do check that edits to CHANGES.txt and such are appropriate and reasonable. |
CHANGES.txt
Outdated
@@ -13,6 +13,7 @@ | |||
- Added `smooth_factor `option to `GeoJSON`, `TopoJSON` and `Choropleth` (JamesGardiner #428) | |||
- `Map` object now accepts Leaflet global switches (sgvandijk #424) | |||
- Added weight option to CircleMarker (palewire #581) | |||
- Added requests support to enable http(s) and ftp for geo_path parameter |
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.
If you want feel free to add you github handle and the PR number here too.
remote_url = '/'.join([ | ||
'https://raw.githubusercontent.com', | ||
'python-visualization/folium/master', | ||
'examples/data/us-states.json']) |
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 one 👍
Thanks! Looks good to go.
And it saves the devs time while reviewing PRs 😉
That is perfect. Let's wait on Travis-CI and merge this. |
Cool — I’ve added my info to the CHANGES.txt file so I think we’re good to go.
Thank you all for the support/tips on getting this through to merged. It’s not something I’ve done before with Travis and all these other tools so it could have been… hairy.
jon
… On 9 Mar 2017, at 14:46, Filipe ***@***.***> wrote:
Right, think I've managed to tidy everything up
Thanks! Looks good to go.
that stickler really is a stickler (but I can appreciate that).
And it saves the devs time while reviewing PRs 😉
Have added a simple test that tries to remotely access one of the example JSON files packaged with Folium from GitHub and checks that the map extent matches its expectations.
That is perfect. Let's wait on Travis-CI and merge this.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub <#602 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/ADEzZe7o9GCCR3m0CQKPI2NVSu4gYy6tks5rkBDCgaJpZM4MUsut>.
--
Jon Reades
m: 07976.987.392
e: [email protected] <mailto:[email protected]>
im: jereades
|
Thanks for the awesome contribution @jreades! |
Added ability to use remote geo_path
Adds a dependency (requests) but enables ability to use http/https/ftp for loading geo_paths.
I'm really rusty on unit tests (last did them in Java 1.2 or thereabouts) so I've not attempted to implement these. This is the first time I've done this, so please review carefully before accepting the PR.