@@ -999,16 +999,22 @@ def test_calibrated_classifier_cv(method):
999999 # binary
10001000 X , y = load_breast_cancer (return_X_y = True )
10011001 X_train , X_test , y_train , y_test = train_test_split (X , y , test_size = 0.2 , random_state = 42 )
1002+ _original_decision_function = lgb .LGBMClassifier .decision_function
1003+ call_count = {"count" : 0 }
1004+
1005+ def _wrapped_decision_function (self , * args , ** kwargs ):
1006+ call_count ["count" ] += 1
1007+ return _original_decision_function (self , * args , ** kwargs )
1008+
10021009 with patch .object (
10031010 lgb .LGBMClassifier ,
10041011 "decision_function" ,
1005- autospec = True ,
1006- wraps = lgb .LGBMClassifier .decision_function ,
1007- ) as mock_decision_function :
1012+ _wrapped_decision_function ,
1013+ ):
10081014 clf = CalibratedClassifierCV (lgb .LGBMClassifier (n_estimators = 10 , verbose = - 1 ), method = method , cv = 3 )
10091015 clf .fit (X_train , y_train )
10101016 proba = clf .predict_proba (X_test )
1011- assert mock_decision_function . call_count > 0
1017+ assert call_count [ "count" ] > 0
10121018 assert proba .shape == (X_test .shape [0 ], 2 )
10131019 np .testing .assert_array_less (proba , 1.0 + 1e-9 )
10141020 np .testing .assert_array_less (- 1e-9 , proba )
@@ -1019,16 +1025,16 @@ def test_calibrated_classifier_cv(method):
10191025 # multiclass
10201026 X , y = load_iris (return_X_y = True )
10211027 X_train , X_test , y_train , y_test = train_test_split (X , y , test_size = 0.2 , random_state = 42 )
1028+ call_count ["count" ] = 0
10221029 with patch .object (
10231030 lgb .LGBMClassifier ,
10241031 "decision_function" ,
1025- autospec = True ,
1026- wraps = lgb .LGBMClassifier .decision_function ,
1027- ) as mock_decision_function :
1032+ _wrapped_decision_function ,
1033+ ):
10281034 clf = CalibratedClassifierCV (lgb .LGBMClassifier (n_estimators = 10 , verbose = - 1 ), method = method , cv = 3 )
10291035 clf .fit (X_train , y_train )
10301036 proba = clf .predict_proba (X_test )
1031- assert mock_decision_function . call_count > 0
1037+ assert call_count [ "count" ] > 0
10321038 assert proba .shape == (X_test .shape [0 ], 3 )
10331039 np .testing .assert_array_less (proba , 1.0 + 1e-9 )
10341040 np .testing .assert_array_less (- 1e-9 , proba )
0 commit comments