def test_data_bias_config_multi_facet(): label_values = [1] facet_name = ["Facet1", "Facet2"] facet_threshold = [[0], [1, 2]] group_name = "A151" data_bias_config = BiasConfig( label_values_or_threshold=label_values, facet_name=facet_name, facet_values_or_threshold=facet_threshold, group_name=group_name, ) expected_config = { "label_values_or_threshold": label_values, "facet": [ { "name_or_index": facet_name[0], "value_or_threshold": facet_threshold[0] }, { "name_or_index": facet_name[1], "value_or_threshold": facet_threshold[1] }, ], "group_variable": group_name, } assert expected_config == data_bias_config.get_config()
def test_facet_of_bias_config(facet_name, facet_values_or_threshold, expected_result): label_values = [1] bias_config = BiasConfig( label_values_or_threshold=label_values, facet_name=facet_name, facet_values_or_threshold=facet_values_or_threshold, ) expected_config = { "label_values_or_threshold": label_values, **expected_result, } assert bias_config.get_config() == expected_config
def bias_config(): return BiasConfig( label_values_or_threshold=[1], facet_name="F1", facet_values_or_threshold=[0.5], group_name="F2", )
def test_invalid_bias_config(): # Empty facet list, with pytest.raises(AssertionError, match="Please provide at least one facet"): BiasConfig( label_values_or_threshold=[1], facet_name=[], ) # Two facets but only one value with pytest.raises( ValueError, match="The number of facet names doesn't match the number of facet values" ): BiasConfig( label_values_or_threshold=[1], facet_name=["Feature1", "Feature2"], facet_values_or_threshold=[[1]], )
def test_data_bias_config(): label_values = [1] facet_name = "F1" facet_threshold = 0.3 group_name = "A151" data_bias_config = BiasConfig( label_values_or_threshold=label_values, facet_name=facet_name, facet_values_or_threshold=facet_threshold, group_name=group_name, ) expected_config = { "label_values_or_threshold": label_values, "facet": [{"name_or_index": facet_name, "value_or_threshold": facet_threshold}], "group_variable": group_name, } assert expected_config == data_bias_config.get_config()
def bias_config(): return BiasConfig( label_values_or_threshold=BIAS_POSITIVE_LABEL_VALUE, facet_name=BIAS_FACET_NAME, facet_values_or_threshold=BIAS_FACET_VALUE, )
def bias_config(): return BiasConfig( label_values_or_threshold=[0], facet_name="customer_gender_female", facet_values_or_threshold=[1], )