Skip to content

Commit 7980830

Browse files
Delete a collection by name
1 parent 686ad64 commit 7980830

10 files changed

Lines changed: 118 additions & 16 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- `tilebox-datasets`: Added `delete_collection` method to `DatasetClient` to delete a collection by name.
13+
1014
## [0.37.1] - 2025-06-10
1115

1216
### Fixed

tilebox-datasets/tests/test_timeseries.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import xarray as xr
77
from attr import dataclass
88
from hypothesis import assume, given, settings
9-
from hypothesis.stateful import Bundle, RuleBasedStateMachine, invariant, rule
9+
from hypothesis.stateful import Bundle, RuleBasedStateMachine, consumes, invariant, rule
1010
from hypothesis.strategies import lists
1111
from promise import Promise
1212

@@ -28,6 +28,7 @@
2828
from tilebox.datasets.data.uuid import uuid_message_to_uuid, uuid_to_uuid_message
2929
from tilebox.datasets.datasetsv1.collections_pb2 import (
3030
CreateCollectionRequest,
31+
DeleteCollectionByNameRequest,
3132
GetCollectionByNameRequest,
3233
ListCollectionsRequest,
3334
)
@@ -291,6 +292,9 @@ def GetCollectionByName(self, req: GetCollectionByNameRequest) -> CollectionInfo
291292
return self.collections[req.collection_name]
292293
raise NotFoundError(f"Collection {req.collection_name} not found")
293294

295+
def DeleteCollectionByName(self, req: DeleteCollectionByNameRequest) -> None: # noqa: N802
296+
del self.collections[req.collection_name]
297+
294298
def ListCollections(self, req: ListCollectionsRequest) -> CollectionInfosMessage: # noqa: N802
295299
_ = req
296300
return CollectionInfosMessage(data=list(self.collections.values()))
@@ -346,6 +350,12 @@ def get_collection(self, collection: CollectionClient) -> None:
346350
got = self.dataset_client.collection(collection.name)
347351
assert got.info() == collection.info()
348352

353+
@rule(collection=consumes(inserted_collections)) # consumes -> remove from bundle afterwards
354+
def delete_collection(self, collection: CollectionClient) -> None:
355+
self.count_collections -= 1
356+
assert self.count_collections >= 0
357+
self.dataset_client.delete_collection(collection.name)
358+
349359
@invariant()
350360
def list_collections(self) -> None:
351361
collections = self.dataset_client.collections()

tilebox-datasets/tilebox/datasets/aio/dataset.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,14 @@ async def collection(self, name: str) -> "CollectionClient":
127127

128128
return CollectionClient(self, info)
129129

130+
async def delete_collection(self, name: str) -> None:
131+
"""Delete a collection by its name.
132+
133+
Args:
134+
name: The name of the collection to delete.
135+
"""
136+
await self._service.delete_collection_by_name(self._dataset.id, name)
137+
130138
def __repr__(self) -> str:
131139
return f"{self.name} [Timeseries Dataset]: {self._dataset.summary}"
132140

tilebox-datasets/tilebox/datasets/datasetsv1/collections_pb2.py

Lines changed: 9 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tilebox-datasets/tilebox/datasets/datasetsv1/collections_pb2.pyi

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,18 @@ class GetCollectionByNameRequest(_message.Message):
2525
dataset_id: _core_pb2.ID
2626
def __init__(self, collection_name: _Optional[str] = ..., with_availability: bool = ..., with_count: bool = ..., dataset_id: _Optional[_Union[_core_pb2.ID, _Mapping]] = ...) -> None: ...
2727

28+
class DeleteCollectionByNameRequest(_message.Message):
29+
__slots__ = ("collection_name", "dataset_id")
30+
COLLECTION_NAME_FIELD_NUMBER: _ClassVar[int]
31+
DATASET_ID_FIELD_NUMBER: _ClassVar[int]
32+
collection_name: str
33+
dataset_id: _core_pb2.ID
34+
def __init__(self, collection_name: _Optional[str] = ..., dataset_id: _Optional[_Union[_core_pb2.ID, _Mapping]] = ...) -> None: ...
35+
36+
class DeleteCollectionByNameResponse(_message.Message):
37+
__slots__ = ()
38+
def __init__(self) -> None: ...
39+
2840
class ListCollectionsRequest(_message.Message):
2941
__slots__ = ("dataset_id", "with_availability", "with_count")
3042
DATASET_ID_FIELD_NUMBER: _ClassVar[int]

