Add custom checks to dataset programatically

Solved!
dadbuz
Level 3
Add custom checks to dataset programatically

Hi,

Is there a way to add custom checks in the same way as adding metrics to a dataset through the dataset api ?

Thanks

0 Kudos
1 Solution
AlexT
Dataiker

Hi @dadbuz ,

You can add checks to a dataset via the api using get_settings() and save()

However to know the exact format of the check should first create the check you want manually on an existing dataset and then copy this to other datasets as needed. 

For example, if I have the following 2 checks:

 

Screenshot 2022-03-23 at 09.53.49.png

The get_settings() metricsChecks will return :

โ€ƒScreenshot 2022-03-23 at 09.56.18.png

If I want to apply the same check to another dataset what I can do is :

import dataiku
import pprint

client = dataiku.api_client()
project = client.get_default_project()

def copy_checks_ds(source_dataset, destination_dataset):

    original_settings = project.get_dataset(source_dataset).get_settings().get_raw()['metricsChecks']
    copy_to_dataset = project.get_dataset(destination_dataset)                                         
    
    settings = copy_to_dataset.get_settings()
    params = settings.get_raw()
    params['metricsChecks'] = original_settings
    
    settings.save()

# call copy
copy_checks_ds("original_dataset_name","destination_dataset_name") 

 

Let me know if that helps!

View solution in original post

0 Kudos
3 Replies
AlexT
Dataiker

Hi @dadbuz ,

You can add checks to a dataset via the api using get_settings() and save()

However to know the exact format of the check should first create the check you want manually on an existing dataset and then copy this to other datasets as needed. 

For example, if I have the following 2 checks:

 

Screenshot 2022-03-23 at 09.53.49.png

The get_settings() metricsChecks will return :

โ€ƒScreenshot 2022-03-23 at 09.56.18.png

If I want to apply the same check to another dataset what I can do is :

import dataiku
import pprint

client = dataiku.api_client()
project = client.get_default_project()

def copy_checks_ds(source_dataset, destination_dataset):

    original_settings = project.get_dataset(source_dataset).get_settings().get_raw()['metricsChecks']
    copy_to_dataset = project.get_dataset(destination_dataset)                                         
    
    settings = copy_to_dataset.get_settings()
    params = settings.get_raw()
    params['metricsChecks'] = original_settings
    
    settings.save()

# call copy
copy_checks_ds("original_dataset_name","destination_dataset_name") 

 

Let me know if that helps!

0 Kudos
wsih
Level 1

Hi @AlexT , 

I don't know why this not working for the model evaluation store, I try to change the settings of mes to add checks programmatically, but after build it is still not there.

Screen Shot 2023-07-12 at 02.26.46.png

dadbuz
Level 3
Author

Thanks Alex!

I was looking at the wrong setting - 'checks' instead of 'metricsChecks';

Will test this and if it works I will accept the answer.

0 Kudos