Skip to content

Commit 3d63ab1

Browse files
committed
allow Feature **id** to be either a String or a Number
1 parent 1ff7b66 commit 3d63ab1

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ 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+
## [unreleased]
9+
10+
- allow Feature's **id** to be either a String or a Number
11+
812
## [0.5.0] - 2022-12-16
913

1014
### Added

geojson_pydantic/features.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@ class Feature(GenericModel, Generic[Geom, Props]):
1818
type: str = Field(default="Feature", const=True)
1919
geometry: Optional[Geom] = None
2020
properties: Optional[Props] = None
21-
id: Optional[str] = None
21+
id: Optional[Union[int, str]] = None
2222
bbox: Optional[BBox] = None
2323

2424
class Config:
2525
"""Model configuration."""
2626

27+
smart_union = True
2728
use_enum_values = True
2829

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

tests/test_features.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,3 +182,14 @@ def test_feature_collection_geo_interface_with_null_geometry():
182182
assert "bbox" not in fc.__geo_interface__
183183
assert "bbox" not in fc.__geo_interface__["features"][0]
184184
assert "bbox" in fc.__geo_interface__["features"][1]
185+
186+
187+
def test_feature_id():
188+
feature = Feature(**test_feature, id="A")
189+
assert feature.id == "A"
190+
191+
feature = Feature(**test_feature, id=1)
192+
assert feature.id == 1
193+
194+
feature = Feature(**test_feature, id="1")
195+
assert feature.id == "1"

0 commit comments

Comments
 (0)