in src/lookoutequipment/dataset.py [0:0]
def delete(self, force_delete=True):
"""
Deletes the dataset
Parameters:
force_delete (boolean):
if set to True, also delete all the models that are using this
dataset before deleting it. Otherwise, this method will list
the attached models (Default: True)
"""
# Let's try to delete this dataset:
try:
delete_dataset_response = self.client.delete_dataset(
DatasetName=self._dataset_name
)
print(f'Dataset "{self._dataset_name}" is deleted successfully.')
return delete_dataset_response
# This might not work if the dataset
# is used by an existing trained model:
except Exception as e:
error_code = e.response['Error']['Code']
# If the dataset is used by existing models and we asked a
# forced delete, we also delete the associated models before
# trying again the dataset deletion:
if (error_code == 'ConflictException') and (force_delete):
print(('Dataset is used by at least a model, deleting the '
'associated model(s) before deleting dataset.'))
models_list = self.list_models()
# List all the models that use this dataset and delete them:
for model_to_delete in models_list:
self.client.delete_model(ModelName=model_to_delete)
print(f'- Model "{model_to_delete}" is deleted successfully.')
# Retry the dataset deletion
delete_dataset_response = self.client.delete_dataset(
DatasetName=self._dataset_name
)
print(f'Dataset "{self._dataset_name}" is deleted successfully.')
return delete_dataset_response
# If force_delete is set to False, then we only list the models
# using this dataset back to the user:
elif force_delete == False:
print('Dataset is used by the following models:')
models_list = self.list_models()
for model_name in models_list:
print(f'- {model_name}')
print(('Rerun this method with `force_delete` set '
'to True to delete these models'))
# Dataset name not found:
elif (error_code == 'ResourceNotFoundException'):
print((f'Dataset "{self._dataset_name}" not found: creating a '
'dataset with this name is possible.'))