-
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
Explicit coordinate validation #1090
Explicit coordinate validation #1090
Conversation
9154e00
to
c961218
Compare
c961218
to
20fb4b1
Compare
a913a7d
to
f579392
Compare
from six.moves.urllib.parse import urlparse, uses_netloc, uses_params, uses_relative | ||
|
||
|
||
_VALID_URLS = set(uses_relative + uses_netloc + uses_params) | ||
_VALID_URLS.discard('') | ||
|
||
|
||
def _is_sized_iterable(arg): | ||
"""Validates the arg is Sized & Iterable""" | ||
return isinstance(arg, abc.Sized) & isinstance(arg, abc.Iterable) |
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.
Don't you think this was simpler with the abc
? I'm fine with this approach but I could not see why the change at a first pass.
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.
Hmm I tried to change it into abc.Sequence, because it should also have __getitem__
, but then it won't work for Numpy arrays. So my problem is that there may be other classes that don't inherit from abc types but have those methods implemented? I guess I prefer the try/except version because it's more intuitive and handles duck types better than abc.
f579392
to
2d31eeb
Compare
2d31eeb
to
64c9712
Compare
64c9712
to
635eb49
Compare
4711e3b
to
20b49ed
Compare
20b49ed
to
de6ea0a
Compare
Rewrite the validation functions in utilities that check single and multiple coordinate pairs. Make them more strict and raise meaningful exceptions. Apply the validation functions throughout the code base wherever possible. For the Marker class and vector classes a new BaseMarker class is added to make the distinction between single and multiple locations explicit. For the HeatMap and FastMarkerCluster classes I made custom validation in the classes themselves. Their use cases are different, so they cannot use the standard validation functions.
de6ea0a
to
05ca372
Compare
It contained an outdated use of the `MarkerCluster` class.
Hi @ocefpaf, I think this is pretty much ready. Could you check it out if you have a moment? |
Awesome changes @Conengmo! Thanks for fixing this!! |
Thanks for the review! |
Problem
We have multiple conversion/validation functions in utilities. It's hard to decide which to use, and they are not thorough.
Solution
Have a few validation/conversion functions that are clear and explicit. They raise meaningful errors. They have extensive tests.
So that's what I tried in this PR. I put some things together into two functions: one for single coordinate pairs and one for lists (of lists) of coordinate pairs. Both try to raise meaningful exceptions and convert to a single common format.
I applied the validation functions throughout the code base when possible. In some cases (
HeatMap
,FastMarkerCluster
) I made custom ones because they have special data formats.For the Marker class and vector classes I added a new BaseMarker class to make the distinction between single and multiple locations explicit. Before the vector classes just passed a list of coordinate pairs to
Marker
, whileMarker
is documented to only accept a single coordinate pair.Possible improvements:
@ocefpaf @jtbaker want to review this one?
Closes #1089