File tree Expand file tree Collapse file tree 4 files changed +42
-2
lines changed Expand file tree Collapse file tree 4 files changed +42
-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,39 @@ 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+
116+ expected_order = [
117+ "type" ,
118+ "stac_version" ,
119+ "stac_extensions" ,
120+ "id" ,
121+ "geometry" ,
122+ "bbox" ,
123+ "properties" ,
124+ "links" ,
125+ "assets" ,
126+ "collection" ,
127+ ]
128+
129+ with tempfile .TemporaryDirectory () as tmp_dir :
130+ p = os .path .join (tmp_dir , "item.json" )
131+ item .save_object (include_self_link = False , dest_href = p )
132+
133+ with open (p ) as f :
134+ item_json = json .load (f )
135+
136+ # Assert the order matches the expected order
137+ actual_order = list (item_json .keys ())
138+ self .assertEqual (
139+ actual_order ,
140+ expected_order ,
141+ f"Order was { actual_order } , expected { expected_order } " ,
142+ )
143+
111144 def test_extra_fields (self ) -> None :
112145 item = pystac .Item .from_file (
113146 TestCases .get_path ("data-files/item/sample-item.json" )
You can’t perform that action at this time.
0 commit comments