Skip to content

Commit

Permalink
Remove empty geometries in Source
Browse files Browse the repository at this point in the history
  • Loading branch information
Jesus89 committed Apr 3, 2020
1 parent 76425cd commit 5f4a6de
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
7 changes: 2 additions & 5 deletions cartoframes/viz/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,8 @@ def __init__(self, source, credentials=None, geom_col=None, encode_data=True):
raise ValueError('No valid geometry found. Please provide an input source with ' +
'a valid geometry or specify the "geom_col" param with a geometry column.')

# Checking empty geometries
has_empty_geoms = self.gdf.geometry.is_empty.any()
if has_empty_geoms:
raise ValueError('Empty geometries found. Please remove the empty geometries first: ' +
'gdf = gdf[~gdf.geometry.is_empty]')
# Remove empty geometries
self.gdf = self.gdf[~self.gdf.geometry.is_empty]

# Checking the uniqueness of the geometry type
geometry_types = set(self.gdf.geom_type.unique())
Expand Down
10 changes: 3 additions & 7 deletions tests/unit/viz/test_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ def test_dates_in_source(self):
gdf = gpd.GeoDataFrame(df, geometry=gpd.points_from_xy(df.lon, df.lat))

assert df.dtypes['date_column'] == np.dtype('datetime64[ns]')

source = Source(gdf)

assert source.datetime_column_names == ['date_column']
Expand Down Expand Up @@ -184,12 +183,9 @@ def test_different_geometry_types_source_fail(self, features):
def test_empty_geometries(self):
geojson = {
"type": "FeatureCollection",
"features": [POINT, EMPTY]
"features": [EMPTY, POINT, EMPTY, EMPTY, POINT, EMPTY]
}
gdf = gpd.GeoDataFrame.from_features(geojson)
source = Source(gdf)

with pytest.raises(ValueError) as e:
Source(gdf)

assert str(e.value).startswith(
'Empty geometries found. Please remove the empty geometries first')
assert len(source.gdf) == 2

0 comments on commit 5f4a6de

Please sign in to comment.