diff --git a/CHANGELOG.md b/CHANGELOG.md index d77a9b2..e298fe0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [0.46.0] - 2025-12-04 + ### Added - `tilebox-datasets`: Added `create_dataset` method to `Client` to create a new dataset. @@ -293,8 +295,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Released under the [MIT](https://opensource.org/license/mit) license. - Released packages: `tilebox-datasets`, `tilebox-workflows`, `tilebox-storage`, `tilebox-grpc` -[Unreleased]: https://github.com/tilebox/tilebox-python/compare/v0.45.0...HEAD -[0.45.0]: https://github.com/tilebox/tilebox-python/compare/v0.45.0...v0.45.0 +[Unreleased]: https://github.com/tilebox/tilebox-python/compare/v0.46.0...HEAD +[0.46.0]: https://github.com/tilebox/tilebox-python/compare/v0.45.0...v0.46.0 +[0.45.0]: https://github.com/tilebox/tilebox-python/compare/v0.44.0...v0.45.0 [0.44.0]: https://github.com/tilebox/tilebox-python/compare/v0.43.0...v0.44.0 [0.43.0]: https://github.com/tilebox/tilebox-python/compare/v0.42.0...v0.43.0 [0.42.0]: https://github.com/tilebox/tilebox-python/compare/v0.41.0...v0.42.0 diff --git a/tilebox-datasets/tests/data/datasets.py b/tilebox-datasets/tests/data/datasets.py index 2b9588b..d1d6b23 100644 --- a/tilebox-datasets/tests/data/datasets.py +++ b/tilebox-datasets/tests/data/datasets.py @@ -1,7 +1,10 @@ import string from dataclasses import replace +from datetime import datetime, timedelta from functools import lru_cache +from uuid import UUID +import numpy as np from google.protobuf.descriptor_pb2 import FieldDescriptorProto, FileDescriptorProto, FileDescriptorSet from hypothesis.strategies import ( DrawFn, @@ -16,6 +19,7 @@ text, uuids, ) +from shapely import Geometry from tests.example_dataset.example_dataset_pb2 import DESCRIPTOR_PROTO from tilebox.datasets.data.datasets import ( @@ -26,6 +30,7 @@ DatasetType, Field, FieldAnnotation, + FieldDict, ListDatasetsResponse, ) from tilebox.datasets.message_pool import register_once @@ -39,6 +44,44 @@ def field_annotations(draw: DrawFn) -> FieldAnnotation: return FieldAnnotation(description, example_value) +@composite +def field_dicts(draw: DrawFn) -> FieldDict: + """A hypothesis strategy for generating random field dicts""" + name = draw(text(alphabet=string.ascii_lowercase + "_", min_size=3, max_size=25)) + field_type = draw( + one_of( + just(str), + just(list[str]), + just(bytes), + just(list[bytes]), + just(bool), + just(list[bool]), + just(int), + just(list[int]), + just(np.uint64), + just(list[np.uint64]), + just(float), + just(list[float]), + just(timedelta), + just(list[timedelta]), + just(datetime), + just(list[datetime]), + just(UUID), + just(list[UUID]), + just(Geometry), + just(list[Geometry]), + ) + ) + annotation = draw(field_annotations()) + + return { + "name": name, + "type": field_type, + "description": annotation.description, + "example_value": annotation.example_value, + } + + @composite def fields(draw: DrawFn) -> Field: """A hypothesis strategy for generating random fields""" diff --git a/tilebox-datasets/tests/data/test_datasets.py b/tilebox-datasets/tests/data/test_datasets.py index 05cdb9a..5c8215a 100644 --- a/tilebox-datasets/tests/data/test_datasets.py +++ b/tilebox-datasets/tests/data/test_datasets.py @@ -6,6 +6,7 @@ dataset_types, datasets, field_annotations, + field_dicts, fields, list_datasets_responses, ) @@ -16,6 +17,7 @@ DatasetType, Field, FieldAnnotation, + FieldDict, ListDatasetsResponse, ) @@ -25,6 +27,15 @@ def test_field_annotations_to_message_and_back(annotation: FieldAnnotation) -> N assert FieldAnnotation.from_message(annotation.to_message()) == annotation +@given(field_dicts()) +def test_field_from_dict(field_dict: FieldDict) -> None: + field = Field.from_dict(field_dict) + assert field.descriptor.name == field_dict["name"] + assert field.descriptor.type is not None + assert field.annotation.description == field_dict.get("description", "") + assert field.annotation.example_value == field_dict.get("example_value", "") + + @given(fields()) def test_fields_to_message_and_back(field: Field) -> None: assert Field.from_message(field.to_message()) == field