whylabs/whylogs

Condition Validator allows duplicated condition validators

Closed this issue · 0 comments

Description

The following code currently registers two validators with the same name, for the same column:

import pandas as pd
from typing import Any
from whylogs.experimental.core.validators import condition_validator
from whylogs.experimental.core.udf_schema import udf_schema
import whylogs as why

data = pd.DataFrame({"col1": [1, 3, 7]})


def do_something_important(validator_name, condition_name: str, value: Any, column_id=None):
    print("Validator: {}\n    Condition name {} failed for value {}".format(validator_name, condition_name, value))
    return

@condition_validator(["col1"], condition_name="less_than_four", actions=[do_something_important])
def lt_4(x):
    return x < 4


@condition_validator(["col1"], condition_name="less_than_four", actions=[do_something_important])
def lt_4_2(x):
    return x < 4


schema = udf_schema()
why.log(data, schema=schema).view()

which would trigger the action twice:

Validator: less_than_four
    Condition name less_than_four failed for value 7
Validator: less_than_four
    Condition name less_than_four failed for value 7

Suggestions

When registering a condition validator with an existing name for the same column, the latest version should replace the existing one.