Repository: AI-SDC/SACRO-ML (language: python)

Issue:
Addressing issue 142



Discussion / hints:

Fix patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index cf958bea..2f477d5c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,14 +1,19 @@
 # Changelog
 
+## Version 1.0.4 (May 5, 2023)
+
+Changes:
+*    Fixed SafeRandomForestClassifier "base estimator changed" error ([#143](https://github.com/AI-SDC/AI-SDC/pull/143))
+
 ## Version 1.0.3 (May 2, 2023)
 
 Changes:
-*    Refactored metrics ([#111](https://github.com/AI-SDC/AI-SDC/pull/111)).
-*    Fixed a bug making a report when dummy reps is 0 ([#113](https://github.com/AI-SDC/AI-SDC/pull/113)).
-*    Fixed safemodel JSON output ([#115](https://github.com/AI-SDC/AI-SDC/pull/115)).
-*    Added a module to produce recommendations from attack JSON output ([#116](https://github.com/AI-SDC/AI-SDC/pull/116)).
-*    Disabled non-default report logs ([#123](https://github.com/AI-SDC/AI-SDC/pull/123)).
-*    Fixed a minor bug in worst case example ([#124](https://github.com/AI-SDC/AI-SDC/pull/124)).
+*    Refactored metrics ([#111](https://github.com/AI-SDC/AI-SDC/pull/111))
+*    Fixed a bug making a report when dummy reps is 0 ([#113](https://github.com/AI-SDC/AI-SDC/pull/113))
+*    Fixed safemodel JSON output ([#115](https://github.com/AI-SDC/AI-SDC/pull/115))
+*    Added a module to produce recommendations from attack JSON output ([#116](https://github.com/AI-SDC/AI-SDC/pull/116))
+*    Disabled non-default report logs ([#123](https://github.com/AI-SDC/AI-SDC/pull/123))
+*    Fixed a minor bug in worst case example ([#124](https://github.com/AI-SDC/AI-SDC/pull/124))
 
 ## Version 1.0.2 (Feb 27, 2023)
 
diff --git a/CITATION.cff b/CITATION.cff
index 0b0a0526..d49689e2 100644
--- a/CITATION.cff
+++ b/CITATION.cff
@@ -1,8 +1,8 @@
 cff-version: 1.2.0
 title: AI-SDC
-version: 1.0.3
-doi: 10.5281/zenodo.7886945
-date-released: 2023-05-02
+version: 1.0.4
+doi:
+date-released: 2023-05-05
 license: MIT
 repository-code: https://github.com/AI-SDC/AI-SDC
 languages:
diff --git a/aisdc/safemodel/classifiers/saferandomforestclassifier.py b/aisdc/safemodel/classifiers/saferandomforestclassifier.py
index 3315f96f..45670be1 100644
--- a/aisdc/safemodel/classifiers/saferandomforestclassifier.py
+++ b/aisdc/safemodel/classifiers/saferandomforestclassifier.py
@@ -12,7 +12,7 @@
 from ..safemodel import SafeModel
 from .safedecisiontreeclassifier import decision_trees_are_equal
 
-# pylint: disable=too-many-ancestors,too-many-instance-attributes
+# pylint: disable=too-many-ancestors,too-many-instance-attributes, unidiomatic-typecheck
 
 
 class SafeRandomForestClassifier(SafeModel, RandomForestClassifier):
@@ -72,7 +72,7 @@ def additional_checks(  # pylint: disable=too-many-nested-blocks,too-many-branch
         for item in self.examine_seperately_items:
             # template for class of things that make up forest
             if item == "base_estimator":
-                if curr_separate[item] != saved_separate[item]:
+                if type(curr_separate[item]) != type(saved_separate[item]):
                     # msg += get_reporting_string(name="basic_params_differ",length=1)
                     msg += get_reporting_string(
                         name="param_changed_from_to",
diff --git a/setup.py b/setup.py
index 54547e0a..4c676d82 100644
--- a/setup.py
+++ b/setup.py
@@ -9,7 +9,7 @@
 
 setup(
     name="aisdc",
-    version="1.0.3",
+    version="1.0.4",
     license="MIT",
     maintainer="Jim Smith",
     maintainer_email="james.smith@uwe.ac.uk",


Test patch:
diff --git a/tests/test_saferandomforestclassifier.py b/tests/test_saferandomforestclassifier.py
index f766f76f..79bf4021 100644
--- a/tests/test_saferandomforestclassifier.py
+++ b/tests/test_saferandomforestclassifier.py
@@ -151,12 +151,12 @@ def test_randomforest_hacked_postfit():
     part2 = get_reporting_string(
         name="param_changed_from_to", key="bootstrap", val=False, cur_val=True
     )
-    part3 = get_reporting_string(
-        name="param_changed_from_to",
-        key="base_estimator",
-        val="DecisionTreeClassifier()",
-        cur_val="DecisionTreeClassifier()",
-    )
+    part3 = ""  # get_reporting_string(
+    #        name="param_changed_from_to",
+    #        key="base_estimator",
+    #        val="DecisionTreeClassifier()",
+    #        cur_val="DecisionTreeClassifier()",
+    #    )
     correct_msg2 = part1 + part2 + part3
     # print(f'Correct: {correct_msg2}\n Actual: {msg2}')
 
@@ -267,12 +267,12 @@ def test_randomforest_hacked_postfit_trees_swapped():
         name="param_changed_from_to", key="max_depth", val="None", cur_val="2"
     )
     part3 = get_reporting_string(name="forest_estimators_differ", idx=5)
-    part4 = get_reporting_string(
-        name="param_changed_from_to",
-        key="base_estimator",
-        val="DecisionTreeClassifier()",
-        cur_val="DecisionTreeClassifier()",
-    )
+    part4 = ""  # get_reporting_string(
+    #        name="param_changed_from_to",
+    #        key="base_estimator",
+    #        val="DecisionTreeClassifier()",
+    #        cur_val="DecisionTreeClassifier()",
+    #    )
     correct_msg = part1 + part2 + part3 + part4
     # print(f'Correct:\n{correct_msg} Actual:\n{msg}')
     assert msg == correct_msg, f"{msg}\n should be {correct_msg}"
@@ -298,12 +298,12 @@ def test_randomforest_hacked_postfit_moretrees():
         name="param_changed_from_to", key="n_estimators", val="5", cur_val="10"
     )
     part3 = get_reporting_string(name="different_num_estimators", num1=10, num2=5)
-    part4 = get_reporting_string(
-        name="param_changed_from_to",
-        key="base_estimator",
-        val="DecisionTreeClassifier()",
-        cur_val="DecisionTreeClassifier()",
-    )
+    part4 = ""  # get_reporting_string(
+    #        name="param_changed_from_to",
+    #        key="base_estimator",
+    #        val="DecisionTreeClassifier()",
+    #        cur_val="DecisionTreeClassifier()",
+    #    )
     correct_msg = part1 + part2 + part3 + part4
     # print(f'Correct:\n{correct_msg} Actual:\n{msg}')
     assert msg == correct_msg, f"{msg}\n should be {correct_msg}"