Skip to content

Commit

Permalink
add keywords to common metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
tylanderson committed Oct 15, 2024
1 parent ba406cb commit be7bccb
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- Add netCDF to pystac.media_type ([#1386](https://github.com/stac-utils/pystac/pull/1386))
- Add convenience method for accessing pystac_client ([#1365](https://github.com/stac-utils/pystac/pull/1365))
- Fix field ordering when saving `Item`s ([#1423](https://github.com/stac-utils/pystac/pull/1423))
- Add keywords to common metadata

### Changed

Expand Down
9 changes: 9 additions & 0 deletions pystac/common_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,3 +213,12 @@ def updated(self) -> datetime | None:
@updated.setter
def updated(self, v: datetime | None) -> None:
self._set_field("updated", utils.map_opt(utils.datetime_to_str, v))

@property
def keywords(self) -> list[str] | None:
"""Get or set the keywords describing an object."""
return self._get_field("keywords", list[str])

@keywords.setter
def keywords(self, v: list[str] | None) -> None:
self._set_field("keywords", v)
1 change: 1 addition & 0 deletions tests/data-files/item/sample-item-asset-properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
"start_datetime": "2017-05-01T13:22:30.040Z",
"end_datetime": "2017-05-02T13:22:30.040Z",
"license": "CC-BY-4.0",
"keywords": ["keyword_a"],
"providers": [
{
"name": "USGS",
Expand Down
22 changes: 22 additions & 0 deletions tests/test_common_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -538,3 +538,25 @@ def test_updated(self) -> None:
self.assertEqual(
analytic.to_dict()["updated"], utils.datetime_to_str(set_value)
)

def test_keywords(self) -> None:
item = self.item.clone()
cm = item.common_metadata
analytic = item.assets["analytic"]
analytic_cm = CommonMetadata(analytic)
thumbnail = item.assets["thumbnail"]
thumbnail_cm = CommonMetadata(thumbnail)

item_value = cm.keywords
a2_known_value = ["keyword_a"]

# Get
self.assertNotEqual(thumbnail_cm.keywords, item_value)
self.assertEqual(thumbnail_cm.keywords, a2_known_value)

# Set
set_value = ["keyword_b"]
analytic_cm.keywords = set_value

self.assertEqual(analytic_cm.keywords, set_value)
self.assertEqual(analytic.to_dict()["keywords"], set_value)

0 comments on commit be7bccb

Please sign in to comment.