Skip to content

Commit

Permalink
feat: permissively deserialize temporal extents (#1222)
Browse files Browse the repository at this point in the history
  • Loading branch information
gadomski authored Sep 22, 2023
1 parent 9a9575f commit b63adb4
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## [Unreleased]

### Added

- Permissive deserialization of Collection temporal extents ([#1222](https://github.com/stac-utils/pystac/pull/1222))

### Fixed

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

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


## [v1.8.3] - 2023-07-12

### Added
Expand Down
14 changes: 14 additions & 0 deletions pystac/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,20 @@ def from_dict(d: Dict[str, Any]) -> TemporalExtent:
"""
parsed_intervals: List[List[Optional[datetime]]] = []
for i in d["interval"]:
if isinstance(i, str):
# d["interval"] is a list of strings, so we correct the list and
# try again
# https://github.com/stac-utils/pystac/issues/1221
warnings.warn(
"A collection's temporal extent should be a list of lists, but "
"is instead a "
"list of strings. pystac is fixing this issue and continuing "
"deserialization, but note that the source "
"collection is invalid STAC.",
UserWarning,
)
d["interval"] = [d["interval"]]
return TemporalExtent.from_dict(d)
start = None
end = None

Expand Down
10 changes: 10 additions & 0 deletions tests/test_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -660,3 +660,13 @@ def test_delete_asset_relative_no_self_link_fails(
assert asset.href in str(e.value)
assert name in collection.assets
assert os.path.exists(href)


def test_permissive_temporal_extent_deserialization(collection: Collection) -> None:
# https://github.com/stac-utils/pystac/issues/1221
collection_dict = collection.to_dict(include_self_link=False, transform_hrefs=False)
collection_dict["extent"]["temporal"]["interval"] = collection_dict["extent"][
"temporal"
]["interval"][0]
with pytest.warns(UserWarning):
Collection.from_dict(collection_dict)

0 comments on commit b63adb4

Please sign in to comment.