From 4d8d9b76cd52dfa67e042caff5d864f7b23a068f Mon Sep 17 00:00:00 2001 From: Gaurav Gupta <47334368+gaugup@users.noreply.github.com> Date: Mon, 30 Oct 2023 13:35:38 -0700 Subject: [PATCH] Update requirements.txt to upgrade dice-ml to 0.11.0 (#2397) * Update requirements.txt to upgrade dice-ml to 0.11.0 * Add test Signed-off-by: Gaurav Gupta * Fix tests Signed-off-by: Gaurav Gupta --------- Signed-off-by: Gaurav Gupta --- responsibleai/requirements.txt | 2 +- .../test_counterfactual_advanced_features.py | 24 ++++++++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/responsibleai/requirements.txt b/responsibleai/requirements.txt index 3410a72627..160f651e49 100644 --- a/responsibleai/requirements.txt +++ b/responsibleai/requirements.txt @@ -1,4 +1,4 @@ -dice-ml>=0.10,<0.11 +dice-ml>=0.11,<0.12 econml>=0.14.1 statsmodels<0.14.0 jsonschema diff --git a/responsibleai/tests/counterfactual/test_counterfactual_advanced_features.py b/responsibleai/tests/counterfactual/test_counterfactual_advanced_features.py index f80911a757..20ad8362f9 100644 --- a/responsibleai/tests/counterfactual/test_counterfactual_advanced_features.py +++ b/responsibleai/tests/counterfactual/test_counterfactual_advanced_features.py @@ -21,10 +21,15 @@ class TestCounterfactualAdvancedFeatures(object): @pytest.mark.parametrize('vary_all_features', [True, False]) @pytest.mark.parametrize('feature_importance', [True, False]) + @pytest.mark.parametrize('encode_target_as_strings', [True, False]) def test_counterfactual_vary_features( - self, vary_all_features, feature_importance): + self, vary_all_features, feature_importance, + encode_target_as_strings): X_train, X_test, y_train, y_test, feature_names, _ = \ create_iris_data() + if encode_target_as_strings: + y_train = y_train.astype(str) + y_test = y_test.astype(str) model = create_lightgbm_classifier(X_train, y_train) X_train['target'] = y_train @@ -50,6 +55,23 @@ def test_counterfactual_vary_features( cf_obj = rai_insights.counterfactual.get()[0] assert cf_obj is not None + for index in range(0, len(cf_obj.cf_examples_list)): + assert isinstance( + cf_obj.cf_examples_list[ + index].test_instance_df[ + 'target'].values[0], str) == encode_target_as_strings + + assert cf_obj.cf_examples_list[ + index].test_instance_df['target'].values[0] in set( + y_train) + + cf_target_array = cf_obj.cf_examples_list[0].final_cfs_df[ + 'target'].values + for inner_index in range(0, 10): + assert isinstance( + cf_target_array[ + inner_index], str) == encode_target_as_strings + assert cf_target_array[inner_index] in set(y_train) @pytest.mark.parametrize('feature_importance', [True, False]) def test_counterfactual_permitted_range(self, feature_importance):