Skip to content

Commit ea6319d

Browse files
committed
allow None bboxes
1 parent eb6c03a commit ea6319d

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

geojson_pydantic/features.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ class Config:
3030
@validator("bbox", pre=True)
3131
def check_bbox(cls, bbox: BBox) -> BBox:
3232
"""Check that bbox is valid."""
33+
if bbox is None:
34+
return bbox
3335
if len(bbox) == 6:
3436
if bbox[0] > bbox[3] or bbox[1] > bbox[4] or bbox[2] > bbox[5]: # type: ignore
3537
raise ValueError(

tests/test_features.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ def test_bad_feature_id(id):
213213
def test_feature_validation():
214214
"""Test default."""
215215
assert Feature(type="Feature", properties=None, geometry=None)
216+
assert Feature(type="Feature", properties=None, geometry=None, bbox=None)
216217

217218
with pytest.raises(ValidationError):
218219
# should be type=Feature
@@ -230,10 +231,12 @@ def test_feature_validation():
230231
# missing geometry
231232
Feature(type="Feature", properties=None)
232233

234+
assert Feature(type="Feature", properties=None, bbox=[0, 0, 100, 100], geometry=None)
235+
233236
with pytest.raises(ValidationError):
234237
# bad bbox2d
235-
Feature(type="Feature", properties=None, bbox=[100, 100, 0, 0])
238+
Feature(type="Feature", properties=None, bbox=[100, 100, 0, 0], geometry=None)
236239

237240
with pytest.raises(ValidationError):
238241
# bad bbox3d
239-
Feature(type="Feature", properties=None, bbox=[100, 100, 100, 0, 0, 0])
242+
Feature(type="Feature", properties=None, bbox=[100, 100, 100, 0, 0, 0], geometry=None)

0 commit comments

Comments
 (0)