Skip to content

Commit 4dc0e0f

Browse files
authored
fix: added missing Classification parameter title (#1539)
* added missing Classification parameter title * added changes to changelog * added missing parameters to test_classification_object: title, nodata, percentage, count
1 parent 1b89b9d commit 4dc0e0f

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
- `Collection.from_items` for creating a `pystac.Collection` from an `ItemCollection` ([#1522](https://github.com/stac-utils/pystac/pull/1522))
88

9+
### Fixed
10+
- fixed missing parameter "title" in pystac.extensions.classification.Classification ([#1539](https://github.com/stac-utils/pystac/pull/1539))
11+
912
## [v1.12.2]
1013

1114
### Fixed

pystac/extensions/classification.py

+17
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ def apply(
6060
value: int,
6161
description: str | None = None,
6262
name: str | None = None,
63+
title: str | None = None,
6364
color_hint: str | None = None,
6465
nodata: bool | None = None,
6566
percentage: float | None = None,
@@ -74,6 +75,7 @@ def apply(
7475
name: Short name of the class for machine readability. Must consist only
7576
of letters, numbers, -, and _ characters. Required as of v2.0 of
7677
this extension.
78+
title: Human-readable name for use in, e.g., a map legend
7779
color_hint: An optional hexadecimal string-encoded representation of the
7880
RGB color that is suggested to represent this class (six hexadecimal
7981
characters, all capitalized)
@@ -90,6 +92,7 @@ def apply(
9092
"As of v2.0.0 of the classification extension, 'name' is required"
9193
)
9294
self.name = name
95+
self.title = title
9396
self.description = description
9497
self.color_hint = color_hint
9598
self.nodata = nodata
@@ -108,6 +111,7 @@ def create(
108111
value: int,
109112
description: str | None = None,
110113
name: str | None = None,
114+
title: str | None = None,
111115
color_hint: str | None = None,
112116
nodata: bool | None = None,
113117
percentage: float | None = None,
@@ -122,6 +126,7 @@ def create(
122126
name: Short name of the class for machine readability. Must consist only
123127
of letters, numbers, -, and _ characters. Required as of v2.0 of
124128
this extension.
129+
title: Human-readable name for use in, e.g., a map legend
125130
color_hint: An optional hexadecimal string-encoded representation of the
126131
RGB color that is suggested to represent this class (six hexadecimal
127132
characters, all capitalized)
@@ -134,6 +139,7 @@ def create(
134139
c.apply(
135140
value=value,
136141
name=name,
142+
title=title,
137143
description=description,
138144
color_hint=color_hint,
139145
nodata=nodata,
@@ -189,6 +195,17 @@ def name(self, v: str) -> None:
189195
)
190196
self.properties["name"] = v
191197

198+
@property
199+
def title(self) -> str | None:
200+
return self.properties.get("title")
201+
202+
@title.setter
203+
def title(self, v: str) -> None:
204+
if v is not None:
205+
self.properties["title"] = v
206+
else:
207+
self.properties.pop("title", None)
208+
192209
@property
193210
def color_hint(self) -> str | None:
194211
"""Get or set the optional color hint for this class.

tests/extensions/test_classification.py

+12-1
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,23 @@ def test_stac_extensions(landsat_item: Item) -> None:
6060

6161
def test_classification_object() -> None:
6262
c = Classification.create(
63-
name="dummy", description="empty class", value=0, color_hint="FF00AB"
63+
name="dummy",
64+
description="empty class",
65+
value=0,
66+
title="dummy title",
67+
color_hint="FF00AB",
68+
nodata=True,
69+
percentage=20.3,
70+
count=2,
6471
)
6572
assert c.name == "dummy"
6673
assert c.description == "empty class"
6774
assert c.color_hint == "FF00AB"
6875
assert c.value == 0
76+
assert c.title == "dummy title"
77+
assert c.nodata is True
78+
assert c.percentage == 20.3
79+
assert c.count == 2
6980

7081
assert Classification(c.to_dict()) == c
7182
with pytest.raises(NotImplementedError):

0 commit comments

Comments
 (0)