File tree Expand file tree Collapse file tree 4 files changed +43
-2
lines changed Expand file tree Collapse file tree 4 files changed +43
-2
lines changed Original file line number Diff line number Diff line change 2020
2121 - id : ruff-format
2222 name : ruff-format
23- entry : ruff format --force-exclude --check
23+ entry : ruff format --force-exclude
2424 language : system
2525 stages : [commit]
2626 types_or : [python, pyi, jupyter]
Original file line number Diff line number Diff line change 66
77- Add netCDF to pystac.media_type ([ #1386 ] ( https://github.com/stac-utils/pystac/pull/1386 ) )
88- Add convenience method for accessing pystac_client ([ #1365 ] ( https://github.com/stac-utils/pystac/pull/1365 ) )
9+ - Fix field ordering when saving ` Item ` s ([ #1423 ] ( https://github.com/stac-utils/pystac/pull/1423 ) )
910
1011### Changed
1112
Original file line number Diff line number Diff line change @@ -365,9 +365,11 @@ def to_dict(
365365 d : dict [str , Any ] = {
366366 "type" : "Feature" ,
367367 "stac_version" : pystac .get_stac_version (),
368+ "stac_extensions" : self .stac_extensions if self .stac_extensions else [],
368369 "id" : self .id ,
369- "properties" : self .properties ,
370370 "geometry" : self .geometry ,
371+ "bbox" : self .bbox if self .bbox is not None else [],
372+ "properties" : self .properties ,
371373 "links" : [link .to_dict (transform_href = transform_hrefs ) for link in links ],
372374 "assets" : assets ,
373375 }
@@ -384,6 +386,10 @@ def to_dict(
384386 for key in self .extra_fields :
385387 d [key ] = self .extra_fields [key ]
386388
389+ # This field is prohibited if there's no geometry
390+ if not self .geometry :
391+ d .pop ("bbox" )
392+
387393 return d
388394
389395 def clone (self ) -> Item :
Original file line number Diff line number Diff line change @@ -108,6 +108,40 @@ def test_asset_absolute_href_no_item_self(self) -> None:
108108 actual_href = rel_asset .get_absolute_href ()
109109 self .assertEqual (None , actual_href )
110110
111+ def test_item_field_order (self ) -> None :
112+ item = pystac .Item .from_file (
113+ TestCases .get_path ("data-files/item/sample-item.json" )
114+ )
115+ item .stac_extensions .append ("FakeExtension" )
116+
117+ expected_order = [
118+ "type" ,
119+ "stac_version" ,
120+ "stac_extensions" ,
121+ "id" ,
122+ "geometry" ,
123+ "bbox" ,
124+ "properties" ,
125+ "links" ,
126+ "assets" ,
127+ "collection" ,
128+ ]
129+
130+ with tempfile .TemporaryDirectory () as tmp_dir :
131+ p = os .path .join (tmp_dir , "item.json" )
132+ item .save_object (include_self_link = False , dest_href = p )
133+
134+ with open (p ) as f :
135+ item_json = json .load (f )
136+
137+ # Assert the order matches the expected order
138+ actual_order = list (item_json .keys ())
139+ self .assertEqual (
140+ actual_order ,
141+ expected_order ,
142+ f"Order was { actual_order } , expected { expected_order } " ,
143+ )
144+
111145 def test_extra_fields (self ) -> None :
112146 item = pystac .Item .from_file (
113147 TestCases .get_path ("data-files/item/sample-item.json" )
You can’t perform that action at this time.
0 commit comments