From 59eda3318b69fd5264b745faf3aff2ce7029b4e4 Mon Sep 17 00:00:00 2001 From: Claire Pajot <35753672+cmpajot@users.noreply.github.com> Date: Mon, 7 Feb 2022 09:04:16 -0800 Subject: [PATCH] Delete Taxonomy (#210) * New version * taxonomy deletion code * Add note about annotation and prediction deletions * nits --- nucleus/__init__.py | 4 ++-- nucleus/dataset.py | 20 ++++++++++++++++++++ tests/test_taxonomy.py | 12 +++++++++++- 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/nucleus/__init__.py b/nucleus/__init__.py index 25c80458..a7e6b92a 100644 --- a/nucleus/__init__.py +++ b/nucleus/__init__.py @@ -391,8 +391,8 @@ def create_dataset( """ warnings.warn( "The default create_dataset('dataset_name', ...) method without the is_scene parameter will be deprecated soon in favor of providing the is_scene parameter explicitly. " - "Please make sure to create a dataset with either create_dataset('dataset_name', is_scene=True, ...) to upload " - "DatasetItems or create_dataset('dataset_name', is_scene=False, ...) to upload " + "Please make sure to create a dataset with either create_dataset('dataset_name', is_scene=False, ...) to upload " + "DatasetItems or create_dataset('dataset_name', is_scene=True, ...) to upload " "LidarScenes.", DeprecationWarning, ) diff --git a/nucleus/dataset.py b/nucleus/dataset.py index 003764e7..fcc414ac 100644 --- a/nucleus/dataset.py +++ b/nucleus/dataset.py @@ -976,6 +976,26 @@ def add_taxonomy( requests_command=requests.post, ) + def delete_taxonomy( + self, + taxonomy_name: str, + ): + """Deletes the given taxonomy. + + All annotations and predictions associated with the taxonomy will be deleted as well. + + Parameters: + taxonomy_name: The name of the taxonomy. + + Returns: + Returns a response with dataset_id, taxonomy_name and status of the delete taxonomy operation. + """ + return self._client.make_request( + {}, + f"dataset/{self.id}/taxonomy/{taxonomy_name}", + requests.delete, + ) + def items_and_annotations( self, ) -> List[Dict[str, Union[DatasetItem, Dict[str, List[Annotation]]]]]: diff --git a/tests/test_taxonomy.py b/tests/test_taxonomy.py index 4b44f7cd..d1d79f85 100644 --- a/tests/test_taxonomy.py +++ b/tests/test_taxonomy.py @@ -5,7 +5,7 @@ @pytest.fixture() def dataset(CLIENT): - ds = CLIENT.create_dataset(TEST_DATASET_NAME) + ds = CLIENT.create_dataset(TEST_DATASET_NAME, is_scene=False) ds.add_taxonomy( "[Pytest] taxonomy", @@ -62,3 +62,13 @@ def test_duplicate_taxonomy_update(dataset): assert response["dataset_id"] == dataset.id assert response["taxonomy_name"] == "[Pytest] taxonomy" assert response["status"] == "Taxonomy updated" + + +def test_delete_taxonomy(dataset): + response = dataset.delete_taxonomy( + "[Pytest] taxonomy", + ) + + assert response["dataset_id"] == dataset.id + assert response["taxonomy_name"] == "[Pytest] taxonomy" + assert response["status"] == "Taxonomy successfully deleted"