From a55cf7db228c04c0f317b619efd7457dcd52d399 Mon Sep 17 00:00:00 2001 From: Andrew <15331990+ahuang11@users.noreply.github.com> Date: Tue, 9 Jul 2024 15:59:07 -0700 Subject: [PATCH 1/2] Fix geopandas type check If geometry is None, it crashes: ```python import hvplot.pandas import censusdis.data as ced from censusdis.datasets import ACS5 from censusdis.counties.washington import KING from censusdis.states import WA GROUP = "B25008" gdf_king = ced.download( ACS5, 2020, # Instead of listing the variables, we can ask for a whole group. group=GROUP, state=WA, county=KING, tract="*", with_geometry=True, # An optional flag that produces better maps in coastal areas. # More on this in the next lesson. remove_water=True, ) gdf_king ``` --- hvplot/converter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hvplot/converter.py b/hvplot/converter.py index eebd60137..0864ab3b3 100644 --- a/hvplot/converter.py +++ b/hvplot/converter.py @@ -1011,7 +1011,7 @@ def _process_data( self.data = data if kind is None: if datatype == 'geopandas': - geom_types = {gt[5:] if 'Multi' in gt else gt for gt in data.geom_type} + geom_types = {gt[5:] if gt and 'Multi' in gt else gt for gt in data.geom_type} else: geom_types = [ type(data.geometry.dtype) From 79a13dd10a06057c6dce4e10524f402e4991e7e8 Mon Sep 17 00:00:00 2001 From: Andrew Huang Date: Thu, 11 Jul 2024 09:13:32 -0700 Subject: [PATCH 2/2] add test and pop none --- hvplot/converter.py | 2 ++ hvplot/tests/testgeo.py | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/hvplot/converter.py b/hvplot/converter.py index 0864ab3b3..570ff39e7 100644 --- a/hvplot/converter.py +++ b/hvplot/converter.py @@ -1012,6 +1012,8 @@ def _process_data( if kind is None: if datatype == 'geopandas': geom_types = {gt[5:] if gt and 'Multi' in gt else gt for gt in data.geom_type} + if None in geom_types: + geom_types.remove(None) else: geom_types = [ type(data.geometry.dtype) diff --git a/hvplot/tests/testgeo.py b/hvplot/tests/testgeo.py index f79607fb6..0ed617fa1 100644 --- a/hvplot/tests/testgeo.py +++ b/hvplot/tests/testgeo.py @@ -438,6 +438,11 @@ def test_polygons_turns_off_hover_when_there_are_no_fields_to_include(self): opts = hv.Store.lookup_options('bokeh', polygons, 'plot').kwargs assert 'hover' not in opts.get('tools') + def test_geometry_none(self): + polygons = self.polygons.copy() + polygons.geometry[1] = None + assert polygons.hvplot(geo=True) + class TestGeoUtil(TestCase): def setUp(self):