Custom Python Script
Hi All
Trying to achieve a custom python script based on below scenario.
My dataset contains a column WeekEnd and values as Dates (Some dates fall on Weekdays and some on Saturday and Sunday).
The check I'm trying to achieve here is check if column WeekEnd falls on Saturday then OK, else ERROR
ONLY able to write below.
Appreciate the help
from dataiku.metric import MetricDataTypes
import datetime
import calendar
def process(last_values,dataset):
date=last_values['col_stats:MAX:WeekEnd'].get_value()
if date == 5:
return 'OK', 'The date falls on a Saturday.'
else:
return 'Error','Record Count does not match: Expected:'
Operating system used: Browser
Best Answer
-
Hi
Thank you for the response.
Here is what I did.
Create a prepare recipe extract Day of Week. (Attached Screenshot).
In Status Tab, Checks, Custom Python Script as below.
from datetime import datetime, timedelta
def process(last_values,dataset):
MinDay = last_values['col_stats:MIN:Day'].get_value()
MaxDay = last_values['col_stats:MAX:Day'].get_value()
if MinDay == str(6) and MinDay == str(6):
return 'OK', 'The date falls on a Saturday, ' + 'Min Day of Week= ' + MinDay + ' Max Day of Week= ' + MaxDay
else:
return 'ERROR', 'The date DOES NOT fall on a Saturday, ' + 'Min Day of Week= ' + MinDay + ' Max Day of Week= ' + MaxDay
Answers
-
Hello,
When you execute this:
last_values['col_stats:MAX:WeekEnd'].get_value()
, you will get the maximum value of yourWeekEnd
column. If it's a binary column (0 or 1), you will get 1 as soon as you have at least one 1 in your dataset.So, do you want to ensure that all records fall on a Saturday? If so, I'll use a prepare step to extract the day of the week from your date columns and a check (no need to use Python) to ensure that for all records, the value is 5.
Matt