Discover this year's submissions to the Dataiku Frontrunner Awards and give kudos to your favorite use cases and success stories!READ MORE

Add custom checks to dataset programatically

Solved!
dadbuz
Level 2
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
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
2 Replies
AlexT
Dataiker
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
dadbuz
Level 2
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