Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add migration for pre-1.0.0-rc.1 Stats Object #447

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- `ItemCollection` class for working with GeoJSON FeatureCollections containing only
STAC Items ([#430](https://github.com/stac-utils/pystac/pull/430))
- Support for Python 3.9 ([#420](https://github.com/stac-utils/pystac/pull/420))
- Migration for pre-1.0.0-rc.1 Stats Objects (renamed to Range Objects in 1.0.0-rc.3) ([#447](https://github.com/stac-utils/pystac/pull/447))

### Changed

Expand Down
13 changes: 13 additions & 0 deletions pystac/serialization/migrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,23 @@ def _migrate_catalog(
d["stac_extensions"] = list(info.extensions)


def _migrate_collection_summaries(
d: Dict[str, Any], version: STACVersionID, info: STACJSONDescription
) -> None:
if version < "1.0.0-rc.1":
for prop, summary in d.get("summaries", {}).items():
if isinstance(summary, dict) and "min" in summary and "max" in summary:
d["summaries"][prop] = {
"minimum": summary["min"],
"maximum": summary["max"],
}


def _migrate_collection(
d: Dict[str, Any], version: STACVersionID, info: STACJSONDescription
) -> None:
_migrate_catalog(d, version, info)
_migrate_collection_summaries(d, version, info)


def _migrate_item(
Expand Down
15 changes: 14 additions & 1 deletion tests/serialization/test_migrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
merge_common_properties,
migrate_to_latest,
)
from pystac.utils import str_to_datetime
from pystac.utils import str_to_datetime, get_required

from tests.utils import TestCases

Expand Down Expand Up @@ -83,3 +83,16 @@ def test_migrates_renamed_extension(self) -> None:

self.assertTrue(ItemAssetsExtension.has_extension(collection))
self.assertIn("item_assets", collection.extra_fields)

def test_migrates_pre_1_0_0_rc1_stats_summary(self) -> None:
collection = pystac.Collection.from_file(
TestCases.get_path(
"data-files/examples/1.0.0-beta.2/collection-spec/"
"examples/sentinel2.json"
)
)
datetime_summary = get_required(
collection.summaries.get_range("datetime"), collection.summaries, "datetime"
)
self.assertEqual(datetime_summary.minimum, "2015-06-23T00:00:00Z")
self.assertEqual(datetime_summary.maximum, "2019-07-10T13:44:56Z")
16 changes: 15 additions & 1 deletion tests/test_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from pystac.extensions.eo import EOExtension
from pystac.validation import validate_dict
from pystac import Collection, Item, Extent, SpatialExtent, TemporalExtent, CatalogType
from pystac.utils import datetime_to_str
from pystac.utils import datetime_to_str, get_required
from tests.utils import TestCases, ARBITRARY_GEOM, ARBITRARY_BBOX

TEST_DATETIME = datetime(2020, 3, 14, 16, 32)
Expand Down Expand Up @@ -182,6 +182,20 @@ def test_assets(self) -> None:
collection = pystac.Collection.from_dict(data)
collection.validate()

def test_schema_summary(self) -> None:
collection = pystac.Collection.from_file(
TestCases.get_path(
"data-files/examples/1.0.0/collection-only/collection-with-schemas.json"
)
)
instruments_schema = get_required(
collection.summaries.get_schema("instruments"),
collection.summaries,
"instruments",
)

self.assertIsInstance(instruments_schema, dict)


class ExtentTest(unittest.TestCase):
def test_spatial_allows_single_bbox(self) -> None:
Expand Down