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
rewrite of validation mechanism #98
Conversation
Use obj.is_valid to get object validation status (Bool). Use obj.errors() to get an error or collection of errors during validation The return type depends on the object, but in any case, bool(obj.errors()) must evaluate to: True in case of error(s) False if no errors This implementation either checks for all subitems or raises NotImplementedError.
geojson/base.py
Outdated
def checkListErrors(self, checkFunc, lst): | ||
"""Validation helper function.""" | ||
# check for errors on each subitem, filter only subitems with errors | ||
results = [checkFunc(i) for i in lst] |
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 could benefit from being a generator:
results = (checkFunc(i) for i in lst)
geojson/base.py
Outdated
def is_valid(self): | ||
return not self.errors() | ||
|
||
def checkListErrors(self, checkFunc, lst): |
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.
Can we call this check_list_errors
? We're not very consistent right now, but it'd be great to have everything be snake case
CHANGELOG.rst
Outdated
@@ -1,6 +1,11 @@ | |||
Changes | |||
======= | |||
|
|||
1.4.0 (2017-07-28) |
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 is a breaking change, so we should bump to 2.0.0 🎊 🎉 2️⃣ .0️⃣
geojson/geometry.py
Outdated
|
||
|
||
class Polygon(Geometry): | ||
pass | ||
def checkPolygon(coord): |
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.
snake case
geojson/geometry.py
Outdated
class Polygon(Geometry): | ||
pass | ||
def checkPolygon(coord): | ||
lengths = all([len(elem) >= 4 for elem in coord]) |
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.
all([len(elem) >= 4 for elem in coord])
I have fixed the comments, except I did not understand last remark:
What needs to be changed here? |
woops, meant to write:
Also, do you happen to know if your changes fix #99 ? |
I have converted from list to generator. Regarding the issue #99, the validation now raises attribute error. Check this: import geojson
fc = geojson.loads("""{
"type": "FeatureCollection",
"features": [{}]
}
""")
print type(fc.features[0])
print fc.errors()
>>> <type 'dict'> I am not sure, but it might be better to fix #99 in the init, so that features list is a list of Feature instances. The validation would in this case turn False on the Feature instance and also on toplevel FeatureCollection object. |
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.
everything looks good to me here, thanks for the pr! before merging, you'll need to address some style/flake8 things:
https://travis-ci.org/frewsxcv/python-geojson/jobs/260921306
geojson/geometry.py
Outdated
if lengths is False: | ||
return 'LinearRing must contain with 4 or more positions' | ||
|
||
isring = all([elem[0] == elem[-1] for elem in coord]) |
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.
isring = all(elem[0] == elem[-1] for elem in coord)
Codecov Report
@@ Coverage Diff @@
## master #98 +/- ##
==========================================
- Coverage 81.23% 78.41% -2.82%
==========================================
Files 12 11 -1
Lines 325 315 -10
Branches 60 52 -8
==========================================
- Hits 264 247 -17
- Misses 51 58 +7
Partials 10 10
Continue to review full report at Codecov.
|
thanks! |
just published 2.0.0 |
This involved some breaking changes, especially during the validation. See jazzband/geojson#98 for details.
With geojson version 2.0.0 the function 'is_valid' was removed. * jazzband/geojson#98 * https://github.com/jazzband/python-geojson/blob/master/CHANGELOG.rst#200-2017-07-28
With geojson version 2.0.0 the function 'is_valid' was removed. * jazzband/geojson#98 * https://github.com/jazzband/python-geojson/blob/master/CHANGELOG.rst#200-2017-07-28
The geojson library removed the geojson.is_valid function with version 2.0.0. * https://github.com/jazzband/python-geojson/blob/master/CHANGELOG.rst#200-2017-07-28 * jazzband/geojson#98
There was a conceptual problem with validation function, since it assumes "valid" for all unknown instances. This in turn generates valid status for some otherwise false imputs (false positives). This implementation instead assumes "not implemented" unless "errors" method is implemented on all subitems.
This change introduces small incompatibility with previous version.
is_valid
function is removedobj.is_valid property
is introduced insteadobj.errors() method
is introduced to get error detailsTest cases and README file is changed to reflect the change.
I have only small set of geojson data available. I suggest to run validation tests on bigger dataset if you have it available.