Skip to content

Commit

Permalink
owdatasampler: test code review
Browse files Browse the repository at this point in the history
  • Loading branch information
cemsbr committed Mar 3, 2018
1 parent 918d6fe commit ec30b92
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 23 deletions.
3 changes: 2 additions & 1 deletion Orange/widgets/data/owdatasampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ def set_sampling_type_i():
self.sampleSizeSpin = gui.spin(
ibox, self, "sampleSizeNumber", label="Instances: ",
minv=1, maxv=self._MAX_SAMPLE_SIZE,
callback=set_sampling_type(self.FixedSize))
callback=set_sampling_type(self.FixedSize),
controlWidth=90)
gui.checkBox(
ibox, self, "replacement", "Sample with replacement",
callback=set_sampling_type(self.FixedSize),
Expand Down
38 changes: 17 additions & 21 deletions Orange/widgets/data/tests/test_owdatasampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,39 +83,35 @@ def test_no_intersection_in_outputs(self):

def test_bigger_size_with_replacement(self):
"""Allow bigger output without replacement."""
_, out_size, actual_size = self._set_bigger_sample_size(True)
self.assertEqual(out_size, actual_size,
'Sample size should not be lowered with replacement')
self.send_signal('Data', self.iris[:2])
sample_size = self.set_fixed_sample_size(3, with_replacement=True)
self.assertEqual(3, sample_size, 'Should be able to set a bigger size '
'with replacement')

def test_bigger_size_without_replacement(self):
"""Lower output samples to match input's without replacement."""
in_size, _, actual_size = self._set_bigger_sample_size(False)
self.assertEqual(in_size, actual_size)
self.send_signal('Data', self.iris[:2])
sample_size = self.set_fixed_sample_size(3)
self.assertEqual(2, sample_size)

def test_bigger_output_warning(self):
self._set_bigger_sample_size(with_replacement=True)
"""Should warn when sample size is bigger than input."""
self.send_signal('Data', self.iris[:2])
self.set_fixed_sample_size(3, with_replacement=True)
self.assertTrue(self.widget.Warning.bigger_sample.is_shown())

def _set_bigger_sample_size(self, with_replacement):
"""Load data, set sample size and click to generate samples.
def set_fixed_sample_size(self, sample_size, with_replacement=False):
"""Set fixed sample size and return the number of gui spin.
The sample size is set to out_size which is bigger than the input size
in_size.
Returns integers in_size, out_size and the actual gui sample size.
Return the actual number in gui so we can check whether it is different
from sample_size. The number can be changed depending on the spin
maximum value.
"""
in_size = 2
out_size = in_size + 1
data = self.iris[:in_size]
self.widget.set_data(data)

self.select_sampling_type(self.widget.FixedSize)
self.widget.controls.replacement.setChecked(with_replacement)
self.widget.sampleSizeSpin.setValue(out_size)
self.widget.sampleSizeSpin.setValue(sample_size)
self.widget.commit()

actual_size = self.widget.sampleSizeSpin.value()
return in_size, out_size, actual_size
return self.widget.sampleSizeSpin.value()

def assertNoIntersection(self, sample, other):
for inst in sample:
Expand Down
3 changes: 2 additions & 1 deletion doc/visual-programming/source/widgets/data/datasampler.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ provided and *Sample Data* is pressed.
- **Fixed sample size** returns a selected number of data instances
with a chance to set *Sample with replacement*, which always samples
from the entire dataset (does not subtract instances already in
the subset)
the subset). With replacement, you can generate more instances than
available in the input dataset.
- `Cross Validation <https://en.wikipedia.org/wiki/Cross-validation_(statistics)>`_
partitions data instances into complementary subsets, where you can
select the number of folds (subsets) and which fold you want to
Expand Down

0 comments on commit ec30b92

Please sign in to comment.