Skip to content

Commit efed9e7

Browse files
committed
Remove pre-0.8 logic from identify methods
1 parent 8cc78ac commit efed9e7

File tree

2 files changed

+16
-33
lines changed

2 files changed

+16
-33
lines changed

pystac/serialization/identify.py

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -187,11 +187,7 @@ def _identify_stac_extensions(
187187
if "links" in d:
188188
found_checksum = False
189189
for link in d["links"]:
190-
# Account for old links as dicts
191-
if isinstance(link, str):
192-
link_props = cast(Dict[str, Any], d["links"][link]).keys()
193-
else:
194-
link_props = cast(Dict[str, Any], link).keys()
190+
link_props = cast(Dict[str, Any], link).keys()
195191

196192
if any(prop.startswith("checksum:") for prop in link_props):
197193
found_checksum = True
@@ -374,15 +370,7 @@ def identify_stac_object(json_dict: Dict[str, Any]) -> STACJSONDescription:
374370
stac_extensions = json_dict.get("stac_extensions", None)
375371

376372
if stac_version is None:
377-
if (
378-
object_type == pystac.STACObjectType.CATALOG
379-
or object_type == pystac.STACObjectType.COLLECTION
380-
):
381-
version_range.set_max(STACVersionID("0.5.2"))
382-
elif object_type == pystac.STACObjectType.ITEM:
383-
version_range.set_max(STACVersionID("0.7.0"))
384-
else: # ItemCollection
385-
version_range.set_min(STACVersionID("0.8.0"))
373+
version_range.set_min(STACVersionID("0.8.0"))
386374
else:
387375
version_range.set_to_single(stac_version)
388376

@@ -394,7 +382,7 @@ def identify_stac_object(json_dict: Dict[str, Any]) -> STACJSONDescription:
394382
# if the stac_extensions property doesn't exist for everything
395383
# but ItemCollection (except after 0.9.0, when ItemCollection also got
396384
# the stac_extensions property).
397-
if version_range.is_earlier_than("0.8.0") or (
385+
if (
398386
object_type == pystac.STACObjectType.ITEMCOLLECTION
399387
and not version_range.is_later_than("0.8.1")
400388
):
@@ -412,21 +400,4 @@ def identify_stac_object(json_dict: Dict[str, Any]) -> STACJSONDescription:
412400
# code translates the short name IDs used pre-1.0.0-RC1 to the
413401
# relevant extension schema uri identifier.
414402

415-
if not version_range.is_single_version():
416-
# Final Checks
417-
418-
if "links" in json_dict:
419-
# links were a dictionary only in 0.5
420-
if "links" in json_dict and isinstance(json_dict["links"], dict):
421-
version_range.set_to_single(STACVersionID("0.5.2"))
422-
423-
# self links became non-required in 0.7.0
424-
if not version_range.is_earlier_than("0.7.0") and not any(
425-
filter(
426-
lambda l: cast(Dict[str, Any], l)["rel"] == pystac.RelType.SELF,
427-
json_dict["links"],
428-
)
429-
):
430-
version_range.set_min(STACVersionID("0.7.0"))
431-
432403
return STACJSONDescription(object_type, version_range, set(stac_extensions))

tests/serialization/test_identify.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def test_identify_non_stac_raises_error(self) -> None:
6868

6969
self.assertIn("JSON does not represent a STAC object", str(ctx.exception))
7070

71-
def test_identify_0_8_itemcollection(self) -> None:
71+
def test_identify_0_8_itemcollection_type(self) -> None:
7272
itemcollection_path = TestCases.get_path(
7373
"data-files/examples/0.8.1/item-spec/"
7474
"examples/itemcollection-sample-full.json"
@@ -97,6 +97,18 @@ def test_identify_invalid_with_stac_version(self) -> None:
9797

9898
self.assertIsNone(identify_stac_object_type(not_stac))
9999

100+
def test_identify_0_8_itemcollection(self) -> None:
101+
itemcollection_path = TestCases.get_path(
102+
"data-files/examples/0.8.1/item-spec/"
103+
"examples/itemcollection-sample-full.json"
104+
)
105+
itemcollection_dict = pystac.StacIO.default().read_json(itemcollection_path)
106+
107+
actual = identify_stac_object(itemcollection_dict)
108+
109+
self.assertEqual(actual.object_type, pystac.STACObjectType.ITEMCOLLECTION)
110+
self.assertTrue(actual.version_range.contains("0.8.1"))
111+
100112

101113
class VersionTest(unittest.TestCase):
102114
def test_version_ordering(self) -> None:

0 commit comments

Comments
 (0)