Skip to content

Commit 9f5249f

Browse files
Add keywords to common metadata (#1443)
* add keywords to common metadata * Update pystac/common_metadata.py * fix: lint --------- Co-authored-by: Pete Gadomski <pete.gadomski@gmail.com>
1 parent 778725d commit 9f5249f

File tree

4 files changed

+33
-0
lines changed

4 files changed

+33
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
- Add netCDF to pystac.media_type ([#1386](https://github.com/stac-utils/pystac/pull/1386))
1414
- Add convenience method for accessing pystac_client ([#1365](https://github.com/stac-utils/pystac/pull/1365))
1515
- Fix field ordering when saving `Item`s ([#1423](https://github.com/stac-utils/pystac/pull/1423))
16+
- Add keywords to common metadata ([#1443](https://github.com/stac-utils/pystac/pull/1443))
1617
- Add roles to common metadata ([#1444](https://github.com/stac-utils/pystac/pull/1444/files))
1718

1819
### Changed

pystac/common_metadata.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,15 @@ def updated(self) -> datetime | None:
232232
def updated(self, v: datetime | None) -> None:
233233
self._set_field("updated", utils.map_opt(utils.datetime_to_str, v))
234234

235+
@property
236+
def keywords(self) -> list[str] | None:
237+
"""Get or set the keywords describing the STAC entity."""
238+
return self._get_field("keywords", list[str])
239+
240+
@keywords.setter
241+
def keywords(self, v: list[str] | None) -> None:
242+
self._set_field("keywords", v)
243+
235244
@property
236245
def roles(self) -> list[str] | None:
237246
"""Get or set the semantic roles of the entity."""

tests/data-files/item/sample-item-asset-properties.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
"start_datetime": "2017-05-01T13:22:30.040Z",
7575
"end_datetime": "2017-05-02T13:22:30.040Z",
7676
"license": "CC-BY-4.0",
77+
"keywords": ["keyword_a"],
7778
"roles": ["a_role"],
7879
"providers": [
7980
{

tests/test_common_metadata.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,28 @@ def test_updated(self) -> None:
541541
analytic.to_dict()["updated"], utils.datetime_to_str(set_value)
542542
)
543543

544+
def test_keywords(self) -> None:
545+
item = self.item.clone()
546+
cm = item.common_metadata
547+
analytic = item.assets["analytic"]
548+
analytic_cm = CommonMetadata(analytic)
549+
thumbnail = item.assets["thumbnail"]
550+
thumbnail_cm = CommonMetadata(thumbnail)
551+
552+
item_value = cm.keywords
553+
a2_known_value = ["keyword_a"]
554+
555+
# Get
556+
self.assertNotEqual(thumbnail_cm.keywords, item_value)
557+
self.assertEqual(thumbnail_cm.keywords, a2_known_value)
558+
559+
# Set
560+
set_value = ["keyword_b"]
561+
analytic_cm.keywords = set_value
562+
563+
self.assertEqual(analytic_cm.keywords, set_value)
564+
self.assertEqual(analytic.to_dict()["keywords"], set_value)
565+
544566
def test_roles(self) -> None:
545567
item = self.item.clone()
546568
cm = item.common_metadata

0 commit comments

Comments
 (0)