diff --git a/Orange/widgets/data/owdatasampler.py b/Orange/widgets/data/owdatasampler.py index e84f2448167..4b9d084e7ab 100644 --- a/Orange/widgets/data/owdatasampler.py +++ b/Orange/widgets/data/owdatasampler.py @@ -385,7 +385,14 @@ def __init__(self, size=0, random_state=None): self.size = size self.random_state = random_state - def __call__(self): + def __call__(self, table=None): + """Bootstrap indices + + Args: + table: Not used (but part of the signature) + Returns: + tuple (out_of_sample, sample) indices + """ rgen = np.random.RandomState(self.random_state) sample = rgen.randint(0, self.size, self.size) sample.sort() # not needed for the code below, just for the user diff --git a/Orange/widgets/data/tests/test_owdatasampler.py b/Orange/widgets/data/tests/test_owdatasampler.py index 1a2482d8c98..c3e0ab27bad 100644 --- a/Orange/widgets/data/tests/test_owdatasampler.py +++ b/Orange/widgets/data/tests/test_owdatasampler.py @@ -12,7 +12,7 @@ def setUpClass(cls): cls.iris = Table("iris") def setUp(self): - self.widget = self.create_widget(OWDataSampler) + self.widget = self.create_widget(OWDataSampler) # type: OWDataSampler def test_error_message(self): """ Check if error message appears and then disappears when @@ -33,3 +33,23 @@ def test_stratified_on_unbalanced_data(self): self.widget.controls.stratify.setChecked(True) self.send_signal("Data", unbalanced_data) self.assertTrue(self.widget.Warning.could_not_stratify.is_shown()) + + def test_bootstrap(self): + self.select_sampling_type(self.widget.Bootstrap) + + self.send_signal("Data", self.iris) + + in_input = set(self.iris.ids) + in_sample = set(self.get_output("Data Sample").ids) + in_remaining = set(self.get_output("Remaining Data").ids) + + self.assertEqual(len(in_sample | in_remaining), len(in_input)) + self.assertEqual(len(in_sample & in_remaining), 0) + self.assertGreater(len(in_sample), 0) + # The following assert has a really high probability of being true: + # 1-(1/150*2/150*...*145/150) ~= 1-2e-64 + self.assertGreater(len(in_remaining), 0) + + def select_sampling_type(self, sampling_type): + buttons = self.widget.controls.sampling_type.group.buttons() + buttons[sampling_type].click()