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

GeoJsonTooltip warn for GeometryCollection #988

Merged
merged 135 commits into from
Dec 9, 2018

Conversation

jtbaker
Copy link
Contributor

@jtbaker jtbaker commented Oct 14, 2018

Closes #929. Checks geometry types for GeometryCollections, stores the feature IDs of any in a list, and warns the user of incompatibility, and suggests refactoring to MultiPolygon geometry type.

jtbaker added 30 commits June 14, 2018 19:49
Added a new Tooltip class to reference GeoJson feature properties, with tests, documentation, and examples. It's flexible, and can take field names, aliases, that can be turned on/off with the 'labels' boolean, a 'sticky' property, and can incorporate Javascript's .toLocaleString() functionality if desired. The same string can be passed for each object with the 'text' variable as well if you'd rather not use the 'fields'.

Also updated the GeoJson JS template to reference this Tooltip object, and added a test to make sure that the values passed exist in the properties.
Further linting.
Seems like maybe the f-string usage in the geojson fields assertion check is causing the build failure. Testing normal string concatenation.
Reverted accidental vega_parse change.
Fixed docstring indentation.
Updating Tooltip docstring broke 120 char line limit.
Removed trailing white space.
Updating my fork to current Master.
…iLang.xml, ide.general.xml, Default.xml, project.default.xml, diff.xml, git.xml, other.xml, jdk.table.xml, Default.xml, code.style.schemes, find.xml, ui.lnf.xml, laf.xml, filetypes.xml, projectView.xml, vcs.xml, editor.codeinsight.xml, notifications.xml, keymap.xml, editor.xml, github_settings.xml, debugger.xml
…, IntelliLang.xml, ide.general.xml, Default.xml, project.default.xml, diff.xml, git.xml, other.xml, jdk.table.xml, Default.xml, code.style.schemes, find.xml, ui.lnf.xml, laf.xml, filetypes.xml, projectView.xml, vcs.xml, editor.codeinsight.xml, notifications.xml, keymap.xml, editor.xml, github_settings.xml, debugger.xml"

This reverts commit 76c9622.
onto separate lines so it is more readable.
@jtbaker
Copy link
Contributor Author

jtbaker commented Oct 15, 2018

Also a suggestion: what do you think about putting this in a separate method? I like to split of distinct functionality in separate methods when it makes sense. For example this could become def warn_for_geometry_collection() or something, with its own docstring explaining why we're doing this.

Ok, that sounds fine to me. To clarify, do you envision it as a validation function that lives in utilities.py to pass GeoJsonTooltip's self._parent.data through in the render method? Or as a class method only?

@Conengmo
Copy link
Member

I was thinking simply a class method. The code is only for GeoJsonTooltip, so moving it to some common place such as utilities is not needed.

warnings.warn(
"GeoJsonTooltip is not configured to render tooltips for GeoJson GeometryCollection geometries. "
"Please consider reworking feature IDs {} to MultiPolygon for full functionality.\n"
"https://tools.ietf.org/html/rfc7946#page-9""".format(geom_collections), UserWarning)
Copy link
Member

Choose a reason for hiding this comment

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

Note that there are still three "s here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Whoops! Fixed.

Fix last string quote from triple to single.
@Conengmo
Copy link
Member

There is one more thing I would like to do in this PR: add a test that verifies the warning is triggered when a geometry collection is used. That way we can be confident the validation function is right, also in the future. It's hard to see if a validation function is working properly without a test, because it's trigger might be rare.

Is that something you want to try @jtbaker? If not that's okay, I can pick it up or we'll leave it out.

@Conengmo Conengmo changed the title GeoJsonTooltip Update GeoJsonTooltip warn for GeometryCollection Oct 24, 2018
@Conengmo Conengmo added the waiting for changes This PR has been reviewed and changes are needed before merging label Oct 28, 2018
@@ -104,3 +106,14 @@ def test_color_line():
opacity=1)
m.add_child(color_line)
m._repr_html_()

def test_geojson_tooltip():

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


def test_geojson_tooltip():
m = folium.Map([30.5, -97.5], zoom_start=10)
geojson = folium.GeoJson("./kuntarajat.geojson",

Choose a reason for hiding this comment

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

F841 local variable 'geojson' is assigned to but never used

m = folium.Map([30.5, -97.5], zoom_start=10)
geojson = folium.GeoJson("./kuntarajat.geojson",
tooltip=folium.GeoJsonTooltip(
fields=['code','name']

Choose a reason for hiding this comment

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

E231 missing whitespace after ','

with warnings.catch_warnings(record=True) as w:
warnings.simplefilter('always')
m._repr_html_()
assert isinstance(w[-1].category, UserWarning), "GeoJsonTooltip GeometryCollection test failed."

Choose a reason for hiding this comment

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

W292 no newline at end of file

def test_geojson_tooltip():
m = folium.Map([30.5, -97.5], zoom_start=10)
folium.GeoJson("./kuntarajat.geojson",
tooltip=folium.GeoJsonTooltip(fields=['code','name'])

Choose a reason for hiding this comment

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

E127 continuation line over-indented for visual indent
E231 missing whitespace after ','

def test_geojson_tooltip():
m = folium.Map([30.5, -97.5], zoom_start=10)
folium.GeoJson("./kuntarajat.geojson",
tooltip=folium.GeoJsonTooltip(fields=['code','name'])

Choose a reason for hiding this comment

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

E231 missing whitespace after ','

@Conengmo
Copy link
Member

Looks good @jtbaker! This is what I had in mind. Unfortunately the test is not working yet in the Travis build. Here is the error:

> assert isinstance(w[-1].category, UserWarning), "GeoJsonTooltip GeometryCollection test failed."
E AssertionError: GeoJsonTooltip GeometryCollection test failed.
E assert False
E +  where False = isinstance(<class 'UserWarning'>, UserWarning)
E +    where <class 'UserWarning'> = <warnings.WarningMessage object at 0x7f328400d7f0>.category

It seems the isinstance test is not working as intended. Looking at the Pytest docs they give two methods for checking warnings:

The first is to use a with pytest.warns(UserWarning): context for the call that's expected to generate a warning.
https://docs.pytest.org/en/latest/warnings.html#warns

The second is to check recorded warnings, like you did. But in their example the don't use isinstance but issubclass: assert issubclass(w.category, UserWarning)
https://docs.pytest.org/en/latest/warnings.html#recwarn

Can you try any of these two methods to get the test working?

Copy link
Member

@Conengmo Conengmo left a comment

Choose a reason for hiding this comment

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

This looks good Jason! Unfortunately the test is currently failing due to an unrelated problem. I already made a fix and will open a PR with it. Should be quick to merge, after than we can update this PR and merge this.

@Conengmo Conengmo added blocked This issue/PR cannot be resolved untill something else is and removed waiting for changes This PR has been reviewed and changes are needed before merging labels Nov 25, 2018
@Conengmo Conengmo merged commit f4d024d into python-visualization:master Dec 9, 2018
@Conengmo Conengmo removed the blocked This issue/PR cannot be resolved untill something else is label Dec 9, 2018
@Conengmo
Copy link
Member

Conengmo commented Dec 9, 2018

Merged! Thanks Jason. Merging upstream master into your branch went well I see.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants