Ejemplo n.º 1
0
    def test_inputs_check_sql(self):
        """Test if check_sql_input is called when data is sent to a widget."""
        d = Table()
        self.send_signal(self.widget.Inputs.data, d)
        self.assertIs(self.widget.pop_called_with(), d)

        a_table = object()
        with patch("Orange.widgets.utils.sql.Table",
                   MagicMock(return_value=a_table)) as table_mock:
            d = SqlTable(None, None, MagicMock())

            d.approx_len = MagicMock(return_value=AUTO_DL_LIMIT - 1)
            self.send_signal(self.widget.Inputs.data, d)
            table_mock.assert_called_once_with(d)
            self.assertIs(self.widget.pop_called_with(), a_table)
            table_mock.reset_mock()

            d.approx_len = MagicMock(return_value=AUTO_DL_LIMIT + 1)
            self.send_signal(self.widget.Inputs.data, d)
            table_mock.assert_not_called()
            self.assertIs(self.widget.pop_called_with(), None)
            self.assertTrue(self.widget.Error.download_sql_data.is_shown())
            table_mock.reset_mock()

            self.send_signal(self.widget.Inputs.data, None)
            table_mock.assert_not_called()
            self.assertIs(self.widget.pop_called_with(), None)
            self.assertFalse(self.widget.Error.download_sql_data.is_shown())
Ejemplo n.º 2
0
    def commit(self):
        if self.data is None:
            sample = other = None
            self.sampled_instances = self.remaining_instances = None
        elif isinstance(self.data, SqlTable):
            other = None
            if self.sampling_type == self.SqlProportion:
                sample = self.data.sample_percentage(
                    self.sampleSizeSqlPercentage, no_cache=True)
            else:
                sample = self.data.sample_time(self.sampleSizeSqlTime,
                                               no_cache=True)
            if self.sql_dl:
                sample.download_data()
                sample = Table(sample)

        else:
            if self.indices is None or not self.use_seed:
                self.updateindices()
                if self.indices is None:
                    return
            if self.sampling_type in (self.FixedProportion, self.FixedSize,
                                      self.Bootstrap):
                remaining, sample = self.indices
            elif self.sampling_type == self.CrossValidation:
                if self.compatibility_mode:
                    remaining, sample = self.indices[self.selectedFold - 1]
                else:
                    sample, remaining = self.indices[self.selectedFold - 1]

            sample = self.data[sample]
            other = self.data[remaining]
            self.sampled_instances = len(sample)
            self.remaining_instances = len(other)

        summary = sample.approx_len() if sample else self.info.NoOutput
        details = format_summary_details(sample) if sample else ""
        self.info.set_output_summary(summary, details)

        self.Outputs.data_sample.send(sample)
        self.Outputs.remaining_data.send(other)
Ejemplo n.º 3
0
def summarize_(data: Table):
    return PartialSummary(data.approx_len(),
                          format_summary_details(data, format=Qt.RichText))