Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion csvkit/utilities/csvjson.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ def update_lon(self, lon):
self.max_lon = lon

def update_coordinates(self, coordinates):
if len(coordinates) <= 3 and isinstance(coordinates[0], (float, int)):
if coordinates and len(coordinates) <= 3 and isinstance(coordinates[0], (float, int)):
self.update_lon(coordinates[0])
self.update_lat(coordinates[1])
else:
Expand Down
3 changes: 3 additions & 0 deletions examples/test_geo_empty_coordinates.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
lat,lon,shape
,,"{""type"":""LineString"",""coordinates"":[]}"
,,"{""type"":""Point"",""coordinates"":[12,34]}"
7 changes: 7 additions & 0 deletions tests/test_utilities/test_csvjson.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,13 @@ def test_geojson_zero_coordinates(self):
self.assertEqual(geojson['features'][1]['geometry']['coordinates'], [0.0, 51.48])
self.assertEqual(geojson['features'][2]['geometry']['coordinates'], [2.35, 0.0])

def test_geojson_empty_coordinates(self):
geojson = json.loads(self.get_output([
'--lat', 'lat', '--lon', 'lon', '--geometry', 'shape', 'examples/test_geo_empty_coordinates.csv',
]))
self.assertEqual(geojson['features'][0]['geometry'], {'type': 'LineString', 'coordinates': []})
self.assertEqual(geojson['bbox'], [12, 34, 12, 34])

def test_geojson_shape(self):
geojson = json.loads(self.get_output(['--lat', 'latitude', '--lon', 'longitude',
'--type', 'type', '--geometry', 'geojson', 'examples/test_geojson.csv']))
Expand Down