From 4d30aaf2e4f7bb899b145ed4ba4ed541b43f61c1 Mon Sep 17 00:00:00 2001 From: Tyler <31015976+tylanderson@users.noreply.github.com> Date: Wed, 2 Oct 2024 22:51:00 -0400 Subject: [PATCH 1/3] add keywords to common metadata --- CHANGELOG.md | 1 + pystac/common_metadata.py | 9 ++++++++ .../item/sample-item-asset-properties.json | 1 + tests/test_common_metadata.py | 22 +++++++++++++++++++ 4 files changed, 33 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 254536bea..9d1f5b4ed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 ([#1443](https://github.com/stac-utils/pystac/pull/1443)) ### Changed diff --git a/pystac/common_metadata.py b/pystac/common_metadata.py index c2d12e71d..8b3d47ce2 100644 --- a/pystac/common_metadata.py +++ b/pystac/common_metadata.py @@ -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) diff --git a/tests/data-files/item/sample-item-asset-properties.json b/tests/data-files/item/sample-item-asset-properties.json index a47273ea0..88a9e5b6b 100644 --- a/tests/data-files/item/sample-item-asset-properties.json +++ b/tests/data-files/item/sample-item-asset-properties.json @@ -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", diff --git a/tests/test_common_metadata.py b/tests/test_common_metadata.py index f7113481c..ab815002b 100644 --- a/tests/test_common_metadata.py +++ b/tests/test_common_metadata.py @@ -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) From 1050622a4de479830089c4318e011b1fcfa30601 Mon Sep 17 00:00:00 2001 From: Pete Gadomski Date: Tue, 15 Oct 2024 14:34:44 -0600 Subject: [PATCH 2/3] Update pystac/common_metadata.py --- pystac/common_metadata.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pystac/common_metadata.py b/pystac/common_metadata.py index 8b3d47ce2..b01b30332 100644 --- a/pystac/common_metadata.py +++ b/pystac/common_metadata.py @@ -216,7 +216,7 @@ def updated(self, v: datetime | None) -> None: @property def keywords(self) -> list[str] | None: - """Get or set the keywords describing an object.""" + """Get or set the keywords describing the STAC entity.""" return self._get_field("keywords", list[str]) @keywords.setter From e700e93b1163240558848f37165f2627bd6d5133 Mon Sep 17 00:00:00 2001 From: Pete Gadomski Date: Tue, 15 Oct 2024 15:09:18 -0600 Subject: [PATCH 3/3] fix: lint --- pystac/common_metadata.py | 2 +- tests/test_common_metadata.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pystac/common_metadata.py b/pystac/common_metadata.py index a80b84c3b..b7d7fbfc5 100644 --- a/pystac/common_metadata.py +++ b/pystac/common_metadata.py @@ -240,7 +240,7 @@ def keywords(self) -> list[str] | None: @keywords.setter def keywords(self, v: list[str] | None) -> None: self._set_field("keywords", v) - + @property def roles(self) -> list[str] | None: """Get or set the semantic roles of the entity.""" diff --git a/tests/test_common_metadata.py b/tests/test_common_metadata.py index 94a6e1a9b..4ea767322 100644 --- a/tests/test_common_metadata.py +++ b/tests/test_common_metadata.py @@ -548,7 +548,7 @@ def test_keywords(self) -> None: analytic_cm = CommonMetadata(analytic) thumbnail = item.assets["thumbnail"] thumbnail_cm = CommonMetadata(thumbnail) - + item_value = cm.keywords a2_known_value = ["keyword_a"] @@ -562,7 +562,7 @@ def test_keywords(self) -> None: self.assertEqual(analytic_cm.keywords, set_value) self.assertEqual(analytic.to_dict()["keywords"], set_value) - + def test_roles(self) -> None: item = self.item.clone() cm = item.common_metadata