Skip to content

Commit da62de5

Browse files
committed
Make extent not required for VerticalSpatialDimension
1 parent 6e8eb22 commit da62de5

File tree

2 files changed

+34
-4
lines changed

2 files changed

+34
-4
lines changed

pystac/extensions/datacube.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,15 +142,18 @@ def from_dict(d: dict[str, Any]) -> Dimension:
142142

143143
class SpatialDimension(Dimension):
144144
@property
145-
def extent(self) -> list[float]:
145+
def extent(self) -> list[float] | None:
146146
"""Extent (lower and upper bounds) of the dimension as two-dimensional array.
147147
Open intervals with ``None`` are not allowed."""
148-
return get_required(
149-
self.properties.get(DIM_EXTENT_PROP), "cube:dimension", DIM_EXTENT_PROP
148+
return cast(
149+
list[float],
150+
get_required(
151+
self.properties.get(DIM_EXTENT_PROP), "cube:dimension", DIM_EXTENT_PROP
152+
),
150153
)
151154

152155
@extent.setter
153-
def extent(self, v: list[float]) -> None:
156+
def extent(self, v: list[float] | None) -> None:
154157
self.properties[DIM_EXTENT_PROP] = v
155158

156159
@property
@@ -228,6 +231,19 @@ def axis(self) -> VerticalSpatialDimensionAxis:
228231
def axis(self, v: VerticalSpatialDimensionAxis) -> None:
229232
self.properties[DIM_AXIS_PROP] = v
230233

234+
@property
235+
def extent(self) -> list[float] | None:
236+
"""Extent (lower and upper bounds) of the dimension as two-dimensional array.
237+
Open intervals with ``None`` are not allowed."""
238+
return self.properties.get(DIM_EXTENT_PROP)
239+
240+
@extent.setter
241+
def extent(self, v: list[float] | None) -> None:
242+
if v is None:
243+
self.properties.pop(DIM_EXTENT_PROP, None)
244+
else:
245+
self.properties[DIM_EXTENT_PROP] = v
246+
231247
@property
232248
def unit(self) -> str | None:
233249
"""The unit of measurement for the data, preferably compliant to `UDUNITS-2

tests/extensions/test_datacube.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,20 @@ def test_temporal_dimension_description(
110110
assert "description" not in temporal_dimension.properties
111111

112112

113+
def test_vertical_dimension_extent_not_required() -> None:
114+
props: dict[str, list[float]] = {}
115+
dim = dc.VerticalSpatialDimension(props)
116+
assert dim.extent is None
117+
118+
119+
def test_vertical_dimension_setting_extent_to_none_pops_it() -> None:
120+
props: dict[str, list[float]] = {"extent": [10, 100]}
121+
dim = dc.VerticalSpatialDimension(props)
122+
assert dim.extent == [10, 100]
123+
dim.extent = None
124+
assert props == {}
125+
126+
113127
def test_stac_extensions(ext_item: Item) -> None:
114128
assert dc.DatacubeExtension.has_extension(ext_item)
115129

0 commit comments

Comments
 (0)