def delete()

in getting_started/utils/lookout_equipment_utils.py [0:0]


    def delete(self, force_delete=True):
        """
        Delete the dataset
        
        PARAMS
        ======
            force_delete: boolean (default: True)
                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.
        """
        # 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 = list_models_for_datasets(
                    dataset_name_prefix=self.dataset_name
                )
    
                # List 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 = list_models_for_datasets(
                    dataset_name_prefix=self.dataset_name,
                )
    
                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.'))