Skip to content

Commit b41a673

Browse files
authored
Merge pull request #86 from scaleapi/delete_annotations
delete annotations
2 parents 0c1524f + de1c7b3 commit b41a673

File tree

5 files changed

+51
-2
lines changed

5 files changed

+51
-2
lines changed

nucleus/__init__.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
IMAGE_URL_KEY,
9191
ITEM_METADATA_SCHEMA_KEY,
9292
ITEMS_KEY,
93+
KEEP_HISTORY_KEY,
9394
MODEL_RUN_ID_KEY,
9495
NAME_KEY,
9596
NUCLEUS_ENDPOINT,
@@ -1037,6 +1038,28 @@ def delete_slice(self, slice_id: str) -> dict:
10371038
)
10381039
return response
10391040

1041+
def delete_annotations(
1042+
self, dataset_id: str, reference_ids: list = None, keep_history=False
1043+
) -> dict:
1044+
"""
1045+
This endpoint deletes annotations.
1046+
1047+
:param
1048+
slice_id: id of the slice
1049+
1050+
:return:
1051+
{}
1052+
"""
1053+
payload = {KEEP_HISTORY_KEY: keep_history}
1054+
if reference_ids:
1055+
payload[REFERENCE_IDS_KEY] = reference_ids
1056+
response = self.make_request(
1057+
payload,
1058+
f"annotation/{dataset_id}",
1059+
requests_command=requests.delete,
1060+
)
1061+
return response
1062+
10401063
def append_to_slice(
10411064
self,
10421065
slice_id: str,

nucleus/constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
ITEM_KEY = "item"
4242
ITEM_METADATA_SCHEMA_KEY = "item_metadata_schema"
4343
JOB_ID_KEY = "job_id"
44+
KEEP_HISTORY_KEY = "keep_history"
4445
LABEL_KEY = "label"
4546
MASK_URL_KEY = "mask_url"
4647
MESSAGE_KEY = "message"

nucleus/dataset.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ def append(
241241
payload={REQUEST_ID_KEY: request_id, UPDATE_KEY: update},
242242
route=f"dataset/{self.id}/append?async=1",
243243
)
244-
return AsyncJob(response["job_id"], self._client)
244+
return AsyncJob(response[JOB_ID_KEY], self._client)
245245

246246
return self._client.populate_dataset(
247247
self.id,
@@ -361,3 +361,11 @@ def items_and_annotations(
361361
requests_command=requests.get,
362362
)
363363
return convert_export_payload(api_payload[EXPORTED_ROWS])
364+
365+
def delete_annotations(
366+
self, reference_ids: list = None, keep_history=False
367+
):
368+
response = self._client.delete_annotations(
369+
self.id, reference_ids, keep_history
370+
)
371+
return AsyncJob(response[JOB_ID_KEY], self._client)

tests/test_annotation.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,3 +302,19 @@ def test_polygon_gt_upload_ignore(dataset):
302302
assert_polygon_annotation_matches_dict(
303303
response_annotation, TEST_POLYGON_ANNOTATIONS[0]
304304
)
305+
306+
@pytest.mark.integration
307+
def test_box_gt_deletion(dataset):
308+
annotation = BoxAnnotation(**TEST_BOX_ANNOTATIONS[0])
309+
310+
print(annotation)
311+
312+
response = dataset.annotate(annotations=[annotation])
313+
314+
assert response["annotations_processed"] == 1
315+
316+
job = dataset.delete_annotations()
317+
job.sleep_until_complete()
318+
job_status = job.status()
319+
assert job_status["status"] == "Completed"
320+
assert job_status["job_id"] == job.id

tests/test_slice.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import copy
22
import pytest
3+
import uuid
34
from nucleus import Slice, NucleusClient, DatasetItem, BoxAnnotation
45
from nucleus.constants import (
56
ANNOTATIONS_KEY,
@@ -170,7 +171,7 @@ def test_slice_send_to_labeling(dataset):
170171

171172
# Slice creation
172173
slc = dataset.create_slice(
173-
name=TEST_SLICE_NAME,
174+
name=(TEST_SLICE_NAME + str(uuid.uuid4())[-10:]),
174175
reference_ids=[ds_items[0].reference_id, ds_items[1].reference_id],
175176
)
176177

0 commit comments

Comments
 (0)