|
2 | 2 | from unittest.mock import Mock, patch |
3 | 3 |
|
4 | 4 | from Orange.classification.base_classification import LearnerClassification |
5 | | -from Orange.data import Table |
| 5 | +from Orange.data import Table, ContinuousVariable |
6 | 6 | from Orange.evaluation import CrossValidation |
7 | 7 | from Orange.modelling import Fitter |
8 | | -from Orange.preprocess import Randomize |
| 8 | +from Orange.preprocess import Randomize, Discretize |
9 | 9 | from Orange.regression.base_regression import LearnerRegression |
10 | 10 |
|
11 | 11 |
|
@@ -130,3 +130,25 @@ def test_correctly_sets_preprocessors_on_learner(self): |
130 | 130 | def test_n_jobs_fitting(self): |
131 | 131 | with patch('Orange.evaluation.testing.CrossValidation._MIN_NJOBS_X_SIZE', 1): |
132 | 132 | CrossValidation(self.heart_disease, [DummyFitter()], k=5, n_jobs=5) |
| 133 | + |
| 134 | + def test_properly_delegates_preprocessing(self): |
| 135 | + class DummyClassificationLearner(LearnerClassification): |
| 136 | + preprocessors = [Discretize()] |
| 137 | + |
| 138 | + def __init__(self, classification_param=1, **_): |
| 139 | + super().__init__() |
| 140 | + self.param = classification_param |
| 141 | + |
| 142 | + class DummyFitter(Fitter): |
| 143 | + __fits__ = {'classification': DummyClassificationLearner, |
| 144 | + 'regression': DummyRegressionLearner} |
| 145 | + |
| 146 | + data = self.heart_disease |
| 147 | + fitter = DummyFitter() |
| 148 | + # Sanity check |
| 149 | + self.assertTrue(any( |
| 150 | + isinstance(v, ContinuousVariable) for v in data.domain.variables)) |
| 151 | + # Preprocess the data and check that the discretization was applied |
| 152 | + pp_data = fitter.preprocess(self.heart_disease) |
| 153 | + self.assertTrue(not any( |
| 154 | + isinstance(v, ContinuousVariable) for v in pp_data.domain.variables)) |
0 commit comments