File tree 4 files changed +33
-8
lines changed
4 files changed +33
-8
lines changed Original file line number Diff line number Diff line change 20
20
21
21
- id : ruff-format
22
22
name : ruff-format
23
- entry : ruff format --force-exclude --check
23
+ entry : ruff format --force-exclude
24
24
language : system
25
25
stages : [commit]
26
26
types_or : [python, pyi, jupyter]
Original file line number Diff line number Diff line change 6
6
7
7
- Add netCDF to pystac.media_type ([ #1386 ] ( https://github.com/stac-utils/pystac/pull/1386 ) )
8
8
- 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 ) )
9
10
10
11
### Changed
11
12
Original file line number Diff line number Diff line change @@ -365,25 +365,25 @@ def to_dict(
365
365
d : dict [str , Any ] = {
366
366
"type" : "Feature" ,
367
367
"stac_version" : pystac .get_stac_version (),
368
+ "stac_extensions" : self .stac_extensions if self .stac_extensions else [],
368
369
"id" : self .id ,
369
- "properties" : self .properties ,
370
370
"geometry" : self .geometry ,
371
+ "bbox" : self .bbox if self .bbox is not None else [],
372
+ "properties" : self .properties ,
371
373
"links" : [link .to_dict (transform_href = transform_hrefs ) for link in links ],
372
374
"assets" : assets ,
373
375
}
374
376
375
- if self .bbox is not None :
376
- d ["bbox" ] = self .bbox
377
-
378
- if self .stac_extensions is not None :
379
- d ["stac_extensions" ] = self .stac_extensions
380
-
381
377
if self .collection_id :
382
378
d ["collection" ] = self .collection_id
383
379
384
380
for key in self .extra_fields :
385
381
d [key ] = self .extra_fields [key ]
386
382
383
+ # This field is prohibited if there's no geometry
384
+ if not self .geometry :
385
+ d .pop ("bbox" )
386
+
387
387
return d
388
388
389
389
def clone (self ) -> Item :
Original file line number Diff line number Diff line change @@ -108,6 +108,30 @@ def test_asset_absolute_href_no_item_self(self) -> None:
108
108
actual_href = rel_asset .get_absolute_href ()
109
109
self .assertEqual (None , actual_href )
110
110
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_dict = item .to_dict (include_self_link = False )
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
+ actual_order = list (item_dict .keys ())
129
+ self .assertEqual (
130
+ actual_order ,
131
+ expected_order ,
132
+ f"Order was { actual_order } , expected { expected_order } " ,
133
+ )
134
+
111
135
def test_extra_fields (self ) -> None :
112
136
item = pystac .Item .from_file (
113
137
TestCases .get_path ("data-files/item/sample-item.json" )
You can’t perform that action at this time.
0 commit comments