Skip to content

Commit 47acd80

Browse files
Merge pull request #119 from bmschmidt/main
allow None bboxes
2 parents eb6c03a + 556795d commit 47acd80

File tree

4 files changed

+29
-4
lines changed

4 files changed

+29
-4
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/)
66
and this project adheres to [Semantic Versioning](http://semver.org/).
77

8+
## [NEXT] - TBD
9+
10+
### Fixed
11+
12+
* Fix issue with null bbox validation (author @bmschmidt, https://github.com/developmentseed/geojson-pydantic/pull/119)
13+
814
## [0.6.0] - 2023-05-09
915

1016
No change since 0.6.0a0

geojson_pydantic/features.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,24 @@ 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
35+
3336
if len(bbox) == 6:
3437
if bbox[0] > bbox[3] or bbox[1] > bbox[4] or bbox[2] > bbox[5]: # type: ignore
3538
raise ValueError(
3639
"BBox must be in the form [west, south, bottom, east, north, top]"
3740
)
41+
3842
elif len(bbox) == 4:
3943
if bbox[0] > bbox[2] or bbox[1] > bbox[3]:
4044
raise ValueError("BBox must be in the form [west, south, east, north]")
45+
4146
else:
4247
raise ValueError(
4348
"BBox must be in the form [west, south, east, north] or [west, south, bottom, east, north, top]"
4449
)
50+
4551
return bbox
4652

4753
@validator("geometry", pre=True, always=True)

geojson_pydantic/geometries.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ def __wkt_coordinates__(self, coordinates: Any, force_z: bool) -> str:
185185
@validator("coordinates")
186186
def check_closure(cls, coordinates: List) -> List:
187187
"""Validate that Polygon is closed (first and last coordinate are the same)."""
188-
if any([ring[-1] != ring[0] for ring in coordinates]):
188+
if any(ring[-1] != ring[0] for ring in coordinates):
189189
raise ValueError("All linear rings have the same start and end coordinates")
190190

191191
return coordinates
@@ -238,7 +238,7 @@ def has_z(self) -> bool:
238238
@validator("coordinates")
239239
def check_closure(cls, coordinates: List) -> List:
240240
"""Validate that Polygon is closed (first and last coordinate are the same)."""
241-
if any([ring[-1] != ring[0] for polygon in coordinates for ring in polygon]):
241+
if any(ring[-1] != ring[0] for polygon in coordinates for ring in polygon):
242242
raise ValueError("All linear rings have the same start and end coordinates")
243243

244244
return coordinates

tests/test_features.py

Lines changed: 15 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,22 @@ def test_feature_validation():
230231
# missing geometry
231232
Feature(type="Feature", properties=None)
232233

234+
assert Feature(
235+
type="Feature", properties=None, bbox=[0, 0, 100, 100], geometry=None
236+
)
237+
assert Feature(
238+
type="Feature", properties=None, bbox=[0, 0, 0, 100, 100, 100], geometry=None
239+
)
240+
233241
with pytest.raises(ValidationError):
234242
# bad bbox2d
235-
Feature(type="Feature", properties=None, bbox=[100, 100, 0, 0])
243+
Feature(type="Feature", properties=None, bbox=[100, 100, 0, 0], geometry=None)
236244

237245
with pytest.raises(ValidationError):
238246
# bad bbox3d
239-
Feature(type="Feature", properties=None, bbox=[100, 100, 100, 0, 0, 0])
247+
Feature(
248+
type="Feature",
249+
properties=None,
250+
bbox=[100, 100, 100, 0, 0, 0],
251+
geometry=None,
252+
)

0 commit comments

Comments
 (0)