Skip to content

Commit b63adb4

Browse files
authored
feat: permissively deserialize temporal extents (#1222)
1 parent 9a9575f commit b63adb4

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## [Unreleased]
44

5+
### Added
6+
7+
- Permissive deserialization of Collection temporal extents ([#1222](https://github.com/stac-utils/pystac/pull/1222))
8+
59
### Fixed
610

711
- Update usage of jsonschema ([#1215](https://github.com/stac-utils/pystac/pull/1215))
@@ -10,7 +14,6 @@
1014

1115
- `pystac.validation.local_validator.LocalValidator` ([#1215](https://github.com/stac-utils/pystac/pull/1215))
1216

13-
1417
## [v1.8.3] - 2023-07-12
1518

1619
### Added

pystac/collection.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,20 @@ def from_dict(d: Dict[str, Any]) -> TemporalExtent:
257257
"""
258258
parsed_intervals: List[List[Optional[datetime]]] = []
259259
for i in d["interval"]:
260+
if isinstance(i, str):
261+
# d["interval"] is a list of strings, so we correct the list and
262+
# try again
263+
# https://github.com/stac-utils/pystac/issues/1221
264+
warnings.warn(
265+
"A collection's temporal extent should be a list of lists, but "
266+
"is instead a "
267+
"list of strings. pystac is fixing this issue and continuing "
268+
"deserialization, but note that the source "
269+
"collection is invalid STAC.",
270+
UserWarning,
271+
)
272+
d["interval"] = [d["interval"]]
273+
return TemporalExtent.from_dict(d)
260274
start = None
261275
end = None
262276

tests/test_collection.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,3 +660,13 @@ def test_delete_asset_relative_no_self_link_fails(
660660
assert asset.href in str(e.value)
661661
assert name in collection.assets
662662
assert os.path.exists(href)
663+
664+
665+
def test_permissive_temporal_extent_deserialization(collection: Collection) -> None:
666+
# https://github.com/stac-utils/pystac/issues/1221
667+
collection_dict = collection.to_dict(include_self_link=False, transform_hrefs=False)
668+
collection_dict["extent"]["temporal"]["interval"] = collection_dict["extent"][
669+
"temporal"
670+
]["interval"][0]
671+
with pytest.warns(UserWarning):
672+
Collection.from_dict(collection_dict)

0 commit comments

Comments
 (0)