tilebox-datasets/tilebox/datasets/datasetsv1/collections_pb2_grpc.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ def __init__(self, channel):
2626
request_serializer=datasets_dot_v1_dot_collections__pb2.GetCollectionByNameRequest.SerializeToString,
2727
response_deserializer=datasets_dot_v1_dot_core__pb2.CollectionInfo.FromString,
2828
_registered_method=True)
29+
self.DeleteCollectionByName = channel.unary_unary(
30+
'/datasets.v1.CollectionService/DeleteCollectionByName',
31+
request_serializer=datasets_dot_v1_dot_collections__pb2.DeleteCollectionByNameRequest.SerializeToString,
32+
response_deserializer=datasets_dot_v1_dot_collections__pb2.DeleteCollectionByNameResponse.FromString,
33+
_registered_method=True)
2934
self.ListCollections = channel.unary_unary(
3035
'/datasets.v1.CollectionService/ListCollections',
3136
request_serializer=datasets_dot_v1_dot_collections__pb2.ListCollectionsRequest.SerializeToString,
@@ -49,6 +54,12 @@ def GetCollectionByName(self, request, context):
4954
context.set_details('Method not implemented!')
5055
raise NotImplementedError('Method not implemented!')
5156

57+
def DeleteCollectionByName(self, request, context):
58+
"""Missing associated documentation comment in .proto file."""
59+
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
60+
context.set_details('Method not implemented!')
61+
raise NotImplementedError('Method not implemented!')
62+
5263
def ListCollections(self, request, context):
5364
"""Missing associated documentation comment in .proto file."""
5465
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
@@ -68,6 +79,11 @@ def add_CollectionServiceServicer_to_server(servicer, server):
6879
request_deserializer=datasets_dot_v1_dot_collections__pb2.GetCollectionByNameRequest.FromString,
6980
response_serializer=datasets_dot_v1_dot_core__pb2.CollectionInfo.SerializeToString,
7081
),
82+
'DeleteCollectionByName': grpc.unary_unary_rpc_method_handler(
83+
servicer.DeleteCollectionByName,
84+
request_deserializer=datasets_dot_v1_dot_collections__pb2.DeleteCollectionByNameRequest.FromString,
85+
response_serializer=datasets_dot_v1_dot_collections__pb2.DeleteCollectionByNameResponse.SerializeToString,
86+
),
7187
'ListCollections': grpc.unary_unary_rpc_method_handler(
7288
servicer.ListCollections,
7389
request_deserializer=datasets_dot_v1_dot_collections__pb2.ListCollectionsRequest.FromString,
@@ -139,6 +155,33 @@ def GetCollectionByName(request,
139155
metadata,
140156
_registered_method=True)
141157

158+
@staticmethod
159+
def DeleteCollectionByName(request,
160+
target,
161+
options=(),
162+
channel_credentials=None,
163+
call_credentials=None,
164+
insecure=False,
165+
compression=None,
166+
wait_for_ready=None,
167+
timeout=None,
168+
metadata=None):
169+
return grpc.experimental.unary_unary(
170+
request,
171+
target,
172+
'/datasets.v1.CollectionService/DeleteCollectionByName',
173+
datasets_dot_v1_dot_collections__pb2.DeleteCollectionByNameRequest.SerializeToString,
174+
datasets_dot_v1_dot_collections__pb2.DeleteCollectionByNameResponse.FromString,
175+
options,
176+
channel_credentials,
177+
insecure,
178+
call_credentials,
179+
compression,
180+
wait_for_ready,
181+
timeout,
182+
metadata,
183+
_registered_method=True)
184+
142185
@staticmethod
143186
def ListCollections(request,
144187
target,

0 commit comments

Comments
 (0)