{
    "file_diffs": [
        {
            "old_file_content": "from functools import partial\nfrom itertools import count, groupby, repeat\nfrom xml.sax.saxutils import escape\n\nimport numpy as np\nfrom scipy.stats import norm, rayleigh, beta, gamma, pareto, expon\n\nfrom AnyQt.QtWidgets import QGraphicsRectItem\nfrom AnyQt.QtGui import QColor, QPen, QBrush, QPainter, QPalette, QPolygonF\nfrom AnyQt.QtCore import Qt, QRectF, QPointF, pyqtSignal as Signal\nimport pyqtgraph as pg\n\nfrom Orange.data import Table, DiscreteVariable, ContinuousVariable\nfrom Orange.preprocess.discretize import decimal_binnings\nfrom Orange.statistics import distribution, contingency\nfrom Orange.widgets import gui, settings\nfrom Orange.widgets.utils.annotated_data import \\\n    create_groups_table, create_annotated_table, ANNOTATED_DATA_SIGNAL_NAME\nfrom Orange.widgets.utils.itemmodels import DomainModel\nfrom Orange.widgets.utils.widgetpreview import WidgetPreview\nfrom Orange.widgets.visualize.utils.plotutils import ElidedLabelsAxis\nfrom Orange.widgets.widget import Input, Output, OWWidget, Msg\n\nfrom Orange.widgets.visualize.owscatterplotgraph import \\\n    LegendItem as SPGLegendItem\n\n\nclass ScatterPlotItem(pg.ScatterPlotItem):\n    Symbols = pg.graphicsItems.ScatterPlotItem.Symbols\n\n    # pylint: disable=arguments-differ\n    def paint(self, painter, option, widget=None):\n        if self.opts[\"pxMode\"]:\n            painter.setRenderHint(QPainter.SmoothPixmapTransform, True)\n        if self.opts[\"antialias\"]:\n            painter.setRenderHint(QPainter.Antialiasing, True)\n        super().paint(painter, option, widget)\n\n\nclass LegendItem(SPGLegendItem):\n    @staticmethod\n    def mousePressEvent(event):\n        if event.button() == Qt.LeftButton:\n            event.accept()\n        else:\n            event.ignore()\n\n    def mouseMoveEvent(self, event):\n        if event.buttons() & Qt.LeftButton:\n            event.accept()\n            if self.parentItem() is not None:\n                self.autoAnchor(\n                    self.pos() + (event.pos() - event.lastPos()) / 2)\n        else:\n            event.ignore()\n\n    @staticmethod\n    def mouseReleaseEvent(event):\n        if event.button() == Qt.LeftButton:\n            event.accept()\n        else:\n            event.ignore()\n\n\nclass DistributionBarItem(pg.GraphicsObject):\n    def __init__(self, x, width, padding, freqs, colors, stacked, expanded,\n                 tooltip):\n        super().__init__()\n        self.x = x\n        self.width = width\n        self.freqs = freqs\n        self.colors = colors\n        self.padding = padding\n        self.stacked = stacked\n        self.expanded = expanded\n        self.__picture = None\n        self.polygon = None\n        self.hovered = False\n        self.setAcceptHoverEvents(True)\n        self.setToolTip(tooltip)\n\n    def hoverEnterEvent(self, event):\n        super().hoverEnterEvent(event)\n        self.hovered = True\n        self.update()\n\n    def hoverLeaveEvent(self, event):\n        super().hoverLeaveEvent(event)\n        self.hovered = False\n        self.update()\n\n    def paint(self, painter, _options, _widget):\n        if self.expanded:\n            tot = np.sum(self.freqs)\n            if tot == 0:\n                return\n            freqs = self.freqs / tot\n        else:\n            freqs = self.freqs\n\n        if not self.padding:\n            padding = self.mapRectFromDevice(QRectF(0, 0, 0.5, 0)).width()\n        else:\n            padding = min(20, self.width * self.padding)\n        sx = self.x + padding\n        padded_width = self.width - 2 * padding\n\n        if self.stacked:\n            painter.setPen(Qt.NoPen)\n            y = 0\n            for freq, color in zip(freqs, self.colors):\n                painter.setBrush(QBrush(color))\n                painter.drawRect(QRectF(sx, y, padded_width, freq))\n                y += freq\n            self.polygon = QPolygonF(QRectF(sx, 0, padded_width, y))\n        else:\n            polypoints = [QPointF(sx, 0)]\n            pen = QPen(QBrush(Qt.white), 0.5)\n            pen.setCosmetic(True)\n            painter.setPen(pen)\n            wsingle = padded_width / len(self.freqs)\n            for i, freq, color in zip(count(), freqs, self.colors):\n                painter.setBrush(QBrush(color))\n                x = sx + wsingle * i\n                painter.drawRect(\n                    QRectF(x, 0, wsingle, freq))\n                polypoints += [QPointF(x, freq),\n                               QPointF(x + wsingle, freq)]\n            polypoints += [QPointF(polypoints[-1].x(), 0), QPointF(sx, 0)]\n            self.polygon = QPolygonF(polypoints)\n\n        if self.hovered:\n            pen = QPen(QBrush(Qt.blue), 2, Qt.DashLine)\n            pen.setCosmetic(True)\n            painter.setPen(pen)\n            painter.setBrush(Qt.NoBrush)\n            painter.drawPolygon(self.polygon)\n\n    @property\n    def x0(self):\n        return self.x\n\n    @property\n    def x1(self):\n        return self.x + self.width\n\n    def boundingRect(self):\n        if self.expanded:\n            height = 1\n        elif self.stacked:\n            height = sum(self.freqs)\n        else:\n            height = max(self.freqs)\n        return QRectF(self.x, 0, self.width, height)\n\n\nclass DistributionWidget(pg.PlotWidget):\n    item_clicked = Signal(DistributionBarItem, Qt.KeyboardModifiers, bool)\n    blank_clicked = Signal()\n    mouse_released = Signal()\n\n    def __init__(self, *args, **kwargs):\n        super().__init__(*args, **kwargs)\n        self.last_item = None\n\n    def _get_bar_item(self, pos):\n        for item in self.items(pos):\n            if isinstance(item, DistributionBarItem):\n                return item\n        return None\n\n    def mousePressEvent(self, ev):\n        super().mousePressEvent(ev)\n        if ev.isAccepted():\n            return\n        if ev.button() != Qt.LeftButton:\n            ev.ignore()\n            return\n\n        ev.accept()\n        self.last_item = self._get_bar_item(ev.pos())\n        if self.last_item:\n            self.item_clicked.emit(self.last_item, ev.modifiers(), False)\n        else:\n            self.blank_clicked.emit()\n\n    def mouseReleaseEvent(self, ev):\n        self.last_item = None\n        self.mouse_released.emit()\n\n    def mouseMoveEvent(self, ev):\n        super().mouseMoveEvent(ev)\n        if self.last_item is not None:\n            item = self._get_bar_item(ev.pos())\n            if item is not None and item is not self.last_item:\n                self.item_clicked.emit(item, ev.modifiers(), True)\n                self.last_item = item\n\n\nclass OWDistributions(OWWidget):\n    name = \"Distributions\"\n    description = \"Display value distributions of a data feature in a graph.\"\n    icon = \"icons/Distribution.svg\"\n    priority = 120\n    keywords = []\n\n    class Inputs:\n        data = Input(\"Data\", Table, doc=\"Set the input dataset\")\n\n    class Outputs:\n        selected_data = Output(\"Selected Data\", Table, default=True)\n        annotated_data = Output(ANNOTATED_DATA_SIGNAL_NAME, Table)\n        histogram_data = Output(\"Histogram Data\", Table)\n\n    class Error(OWWidget.Error):\n        no_defined_values_var = \\\n            Msg(\"Variable '{}' does not have any defined values\")\n        no_defined_values_pair = \\\n            Msg(\"No data instances with '{}' and '{}' defined\")\n\n    class Warning(OWWidget.Warning):\n        ignored_nans = Msg(\"Data instances with missing values are ignored\")\n\n    settingsHandler = settings.DomainContextHandler()\n    var = settings.ContextSetting(None)\n    cvar = settings.ContextSetting(None)\n    selection = settings.ContextSetting(set(), schema_only=True)\n    # number_of_bins must be a context setting because selection depends on it\n    number_of_bins = settings.ContextSetting(5, schema_only=True)\n\n    fitted_distribution = settings.Setting(0)\n    show_probs = settings.Setting(False)\n    stacked_columns = settings.Setting(False)\n    cumulative_distr = settings.Setting(False)\n\n    auto_apply = settings.Setting(True)\n\n    graph_name = \"plot\"\n\n    Fitters = (\n        (\"None\", None, (), ()),\n        (\"Normal\", norm, (\"loc\", \"scale\"), (\"μ\", \"σ²\")),\n        (\"Beta\", beta, (\"a\", \"b\", \"loc\", \"scale\"),\n         (\"α\", \"β\", \"-loc\", \"-scale\")),\n        (\"Gamma\", gamma, (\"a\", \"loc\", \"scale\"), (\"α\", \"β\", \"-loc\", \"-scale\")),\n        (\"Rayleigh\", rayleigh, (\"loc\", \"scale\"), (\"-loc\", \"σ²\")),\n        (\"Pareto\", pareto, (\"b\", \"loc\", \"scale\"), (\"α\", \"-loc\", \"-scale\")),\n        (\"Exponential\", expon, (\"loc\", \"scale\"), (\"-loc\", \"λ\")),\n    )\n\n    DragNone, DragAdd, DragRemove = range(3)\n\n    def __init__(self):\n        super().__init__()\n        self.data = None\n        self.valid_data = self.valid_group_data = None\n        self.bar_items = []\n        self.curve_descriptions = None\n        self.binnings = []\n\n        self.last_click_idx = None\n        self.drag_operation = self.DragNone\n        self.key_operation = None\n        self._user_var_bins = {}\n\n        gui.listView(\n            self.controlArea, self, \"var\", box=\"Variable\",\n            model=DomainModel(valid_types=DomainModel.PRIMITIVE,\n                              separators=False),\n            callback=self._on_var_changed)\n\n        box = self.continuous_box = gui.vBox(self.controlArea, \"Distribution\")\n        slider = gui.hSlider(\n            box, self, \"number_of_bins\",\n            label=\"Bin width\", orientation=Qt.Horizontal,\n            minValue=0, maxValue=max(1, len(self.binnings) - 1),\n            createLabel=False, callback=self._on_bins_changed)\n        self.bin_width_label = gui.widgetLabel(slider.box)\n        self.bin_width_label.setFixedWidth(35)\n        self.bin_width_label.setAlignment(Qt.AlignRight)\n        slider.sliderReleased.connect(self._on_bin_slider_released)\n        gui.comboBox(\n            box, self, \"fitted_distribution\", label=\"Fitted distribution\",\n            orientation=Qt.Horizontal, items=(name[0] for name in self.Fitters),\n            callback=self.replot)\n        gui.checkBox(\n            box, self, \"cumulative_distr\", \"Show cumulative distribution\",\n            callback=self.replot)\n\n        box = gui.vBox(self.controlArea, \"Columns\")\n        gui.comboBox(\n            box, self, \"cvar\", label=\"Split by\", orientation=Qt.Horizontal,\n            model=DomainModel(placeholder=\"(None)\",\n                              valid_types=(DiscreteVariable), ),\n            callback=self._on_cvar_changed, contentsLength=18)\n        box2 = gui.indentedBox(box, sep=12)\n        gui.checkBox(\n            box2, self, \"stacked_columns\", \"Stack columns\",\n            callback=self.replot)\n        gui.checkBox(\n            box2, self, \"show_probs\", \"Show probabilities\",\n            callback=self._on_show_probabilities_changed)\n\n        gui.auto_commit(\n            self.controlArea, self, \"auto_apply\", \"&Apply\", commit=self.apply)\n\n        self._setup_plots()\n        self._setup_legend()\n\n    def _setup_plots(self):\n        def add_new_plot(zvalue):\n            plot = pg.ViewBox(enableMouse=False, enableMenu=False)\n            self.ploti.scene().addItem(plot)\n            pg.AxisItem(\"right\").linkToView(plot)\n            plot.setXLink(self.ploti)\n            plot.setZValue(zvalue)\n            return plot\n\n        self.plotview = DistributionWidget(background=None)\n        self.plotview.item_clicked.connect(self._on_item_clicked)\n        self.plotview.blank_clicked.connect(self._on_blank_clicked)\n        self.plotview.mouse_released.connect(self._on_end_selecting)\n        self.plotview.setRenderHint(QPainter.Antialiasing)\n        self.mainArea.layout().addWidget(self.plotview)\n        self.ploti = pg.PlotItem(\n            enableMenu=False, enableMouse=False,\n            axisItems={\"bottom\": ElidedLabelsAxis(\"bottom\")})\n        self.plot = self.ploti.vb\n        self.plot.setMouseEnabled(False, False)\n        self.ploti.hideButtons()\n        self.plotview.setCentralItem(self.ploti)\n\n        self.plot_pdf = add_new_plot(10)\n        self.plot_mark = add_new_plot(-10)\n        self.plot_mark.setYRange(0, 1)\n        self.ploti.vb.sigResized.connect(self.update_views)\n        self.update_views()\n\n        pen = QPen(self.palette().color(QPalette.Text))\n        self.ploti.getAxis(\"bottom\").setPen(pen)\n        left = self.ploti.getAxis(\"left\")\n        left.setPen(pen)\n        left.setStyle(stopAxisAtTick=(True, True))\n\n    def _setup_legend(self):\n        self._legend = LegendItem()\n        self._legend.setParentItem(self.plot)\n        self._legend.hide()\n        self._legend.anchor((1, 0), (1, 0))\n\n    # -----------------------------\n    # Event and signal handlers\n\n    def update_views(self):\n        for plot in (self.plot_pdf, self.plot_mark):\n            plot.setGeometry(self.plot.sceneBoundingRect())\n            plot.linkedViewChanged(self.plot, plot.XAxis)\n\n    def onDeleteWidget(self):\n        self.plot.clear()\n        self.plot_pdf.clear()\n        self.plot_mark.clear()\n        super().onDeleteWidget()\n\n    @Inputs.data\n    def set_data(self, data):\n        self.closeContext()\n        self.var = self.cvar = None\n        self.data = data\n        domain = self.data.domain if self.data else None\n        varmodel = self.controls.var.model()\n        cvarmodel = self.controls.cvar.model()\n        varmodel.set_domain(domain)\n        cvarmodel.set_domain(domain)\n        if varmodel:\n            self.var = varmodel[min(len(domain.class_vars), len(varmodel) - 1)]\n        if domain is not None and domain.has_discrete_class:\n            self.cvar = domain.class_var\n        self.reset_select()\n        self._user_var_bins.clear()\n        self.openContext(domain)\n        self.set_valid_data()\n        self.recompute_binnings()\n        self.replot()\n        self.apply()\n\n    def _on_var_changed(self):\n        self.reset_select()\n        self.set_valid_data()\n        self.recompute_binnings()\n        self.replot()\n        self.apply()\n\n    def _on_cvar_changed(self):\n        self.set_valid_data()\n        self.replot()\n        self.apply()\n\n    def _on_bins_changed(self):\n        self.reset_select()\n        self._set_bin_width_slider_label()\n        self.replot()\n        # this is triggered when dragging, so don't call apply here;\n        # apply is called on sliderReleased\n\n    def _on_bin_slider_released(self):\n        self._user_var_bins[self.var] = self.number_of_bins\n        self.apply()\n\n    def _set_bin_width_slider_label(self):\n        text = \"\"\n        if self.number_of_bins < len(self.binnings):\n            bins = self.binnings[self.number_of_bins]\n            if len(bins) > 1:\n                text = self.var.repr_val(bins[1] - bins[0])\n        self.bin_width_label.setText(text)\n\n    def _on_show_probabilities_changed(self):\n        label = self.controls.fitted_distribution.label\n        if self.show_probs:\n            label.setText(\"Fitted probability\")\n            label.setToolTip(\n                \"Chosen distribution is used to compute Bayesian probabilities\")\n        else:\n            label.setText(\"Fitted distribution\")\n            label.setToolTip(\"\")\n        self.replot()\n\n    @property\n    def is_valid(self):\n        return self.valid_data is not None\n\n    def set_valid_data(self):\n        err_def_var = self.Error.no_defined_values_var\n        err_def_pair = self.Error.no_defined_values_pair\n        err_def_var.clear()\n        err_def_pair.clear()\n        self.Warning.ignored_nans.clear()\n\n        self.valid_data = self.valid_group_data = None\n        if self.var is None:\n            return\n\n        column = self.data.get_column_view(self.var)[0].astype(float)\n        valid_mask = np.isfinite(column)\n        if not np.any(valid_mask):\n            self.Error.no_defined_values_var(self.var.name)\n            return\n        if self.cvar:\n            ccolumn = self.data.get_column_view(self.cvar)[0].astype(float)\n            valid_mask *= np.isfinite(ccolumn)\n            if not np.any(valid_mask):\n                self.Error.no_defined_values_pair(self.var.name, self.cvar.name)\n                return\n            self.valid_group_data = ccolumn[valid_mask]\n        if not np.all(valid_mask):\n            self.Warning.ignored_nans()\n        self.valid_data = column[valid_mask]\n\n    # -----------------------------\n    # Plotting\n\n    def replot(self):\n        self._clear_plot()\n        if self.is_valid:\n            self._set_axis_names()\n            self._update_controls_state()\n            self._call_plotting()\n            self._display_legend()\n        self.show_selection()\n\n    def _clear_plot(self):\n        self.plot.clear()\n        self.plot_pdf.clear()\n        self.plot_mark.clear()\n        self.bar_items = []\n        self._legend.clear()\n        self._legend.hide()\n\n    def _set_axis_names(self):\n        assert self.is_valid  # called only from replot, so assumes data is OK\n        bottomaxis = self.ploti.getAxis(\"bottom\")\n        bottomaxis.setLabel(self.var and self.var.name)\n\n        leftaxis = self.ploti.getAxis(\"left\")\n        if self.show_probs and self.cvar:\n            leftaxis.setLabel(\n                f\"Probability of '{self.cvar.name}' at given '{self.var.name}'\")\n        else:\n            leftaxis.setLabel(\"Frequency\")\n        leftaxis.resizeEvent()\n\n    def _update_controls_state(self):\n        assert self.is_valid  # called only from replot, so assumes data is OK\n        self.continuous_box.setDisabled(self.var.is_discrete)\n        self.controls.show_probs.setDisabled(self.cvar is None)\n        self.controls.stacked_columns.setDisabled(self.cvar is None)\n\n    def _call_plotting(self):\n        assert self.is_valid  # called only from replot, so assumes data is OK\n        self.curve_descriptions = None\n        if self.var.is_discrete:\n            if self.cvar:\n                self._disc_split_plot()\n            else:\n                self._disc_plot()\n        else:\n            if self.cvar:\n                self._cont_split_plot()\n            else:\n                self._cont_plot()\n        self.plot.autoRange()\n\n    def _add_bar(self, x, width, padding, freqs, colors, stacked, expanded,\n                 tooltip):\n        item = DistributionBarItem(\n            x, width, padding, freqs, colors, stacked, expanded, tooltip)\n        self.plot.addItem(item)\n        self.bar_items.append(item)\n\n    def _disc_plot(self):\n        var = self.var\n        self.ploti.getAxis(\"bottom\").setTicks([list(enumerate(var.values))])\n        colors = [QColor(0, 128, 255)]\n        dist = distribution.get_distribution(self.data, self.var)\n        for i, freq in enumerate(dist):\n            tooltip = \\\n                \"<p style='white-space:pre;'>\" \\\n                f\"<b>{escape(var.values[i])}</b>: {int(freq)} \" \\\n                f\"({100 * freq / len(self.valid_data):.2f} %) \"\n            self._add_bar(\n                i - 0.5, 1, 0.1, [freq], colors,\n                stacked=False, expanded=False, tooltip=tooltip)\n\n    def _disc_split_plot(self):\n        var = self.var\n        self.ploti.getAxis(\"bottom\").setTicks([list(enumerate(var.values))])\n        gcolors = [QColor(*col) for col in self.cvar.colors]\n        gvalues = self.cvar.values\n        conts = contingency.get_contingency(self.data, self.cvar, self.var)\n        total = len(self.data)\n        for i, freqs in enumerate(conts):\n            self._add_bar(\n                i - 0.5, 1, 0.1, freqs, gcolors,\n                stacked=self.stacked_columns, expanded=self.show_probs,\n                tooltip=self._split_tooltip(\n                    var.values[i], np.sum(freqs), total, gvalues, freqs))\n\n    def _cont_plot(self):\n        self.ploti.getAxis(\"bottom\").setTicks(None)\n        data = self.valid_data\n        y, x = np.histogram(data, bins=self.binnings[self.number_of_bins])\n        total = len(data)\n        colors = [QColor(0, 128, 255)]\n        if self.fitted_distribution:\n            colors[0] = colors[0].lighter(130)\n\n        tot_freq = 0\n        lasti = len(y) - 1\n        for i, (x0, x1), freq in zip(count(), zip(x, x[1:]), y):\n            tot_freq += freq\n            tooltip = \\\n                \"<p style='white-space:pre;'>\" \\\n                f\"<b>{escape(self.str_int(x0, x1, not i, i == lasti))}</b>: \" \\\n                f\"{freq} ({100 * freq / total:.2f} %)</p>\"\n            self._add_bar(\n                x0, x1 - x0, 0, [tot_freq if self.cumulative_distr else freq],\n                colors, stacked=False, expanded=False, tooltip=tooltip)\n\n        if self.fitted_distribution:\n            self._plot_approximations(\n                x[0], x[-1], [self._fit_approximation(data)],\n                [QColor(0, 0, 0)], (1,))\n\n    def _cont_split_plot(self):\n        self.ploti.getAxis(\"bottom\").setTicks(None)\n        data = self.valid_data\n        _, bins = np.histogram(data, bins=self.binnings[self.number_of_bins])\n        gvalues = self.cvar.values\n        varcolors = [QColor(*col) for col in self.cvar.colors]\n        if self.fitted_distribution:\n            gcolors = [c.lighter(130) for c in varcolors]\n        else:\n            gcolors = varcolors\n        nvalues = len(gvalues)\n        ys = []\n        fitters = []\n        prior_sizes = []\n        for val_idx in range(nvalues):\n            group_data = data[self.valid_group_data == val_idx]\n            prior_sizes.append(len(group_data))\n            ys.append(np.histogram(group_data, bins)[0])\n            if self.fitted_distribution:\n                fitters.append(self._fit_approximation(group_data))\n        total = len(data)\n        prior_sizes = np.array(prior_sizes)\n        tot_freqs = np.zeros(len(ys))\n\n        lasti = len(ys[0]) - 1\n        for i, x0, x1, freqs in zip(count(), bins, bins[1:], zip(*ys)):\n            tot_freqs += freqs\n            plotfreqs = tot_freqs.copy() if self.cumulative_distr else freqs\n            self._add_bar(\n                x0, x1 - x0, 0 if self.stacked_columns else 0.1, plotfreqs,\n                gcolors, stacked=self.stacked_columns, expanded=self.show_probs,\n                tooltip=self._split_tooltip(\n                    self.str_int(x0, x1, not i, i == lasti),\n                    np.sum(plotfreqs), total, gvalues, plotfreqs))\n\n        if fitters:\n            self._plot_approximations(bins[0], bins[-1], fitters, varcolors,\n                                      prior_sizes / len(data))\n\n    def _fit_approximation(self, y):\n        def join_pars(pairs):\n            strv = self.var.str_val\n            return \", \".join(f\"{sname}={strv(val)}\" for sname, val in pairs)\n\n        def str_params():\n            s = join_pars(\n                (sname, val) for sname, val in zip(str_names, fitted)\n                if sname[0] != \"-\")\n            par = join_pars(\n                (sname[1:], val) for sname, val in zip(str_names, fitted)\n                if sname[0] == \"-\")\n            if par:\n                s += f\" ({par})\"\n            return s\n\n        _, dist, names, str_names = self.Fitters[self.fitted_distribution]\n        fitted = dist.fit(y)\n        params = {name: val for name, val in zip(names, fitted)}\n        return partial(dist.pdf, **params), str_params()\n\n    def _plot_approximations(self, x0, x1, fitters, colors, prior_probs=0):\n        x = np.linspace(x0, x1, 100)\n        ys = np.empty((len(fitters), 100))\n        self.curve_descriptions = [s for _, s in fitters]\n        for y, (fitter, _), color in zip(ys, fitters, colors):\n            y[:] = fitter(x)\n            if self.cumulative_distr:\n                y[:] = np.cumsum(y)\n        tots = np.sum(ys, axis=0)\n\n        show_probs = self.show_probs and self.cvar is not None\n        plot = self.ploti if show_probs else self.plot_pdf\n\n        for y, prior_prob, color in zip(ys, prior_probs, colors):\n            if show_probs:\n                y_p = y * prior_prob\n                y = y_p / (y_p + (tots - y) * (1 - prior_prob))\n            plot.addItem(pg.PlotCurveItem(\n                x=x, y=y,\n                pen=pg.mkPen(width=5, color=color),\n                shadowPen=pg.mkPen(width=8, color=color.darker(120))))\n        if not show_probs:\n            self.plot_pdf.autoRange()\n\n    @staticmethod\n    def _split_tooltip(valname, tot_group, total, gvalues, freqs):\n        div_group = tot_group or 1\n        cs = \"white-space:pre; text-align: right;\"\n        s = f\"style='{cs} padding-left: 1em'\"\n        snp = f\"style='{cs}'\"\n        return f\"<table style='border-collapse: collapse'>\" \\\n               f\"<tr><th {s}>{escape(valname)}:</th>\" \\\n               f\"<td {snp}><b>{int(tot_group)}</b></td>\" \\\n               \"<td/>\" \\\n               f\"<td {s}><b>{100 * tot_group / total:.2f} %</b></td></tr>\" + \\\n               f\"<tr><td/><td/><td {s}>(in group)</td><td {s}>(overall)</td>\" \\\n               \"</tr>\" + \\\n               \"\".join(\n                   \"<tr>\"\n                   f\"<th {s}>{value}:</th>\"\n                   f\"<td {snp}><b>{int(freq)}</b></td>\"\n                   f\"<td {s}>{100 * freq / div_group:.2f} %</td>\"\n                   f\"<td {s}>{100 * freq / total:.2f} %</td>\"\n                   \"</tr>\"\n                   for value, freq in zip(gvalues, freqs)) + \\\n               \"</table>\"\n\n    def _display_legend(self):\n        assert self.is_valid  # called only from replot, so assumes data is OK\n        if self.cvar is None:\n            if not self.curve_descriptions:\n                self._legend.hide()\n                return\n            self._legend.addItem(\n                pg.PlotCurveItem(pen=pg.mkPen(width=5, color=0.0)),\n                self.curve_descriptions[0])\n        else:\n            cvar_values = self.cvar.values\n            colors = [QColor(*col) for col in self.cvar.colors]\n            descriptions = self.curve_descriptions or repeat(None)\n            for color, name, desc in zip(colors, cvar_values, descriptions):\n                self._legend.addItem(\n                    ScatterPlotItem(pen=color, brush=color, size=10, shape=\"s\"),\n                    escape(name + (f\" ({desc})\" if desc else \"\")))\n        self._legend.show()\n\n    # -----------------------------\n    # Bins\n\n    def recompute_binnings(self):\n        self.binnings = []\n        max_bins = 0\n        if self.is_valid and self.var.is_continuous:\n            # binning is computed on valid var data, ignoring any cvar nans\n            column = self.data.get_column_view(self.var)[0].astype(float)\n            if np.any(np.isfinite(column)):\n                self.binnings = decimal_binnings(\n                    column, min_width=self.min_var_resolution(self.var),\n                    add_unique=10, min_unique=5)\n                max_bins = len(self.binnings) - 1\n\n        self.controls.number_of_bins.setMaximum(max_bins)\n        self.number_of_bins = min(\n            max_bins, self._user_var_bins.get(self.var, self.number_of_bins))\n        self._set_bin_width_slider_label()\n\n    @staticmethod\n    def min_var_resolution(var):\n        # pylint: disable=unidiomatic-typecheck\n        if type(var) is not ContinuousVariable:\n            return 0\n        return 10 ** -var.number_of_decimals\n\n    def str_int(self, x0, x1, first, last):\n        var = self.var\n        sx0, sx1 = var.repr_val(x0), var.repr_val(x1)\n        if self.cumulative_distr:\n            return f\"{var.name} < {sx1}\"\n        elif first and last:\n            return f\"{var.name} = {sx0}\"\n        elif first:\n            return f\"{var.name} < {sx1}\"\n        elif last:\n            return f\"{var.name} ≥ {sx0}\"\n        elif sx0 == sx1 or x1 - x0 <= self.min_var_resolution(var):\n            return f\"{var.name} = {sx0}\"\n        else:\n            return f\"{sx0} ≤ {var.name} < {sx1}\"\n\n    # -----------------------------\n    # Selection\n\n    def _on_item_clicked(self, item, modifiers, drag):\n        def add_or_remove(idx, add):\n            self.drag_operation = [self.DragRemove, self.DragAdd][add]\n            if add:\n                self.selection.add(idx)\n            else:\n                if idx in self.selection:\n                    # This can be False when removing with dragging and the\n                    # mouse crosses unselected items\n                    self.selection.remove(idx)\n\n        def add_range(add):\n            if self.last_click_idx is None:\n                add = True\n                idx_range = {idx}\n            else:\n                from_idx, to_idx = sorted((self.last_click_idx, idx))\n                idx_range = set(range(from_idx, to_idx + 1))\n            self.drag_operation = [self.DragRemove, self.DragAdd][add]\n            if add:\n                self.selection |= idx_range\n            else:\n                self.selection -= idx_range\n\n        self.key_operation = None\n        if item is None:\n            self.reset_select()\n            return\n\n        idx = self.bar_items.index(item)\n        if drag:\n            # Dragging has to add a range, otherwise fast dragging skips bars\n            add_range(self.drag_operation == self.DragAdd)\n        else:\n            if modifiers & Qt.ShiftModifier:\n                add_range(self.drag_operation == self.DragAdd)\n            elif modifiers & Qt.ControlModifier:\n                add_or_remove(idx, add=idx not in self.selection)\n            else:\n                if self.selection == {idx}:\n                    # Clicking on a single selected bar  deselects it,\n                    # but dragging from here will select\n                    add_or_remove(idx, add=False)\n                    self.drag_operation = self.DragAdd\n                else:\n                    self.selection.clear()\n                    add_or_remove(idx, add=True)\n        self.last_click_idx = idx\n\n        self.show_selection()\n\n    def _on_blank_clicked(self):\n        self.reset_select()\n\n    def reset_select(self):\n        self.selection.clear()\n        self.last_click_idx = None\n        self.drag_operation = None\n        self.key_operation = None\n        self.show_selection()\n\n    def _on_end_selecting(self):\n        self.apply()\n\n    def show_selection(self):\n        self.plot_mark.clear()\n        if not self.is_valid:  # though if it's not, selection is empty anyway\n            return\n\n        blue = QColor(Qt.blue)\n        pen = QPen(QBrush(blue), 3)\n        pen.setCosmetic(True)\n        brush = QBrush(blue.lighter(190))\n\n        for group in self.grouped_selection():\n            group = list(group)\n            left_idx, right_idx = group[0], group[-1]\n            left_pad, right_pad = self._determine_padding(left_idx, right_idx)\n            x0 = self.bar_items[left_idx].x0 - left_pad\n            x1 = self.bar_items[right_idx].x1 + right_pad\n            item = QGraphicsRectItem(x0, 0, x1 - x0, 1)\n            item.setPen(pen)\n            item.setBrush(brush)\n            if self.var.is_continuous:\n                valname = self.str_int(\n                    x0, x1, not left_idx, right_idx == len(self.bar_items) - 1)\n                inside = sum(np.sum(self.bar_items[i].freqs) for i in group)\n                total = len(self.valid_data)\n                item.setToolTip(\n                    \"<p style='white-space:pre;'>\"\n                    f\"<b>{escape(valname)}</b>: \"\n                    f\"{inside} ({100 * inside / total:.2f} %)\")\n            self.plot_mark.addItem(item)\n\n    def _determine_padding(self, left_idx, right_idx):\n        def _padding(i):\n            return (self.bar_items[i + 1].x0 - self.bar_items[i].x1) / 2\n\n        if len(self.bar_items) == 1:\n            return 6, 6\n        if left_idx == 0 and right_idx == len(self.bar_items) - 1:\n            return (_padding(0), ) * 2\n\n        if left_idx > 0:\n            left_pad = _padding(left_idx - 1)\n        if right_idx < len(self.bar_items) - 1:\n            right_pad = _padding(right_idx)\n        else:\n            right_pad = left_pad\n        if left_idx == 0:\n            left_pad = right_pad\n        return left_pad, right_pad\n\n    def grouped_selection(self):\n        return [[g[1] for g in group]\n                for _, group in groupby(enumerate(sorted(self.selection)),\n                                        key=lambda x: x[1] - x[0])]\n\n    def keyPressEvent(self, e):\n        def on_nothing_selected():\n            if e.key() == Qt.Key_Left:\n                self.last_click_idx = len(self.bar_items) - 1\n            else:\n                self.last_click_idx = 0\n            self.selection.add(self.last_click_idx)\n\n        def on_key_left():\n            if e.modifiers() & Qt.ShiftModifier:\n                if self.key_operation == Qt.Key_Right and first != last:\n                    self.selection.remove(last)\n                    self.last_click_idx = last - 1\n                elif first:\n                    self.key_operation = Qt.Key_Left\n                    self.selection.add(first - 1)\n                    self.last_click_idx = first - 1\n            else:\n                self.selection.clear()\n                self.last_click_idx = max(first - 1, 0)\n                self.selection.add(self.last_click_idx)\n\n        def on_key_right():\n            if e.modifiers() & Qt.ShiftModifier:\n                if self.key_operation == Qt.Key_Left and first != last:\n                    self.selection.remove(first)\n                    self.last_click_idx = first + 1\n                elif not self._is_last_bar(last):\n                    self.key_operation = Qt.Key_Right\n                    self.selection.add(last + 1)\n                    self.last_click_idx = last + 1\n            else:\n                self.selection.clear()\n                self.last_click_idx = min(last + 1, len(self.bar_items) - 1)\n                self.selection.add(self.last_click_idx)\n\n        if not self.is_valid or not self.bar_items \\\n                or e.key() not in (Qt.Key_Left, Qt.Key_Right):\n            super().keyPressEvent(e)\n            return\n\n        prev_selection = self.selection.copy()\n        if not self.selection:\n            on_nothing_selected()\n        else:\n            first, last = min(self.selection), max(self.selection)\n            if e.key() == Qt.Key_Left:\n                on_key_left()\n            else:\n                on_key_right()\n\n        if self.selection != prev_selection:\n            self.drag_operation = self.DragAdd\n            self.show_selection()\n            self.apply()\n\n    def keyReleaseEvent(self, ev):\n        if ev.key() == Qt.Key_Shift:\n            self.key_operation = None\n        super().keyReleaseEvent(ev)\n\n\n    # -----------------------------\n    # Output\n\n    def apply(self):\n        data = self.data\n        selected_data = annotated_data = histogram_data = None\n        if self.is_valid:\n            if self.var.is_discrete:\n                group_indices, values = self._get_output_indices_disc()\n            else:\n                group_indices, values = self._get_output_indices_cont()\n                hist_indices, hist_values = self._get_histogram_indices()\n                histogram_data = create_groups_table(\n                    data, hist_indices, values=hist_values)\n            selected = np.nonzero(group_indices)[0]\n            if selected.size:\n                selected_data = create_groups_table(\n                    data, group_indices,\n                    include_unselected=False, values=values)\n                annotated_data = create_annotated_table(data, selected)\n\n        self.Outputs.selected_data.send(selected_data)\n        self.Outputs.annotated_data.send(annotated_data)\n        self.Outputs.histogram_data.send(histogram_data)\n\n    def _get_output_indices_disc(self):\n        group_indices = np.zeros(len(self.data), dtype=np.int32)\n        col = self.data.get_column_view(self.var)[0].astype(float)\n        for group_idx, val_idx in enumerate(self.selection, start=1):\n            group_indices[col == val_idx] = group_idx\n        values = [self.var.values[i] for i in self.selection]\n        return group_indices, values\n\n    def _get_output_indices_cont(self):\n        group_indices = np.zeros(len(self.data), dtype=np.int32)\n        col = self.data.get_column_view(self.var)[0].astype(float)\n        values = []\n        for group_idx, group in enumerate(self.grouped_selection(), start=1):\n            x0 = x1 = None\n            for bar_idx in group:\n                minx, maxx, mask = self._get_cont_baritem_indices(col, bar_idx)\n                if x0 is None:\n                    x0 = minx\n                x1 = maxx\n                group_indices[mask] = group_idx\n            # pylint: disable=undefined-loop-variable\n            values.append(\n                self.str_int(x0, x1, not bar_idx, self._is_last_bar(bar_idx)))\n        return group_indices, values\n\n    def _get_histogram_indices(self):\n        group_indices = np.zeros(len(self.data), dtype=np.int32)\n        col = self.data.get_column_view(self.var)[0].astype(float)\n        values = []\n        for bar_idx in range(len(self.bar_items)):\n            x0, x1, mask = self._get_cont_baritem_indices(col, bar_idx)\n            group_indices[mask] = bar_idx + 1\n            values.append(\n                self.str_int(x0, x1, not bar_idx, self._is_last_bar(bar_idx)))\n        return group_indices, values\n\n    def _get_cont_baritem_indices(self, col, bar_idx):\n        bar_item = self.bar_items[bar_idx]\n        minx = bar_item.x0\n        maxx = bar_item.x1 + (bar_idx == len(self.bar_items) - 1)\n        with np.errstate(invalid=\"ignore\"):\n            return minx, maxx, (col >= minx) * (col < maxx)\n\n    def _is_last_bar(self, idx):\n        return idx == len(self.bar_items) - 1\n\n    # -----------------------------\n    # Report\n\n    def get_widget_name_extension(self):\n        return self.var\n\n    def send_report(self):\n        self.plotview.scene().setSceneRect(self.plotview.sceneRect())\n        if not self.is_valid:\n            return\n        self.report_plot()\n        if self.cumulative_distr:\n            text = f\"Cummulative distribution of '{self.var.name}'\"\n        else:\n            text = f\"Distribution of '{self.var.name}'\"\n        if self.cvar:\n            text += f\" with columns split by '{self.cvar.name}'\"\n        self.report_caption(text)\n\n\nif __name__ == \"__main__\":  # pragma: no cover\n    WidgetPreview(OWDistributions).run(Table(\"heart_disease.tab\"))\n",
            "new_file_content": "from functools import partial\nfrom itertools import count, groupby, repeat\nfrom xml.sax.saxutils import escape\n\nimport numpy as np\nfrom scipy.stats import norm, rayleigh, beta, gamma, pareto, expon\n\nfrom AnyQt.QtWidgets import QGraphicsRectItem\nfrom AnyQt.QtGui import QColor, QPen, QBrush, QPainter, QPalette, QPolygonF\nfrom AnyQt.QtCore import Qt, QRectF, QPointF, pyqtSignal as Signal\nimport pyqtgraph as pg\n\nfrom Orange.data import Table, DiscreteVariable, ContinuousVariable\nfrom Orange.preprocess.discretize import decimal_binnings\nfrom Orange.statistics import distribution, contingency\nfrom Orange.widgets import gui, settings\nfrom Orange.widgets.utils.annotated_data import \\\n    create_groups_table, create_annotated_table, ANNOTATED_DATA_SIGNAL_NAME\nfrom Orange.widgets.utils.itemmodels import DomainModel\nfrom Orange.widgets.utils.widgetpreview import WidgetPreview\nfrom Orange.widgets.visualize.utils.plotutils import ElidedLabelsAxis\nfrom Orange.widgets.widget import Input, Output, OWWidget, Msg\n\nfrom Orange.widgets.visualize.owscatterplotgraph import \\\n    LegendItem as SPGLegendItem\n\n\nclass ScatterPlotItem(pg.ScatterPlotItem):\n    Symbols = pg.graphicsItems.ScatterPlotItem.Symbols\n\n    # pylint: disable=arguments-differ\n    def paint(self, painter, option, widget=None):\n        if self.opts[\"pxMode\"]:\n            painter.setRenderHint(QPainter.SmoothPixmapTransform, True)\n        if self.opts[\"antialias\"]:\n            painter.setRenderHint(QPainter.Antialiasing, True)\n        super().paint(painter, option, widget)\n\n\nclass LegendItem(SPGLegendItem):\n    @staticmethod\n    def mousePressEvent(event):\n        if event.button() == Qt.LeftButton:\n            event.accept()\n        else:\n            event.ignore()\n\n    def mouseMoveEvent(self, event):\n        if event.buttons() & Qt.LeftButton:\n            event.accept()\n            if self.parentItem() is not None:\n                self.autoAnchor(\n                    self.pos() + (event.pos() - event.lastPos()) / 2)\n        else:\n            event.ignore()\n\n    @staticmethod\n    def mouseReleaseEvent(event):\n        if event.button() == Qt.LeftButton:\n            event.accept()\n        else:\n            event.ignore()\n\n\nclass DistributionBarItem(pg.GraphicsObject):\n    def __init__(self, x, width, padding, freqs, colors, stacked, expanded,\n                 tooltip):\n        super().__init__()\n        self.x = x\n        self.width = width\n        self.freqs = freqs\n        self.colors = colors\n        self.padding = padding\n        self.stacked = stacked\n        self.expanded = expanded\n        self.__picture = None\n        self.polygon = None\n        self.hovered = False\n        self.setAcceptHoverEvents(True)\n        self.setToolTip(tooltip)\n\n    def hoverEnterEvent(self, event):\n        super().hoverEnterEvent(event)\n        self.hovered = True\n        self.update()\n\n    def hoverLeaveEvent(self, event):\n        super().hoverLeaveEvent(event)\n        self.hovered = False\n        self.update()\n\n    def paint(self, painter, _options, _widget):\n        if self.expanded:\n            tot = np.sum(self.freqs)\n            if tot == 0:\n                return\n            freqs = self.freqs / tot\n        else:\n            freqs = self.freqs\n\n        if not self.padding:\n            padding = self.mapRectFromDevice(QRectF(0, 0, 0.5, 0)).width()\n        else:\n            padding = min(20, self.width * self.padding)\n        sx = self.x + padding\n        padded_width = self.width - 2 * padding\n\n        if self.stacked:\n            painter.setPen(Qt.NoPen)\n            y = 0\n            for freq, color in zip(freqs, self.colors):\n                painter.setBrush(QBrush(color))\n                painter.drawRect(QRectF(sx, y, padded_width, freq))\n                y += freq\n            self.polygon = QPolygonF(QRectF(sx, 0, padded_width, y))\n        else:\n            polypoints = [QPointF(sx, 0)]\n            pen = QPen(QBrush(Qt.white), 0.5)\n            pen.setCosmetic(True)\n            painter.setPen(pen)\n            wsingle = padded_width / len(self.freqs)\n            for i, freq, color in zip(count(), freqs, self.colors):\n                painter.setBrush(QBrush(color))\n                x = sx + wsingle * i\n                painter.drawRect(\n                    QRectF(x, 0, wsingle, freq))\n                polypoints += [QPointF(x, freq),\n                               QPointF(x + wsingle, freq)]\n            polypoints += [QPointF(polypoints[-1].x(), 0), QPointF(sx, 0)]\n            self.polygon = QPolygonF(polypoints)\n\n        if self.hovered:\n            pen = QPen(QBrush(Qt.blue), 2, Qt.DashLine)\n            pen.setCosmetic(True)\n            painter.setPen(pen)\n            painter.setBrush(Qt.NoBrush)\n            painter.drawPolygon(self.polygon)\n\n    @property\n    def x0(self):\n        return self.x\n\n    @property\n    def x1(self):\n        return self.x + self.width\n\n    def boundingRect(self):\n        if self.expanded:\n            height = 1\n        elif self.stacked:\n            height = sum(self.freqs)\n        else:\n            height = max(self.freqs)\n        return QRectF(self.x, 0, self.width, height)\n\n\nclass DistributionWidget(pg.PlotWidget):\n    item_clicked = Signal(DistributionBarItem, Qt.KeyboardModifiers, bool)\n    blank_clicked = Signal()\n    mouse_released = Signal()\n\n    def __init__(self, *args, **kwargs):\n        super().__init__(*args, **kwargs)\n        self.last_item = None\n\n    def _get_bar_item(self, pos):\n        for item in self.items(pos):\n            if isinstance(item, DistributionBarItem):\n                return item\n        return None\n\n    def mousePressEvent(self, ev):\n        super().mousePressEvent(ev)\n        if ev.isAccepted():\n            return\n        if ev.button() != Qt.LeftButton:\n            ev.ignore()\n            return\n\n        ev.accept()\n        self.last_item = self._get_bar_item(ev.pos())\n        if self.last_item:\n            self.item_clicked.emit(self.last_item, ev.modifiers(), False)\n        else:\n            self.blank_clicked.emit()\n\n    def mouseReleaseEvent(self, ev):\n        self.last_item = None\n        self.mouse_released.emit()\n\n    def mouseMoveEvent(self, ev):\n        super().mouseMoveEvent(ev)\n        if self.last_item is not None:\n            item = self._get_bar_item(ev.pos())\n            if item is not None and item is not self.last_item:\n                self.item_clicked.emit(item, ev.modifiers(), True)\n                self.last_item = item\n\n\nclass OWDistributions(OWWidget):\n    name = \"Distributions\"\n    description = \"Display value distributions of a data feature in a graph.\"\n    icon = \"icons/Distribution.svg\"\n    priority = 120\n    keywords = []\n\n    class Inputs:\n        data = Input(\"Data\", Table, doc=\"Set the input dataset\")\n\n    class Outputs:\n        selected_data = Output(\"Selected Data\", Table, default=True)\n        annotated_data = Output(ANNOTATED_DATA_SIGNAL_NAME, Table)\n        histogram_data = Output(\"Histogram Data\", Table)\n\n    class Error(OWWidget.Error):\n        no_defined_values_var = \\\n            Msg(\"Variable '{}' does not have any defined values\")\n        no_defined_values_pair = \\\n            Msg(\"No data instances with '{}' and '{}' defined\")\n\n    class Warning(OWWidget.Warning):\n        ignored_nans = Msg(\"Data instances with missing values are ignored\")\n\n    settingsHandler = settings.DomainContextHandler()\n    var = settings.ContextSetting(None)\n    cvar = settings.ContextSetting(None)\n    selection = settings.ContextSetting(set(), schema_only=True)\n    # number_of_bins must be a context setting because selection depends on it\n    number_of_bins = settings.ContextSetting(5, schema_only=True)\n\n    fitted_distribution = settings.Setting(0)\n    show_probs = settings.Setting(False)\n    stacked_columns = settings.Setting(False)\n    cumulative_distr = settings.Setting(False)\n\n    auto_apply = settings.Setting(True)\n\n    graph_name = \"plot\"\n\n    Fitters = (\n        (\"None\", None, (), ()),\n        (\"Normal\", norm, (\"loc\", \"scale\"), (\"μ\", \"σ²\")),\n        (\"Beta\", beta, (\"a\", \"b\", \"loc\", \"scale\"),\n         (\"α\", \"β\", \"-loc\", \"-scale\")),\n        (\"Gamma\", gamma, (\"a\", \"loc\", \"scale\"), (\"α\", \"β\", \"-loc\", \"-scale\")),\n        (\"Rayleigh\", rayleigh, (\"loc\", \"scale\"), (\"-loc\", \"σ²\")),\n        (\"Pareto\", pareto, (\"b\", \"loc\", \"scale\"), (\"α\", \"-loc\", \"-scale\")),\n        (\"Exponential\", expon, (\"loc\", \"scale\"), (\"-loc\", \"λ\")),\n    )\n\n    DragNone, DragAdd, DragRemove = range(3)\n\n    def __init__(self):\n        super().__init__()\n        self.data = None\n        self.valid_data = self.valid_group_data = None\n        self.bar_items = []\n        self.curve_descriptions = None\n        self.binnings = []\n\n        self.last_click_idx = None\n        self.drag_operation = self.DragNone\n        self.key_operation = None\n        self._user_var_bins = {}\n\n        gui.listView(\n            self.controlArea, self, \"var\", box=\"Variable\",\n            model=DomainModel(valid_types=DomainModel.PRIMITIVE,\n                              separators=False),\n            callback=self._on_var_changed)\n\n        box = self.continuous_box = gui.vBox(self.controlArea, \"Distribution\")\n        slider = gui.hSlider(\n            box, self, \"number_of_bins\",\n            label=\"Bin width\", orientation=Qt.Horizontal,\n            minValue=0, maxValue=max(1, len(self.binnings) - 1),\n            createLabel=False, callback=self._on_bins_changed)\n        self.bin_width_label = gui.widgetLabel(slider.box)\n        self.bin_width_label.setFixedWidth(35)\n        self.bin_width_label.setAlignment(Qt.AlignRight)\n        slider.sliderReleased.connect(self._on_bin_slider_released)\n        gui.comboBox(\n            box, self, \"fitted_distribution\", label=\"Fitted distribution\",\n            orientation=Qt.Horizontal, items=(name[0] for name in self.Fitters),\n            callback=self.replot)\n        gui.checkBox(\n            box, self, \"cumulative_distr\", \"Show cumulative distribution\",\n            callback=self.replot)\n\n        box = gui.vBox(self.controlArea, \"Columns\")\n        gui.comboBox(\n            box, self, \"cvar\", label=\"Split by\", orientation=Qt.Horizontal,\n            model=DomainModel(placeholder=\"(None)\",\n                              valid_types=(DiscreteVariable), ),\n            callback=self._on_cvar_changed, contentsLength=18)\n        box2 = gui.indentedBox(box, sep=12)\n        gui.checkBox(\n            box2, self, \"stacked_columns\", \"Stack columns\",\n            callback=self.replot)\n        gui.checkBox(\n            box2, self, \"show_probs\", \"Show probabilities\",\n            callback=self._on_show_probabilities_changed)\n\n        gui.auto_commit(\n            self.controlArea, self, \"auto_apply\", \"&Apply\", commit=self.apply)\n\n        self._setup_plots()\n        self._setup_legend()\n\n    def _setup_plots(self):\n        def add_new_plot(zvalue):\n            plot = pg.ViewBox(enableMouse=False, enableMenu=False)\n            self.ploti.scene().addItem(plot)\n            pg.AxisItem(\"right\").linkToView(plot)\n            plot.setXLink(self.ploti)\n            plot.setZValue(zvalue)\n            return plot\n\n        self.plotview = DistributionWidget(background=None)\n        self.plotview.item_clicked.connect(self._on_item_clicked)\n        self.plotview.blank_clicked.connect(self._on_blank_clicked)\n        self.plotview.mouse_released.connect(self._on_end_selecting)\n        self.plotview.setRenderHint(QPainter.Antialiasing)\n        self.mainArea.layout().addWidget(self.plotview)\n        self.ploti = pg.PlotItem(\n            enableMenu=False, enableMouse=False,\n            axisItems={\"bottom\": ElidedLabelsAxis(\"bottom\")})\n        self.plot = self.ploti.vb\n        self.plot.setMouseEnabled(False, False)\n        self.ploti.hideButtons()\n        self.plotview.setCentralItem(self.ploti)\n\n        self.plot_pdf = add_new_plot(10)\n        self.plot_mark = add_new_plot(-10)\n        self.plot_mark.setYRange(0, 1)\n        self.ploti.vb.sigResized.connect(self.update_views)\n        self.update_views()\n\n        pen = QPen(self.palette().color(QPalette.Text))\n        self.ploti.getAxis(\"bottom\").setPen(pen)\n        left = self.ploti.getAxis(\"left\")\n        left.setPen(pen)\n        left.setStyle(stopAxisAtTick=(True, True))\n\n    def _setup_legend(self):\n        self._legend = LegendItem()\n        self._legend.setParentItem(self.plot)\n        self._legend.hide()\n        self._legend.anchor((1, 0), (1, 0))\n\n    # -----------------------------\n    # Event and signal handlers\n\n    def update_views(self):\n        for plot in (self.plot_pdf, self.plot_mark):\n            plot.setGeometry(self.plot.sceneBoundingRect())\n            plot.linkedViewChanged(self.plot, plot.XAxis)\n\n    def onDeleteWidget(self):\n        self.plot.clear()\n        self.plot_pdf.clear()\n        self.plot_mark.clear()\n        super().onDeleteWidget()\n\n    @Inputs.data\n    def set_data(self, data):\n        self.closeContext()\n        self.var = self.cvar = None\n        self.data = data\n        domain = self.data.domain if self.data else None\n        varmodel = self.controls.var.model()\n        cvarmodel = self.controls.cvar.model()\n        varmodel.set_domain(domain)\n        cvarmodel.set_domain(domain)\n        if varmodel:\n            self.var = varmodel[min(len(domain.class_vars), len(varmodel) - 1)]\n        if domain is not None and domain.has_discrete_class:\n            self.cvar = domain.class_var\n        self.reset_select()\n        self._user_var_bins.clear()\n        self.openContext(domain)\n        self.set_valid_data()\n        self.recompute_binnings()\n        self.replot()\n        self.apply()\n\n    def _on_var_changed(self):\n        self.reset_select()\n        self.set_valid_data()\n        self.recompute_binnings()\n        self.replot()\n        self.apply()\n\n    def _on_cvar_changed(self):\n        self.set_valid_data()\n        self.replot()\n        self.apply()\n\n    def _on_bins_changed(self):\n        self.reset_select()\n        self._set_bin_width_slider_label()\n        self.replot()\n        # this is triggered when dragging, so don't call apply here;\n        # apply is called on sliderReleased\n\n    def _on_bin_slider_released(self):\n        self._user_var_bins[self.var] = self.number_of_bins\n        self.apply()\n\n    def _set_bin_width_slider_label(self):\n        text = \"\"\n        if self.number_of_bins < len(self.binnings):\n            bins = self.binnings[self.number_of_bins]\n            if len(bins) > 1:\n                text = self.var.repr_val(bins[1] - bins[0])\n        self.bin_width_label.setText(text)\n\n    def _on_show_probabilities_changed(self):\n        label = self.controls.fitted_distribution.label\n        if self.show_probs:\n            label.setText(\"Fitted probability\")\n            label.setToolTip(\n                \"Chosen distribution is used to compute Bayesian probabilities\")\n        else:\n            label.setText(\"Fitted distribution\")\n            label.setToolTip(\"\")\n        self.replot()\n\n    @property\n    def is_valid(self):\n        return self.valid_data is not None\n\n    def set_valid_data(self):\n        err_def_var = self.Error.no_defined_values_var\n        err_def_pair = self.Error.no_defined_values_pair\n        err_def_var.clear()\n        err_def_pair.clear()\n        self.Warning.ignored_nans.clear()\n\n        self.valid_data = self.valid_group_data = None\n        if self.var is None:\n            return\n\n        column = self.data.get_column_view(self.var)[0].astype(float)\n        valid_mask = np.isfinite(column)\n        if not np.any(valid_mask):\n            self.Error.no_defined_values_var(self.var.name)\n            return\n        if self.cvar:\n            ccolumn = self.data.get_column_view(self.cvar)[0].astype(float)\n            valid_mask *= np.isfinite(ccolumn)\n            if not np.any(valid_mask):\n                self.Error.no_defined_values_pair(self.var.name, self.cvar.name)\n                return\n            self.valid_group_data = ccolumn[valid_mask]\n        if not np.all(valid_mask):\n            self.Warning.ignored_nans()\n        self.valid_data = column[valid_mask]\n\n    # -----------------------------\n    # Plotting\n\n    def replot(self):\n        self._clear_plot()\n        if self.is_valid:\n            self._set_axis_names()\n            self._update_controls_state()\n            self._call_plotting()\n            self._display_legend()\n        self.show_selection()\n\n    def _clear_plot(self):\n        self.plot.clear()\n        self.plot_pdf.clear()\n        self.plot_mark.clear()\n        self.bar_items = []\n        self._legend.clear()\n        self._legend.hide()\n\n    def _set_axis_names(self):\n        assert self.is_valid  # called only from replot, so assumes data is OK\n        bottomaxis = self.ploti.getAxis(\"bottom\")\n        bottomaxis.setLabel(self.var and self.var.name)\n\n        leftaxis = self.ploti.getAxis(\"left\")\n        if self.show_probs and self.cvar:\n            leftaxis.setLabel(\n                f\"Probability of '{self.cvar.name}' at given '{self.var.name}'\")\n        else:\n            leftaxis.setLabel(\"Frequency\")\n        leftaxis.resizeEvent()\n\n    def _update_controls_state(self):\n        assert self.is_valid  # called only from replot, so assumes data is OK\n        self.continuous_box.setDisabled(self.var.is_discrete)\n        self.controls.show_probs.setDisabled(self.cvar is None)\n        self.controls.stacked_columns.setDisabled(self.cvar is None)\n\n    def _call_plotting(self):\n        assert self.is_valid  # called only from replot, so assumes data is OK\n        self.curve_descriptions = None\n        if self.var.is_discrete:\n            if self.cvar:\n                self._disc_split_plot()\n            else:\n                self._disc_plot()\n        else:\n            if self.cvar:\n                self._cont_split_plot()\n            else:\n                self._cont_plot()\n        self.plot.autoRange()\n\n    def _add_bar(self, x, width, padding, freqs, colors, stacked, expanded,\n                 tooltip):\n        item = DistributionBarItem(\n            x, width, padding, freqs, colors, stacked, expanded, tooltip)\n        self.plot.addItem(item)\n        self.bar_items.append(item)\n\n    def _disc_plot(self):\n        var = self.var\n        self.ploti.getAxis(\"bottom\").setTicks([list(enumerate(var.values))])\n        colors = [QColor(0, 128, 255)]\n        dist = distribution.get_distribution(self.data, self.var)\n        for i, freq in enumerate(dist):\n            tooltip = \\\n                \"<p style='white-space:pre;'>\" \\\n                f\"<b>{escape(var.values[i])}</b>: {int(freq)} \" \\\n                f\"({100 * freq / len(self.valid_data):.2f} %) \"\n            self._add_bar(\n                i - 0.5, 1, 0.1, [freq], colors,\n                stacked=False, expanded=False, tooltip=tooltip)\n\n    def _disc_split_plot(self):\n        var = self.var\n        self.ploti.getAxis(\"bottom\").setTicks([list(enumerate(var.values))])\n        gcolors = [QColor(*col) for col in self.cvar.colors]\n        gvalues = self.cvar.values\n        conts = contingency.get_contingency(self.data, self.cvar, self.var)\n        total = len(self.data)\n        for i, freqs in enumerate(conts):\n            self._add_bar(\n                i - 0.5, 1, 0.1, freqs, gcolors,\n                stacked=self.stacked_columns, expanded=self.show_probs,\n                tooltip=self._split_tooltip(\n                    var.values[i], np.sum(freqs), total, gvalues, freqs))\n\n    def _cont_plot(self):\n        self.ploti.getAxis(\"bottom\").setTicks(None)\n        data = self.valid_data\n        y, x = np.histogram(data, bins=self.binnings[self.number_of_bins])\n        total = len(data)\n        colors = [QColor(0, 128, 255)]\n        if self.fitted_distribution:\n            colors[0] = colors[0].lighter(130)\n\n        tot_freq = 0\n        lasti = len(y) - 1\n        for i, (x0, x1), freq in zip(count(), zip(x, x[1:]), y):\n            tot_freq += freq\n            tooltip = \\\n                \"<p style='white-space:pre;'>\" \\\n                f\"<b>{escape(self.str_int(x0, x1, not i, i == lasti))}</b>: \" \\\n                f\"{freq} ({100 * freq / total:.2f} %)</p>\"\n            self._add_bar(\n                x0, x1 - x0, 0, [tot_freq if self.cumulative_distr else freq],\n                colors, stacked=False, expanded=False, tooltip=tooltip)\n\n        if self.fitted_distribution:\n            self._plot_approximations(\n                x[0], x[-1], [self._fit_approximation(data)],\n                [QColor(0, 0, 0)], (1,))\n\n    def _cont_split_plot(self):\n        self.ploti.getAxis(\"bottom\").setTicks(None)\n        data = self.valid_data\n        _, bins = np.histogram(data, bins=self.binnings[self.number_of_bins])\n        gvalues = self.cvar.values\n        varcolors = [QColor(*col) for col in self.cvar.colors]\n        if self.fitted_distribution:\n            gcolors = [c.lighter(130) for c in varcolors]\n        else:\n            gcolors = varcolors\n        nvalues = len(gvalues)\n        ys = []\n        fitters = []\n        prior_sizes = []\n        for val_idx in range(nvalues):\n            group_data = data[self.valid_group_data == val_idx]\n            prior_sizes.append(len(group_data))\n            ys.append(np.histogram(group_data, bins)[0])\n            if self.fitted_distribution:\n                fitters.append(self._fit_approximation(group_data))\n        total = len(data)\n        prior_sizes = np.array(prior_sizes)\n        tot_freqs = np.zeros(len(ys))\n\n        lasti = len(ys[0]) - 1\n        for i, x0, x1, freqs in zip(count(), bins, bins[1:], zip(*ys)):\n            tot_freqs += freqs\n            plotfreqs = tot_freqs.copy() if self.cumulative_distr else freqs\n            self._add_bar(\n                x0, x1 - x0, 0 if self.stacked_columns else 0.1, plotfreqs,\n                gcolors, stacked=self.stacked_columns, expanded=self.show_probs,\n                tooltip=self._split_tooltip(\n                    self.str_int(x0, x1, not i, i == lasti),\n                    np.sum(plotfreqs), total, gvalues, plotfreqs))\n\n        if fitters:\n            self._plot_approximations(bins[0], bins[-1], fitters, varcolors,\n                                      prior_sizes / len(data))\n\n    def _fit_approximation(self, y):\n        def join_pars(pairs):\n            strv = self.var.str_val\n            return \", \".join(f\"{sname}={strv(val)}\" for sname, val in pairs)\n\n        def str_params():\n            s = join_pars(\n                (sname, val) for sname, val in zip(str_names, fitted)\n                if sname[0] != \"-\")\n            par = join_pars(\n                (sname[1:], val) for sname, val in zip(str_names, fitted)\n                if sname[0] == \"-\")\n            if par:\n                s += f\" ({par})\"\n            return s\n\n        _, dist, names, str_names = self.Fitters[self.fitted_distribution]\n        fitted = dist.fit(y)\n        params = {name: val for name, val in zip(names, fitted)}\n        return partial(dist.pdf, **params), str_params()\n\n    def _plot_approximations(self, x0, x1, fitters, colors, prior_probs=0):\n        x = np.linspace(x0, x1, 100)\n        ys = np.empty((len(fitters), 100))\n        self.curve_descriptions = [s for _, s in fitters]\n        for y, (fitter, _), color in zip(ys, fitters, colors):\n            y[:] = fitter(x)\n            if self.cumulative_distr:\n                y[:] = np.cumsum(y)\n        tots = np.sum(ys, axis=0)\n\n        show_probs = self.show_probs and self.cvar is not None\n        plot = self.ploti if show_probs else self.plot_pdf\n\n        for y, prior_prob, color in zip(ys, prior_probs, colors):\n            if show_probs:\n                y_p = y * prior_prob\n                y = y_p / (y_p + (tots - y) * (1 - prior_prob))\n            plot.addItem(pg.PlotCurveItem(\n                x=x, y=y,\n                pen=pg.mkPen(width=5, color=color),\n                shadowPen=pg.mkPen(width=8, color=color.darker(120))))\n        if not show_probs:\n            self.plot_pdf.autoRange()\n\n    @staticmethod\n    def _split_tooltip(valname, tot_group, total, gvalues, freqs):\n        div_group = tot_group or 1\n        cs = \"white-space:pre; text-align: right;\"\n        s = f\"style='{cs} padding-left: 1em'\"\n        snp = f\"style='{cs}'\"\n        return f\"<table style='border-collapse: collapse'>\" \\\n               f\"<tr><th {s}>{escape(valname)}:</th>\" \\\n               f\"<td {snp}><b>{int(tot_group)}</b></td>\" \\\n               \"<td/>\" \\\n               f\"<td {s}><b>{100 * tot_group / total:.2f} %</b></td></tr>\" + \\\n               f\"<tr><td/><td/><td {s}>(in group)</td><td {s}>(overall)</td>\" \\\n               \"</tr>\" + \\\n               \"\".join(\n                   \"<tr>\"\n                   f\"<th {s}>{value}:</th>\"\n                   f\"<td {snp}><b>{int(freq)}</b></td>\"\n                   f\"<td {s}>{100 * freq / div_group:.2f} %</td>\"\n                   f\"<td {s}>{100 * freq / total:.2f} %</td>\"\n                   \"</tr>\"\n                   for value, freq in zip(gvalues, freqs)) + \\\n               \"</table>\"\n\n    def _display_legend(self):\n        assert self.is_valid  # called only from replot, so assumes data is OK\n        if self.cvar is None:\n            if not self.curve_descriptions:\n                self._legend.hide()\n                return\n            self._legend.addItem(\n                pg.PlotCurveItem(pen=pg.mkPen(width=5, color=0.0)),\n                self.curve_descriptions[0])\n        else:\n            cvar_values = self.cvar.values\n            colors = [QColor(*col) for col in self.cvar.colors]\n            descriptions = self.curve_descriptions or repeat(None)\n            for color, name, desc in zip(colors, cvar_values, descriptions):\n                self._legend.addItem(\n                    ScatterPlotItem(pen=color, brush=color, size=10, shape=\"s\"),\n                    escape(name + (f\" ({desc})\" if desc else \"\")))\n        self._legend.show()\n\n    # -----------------------------\n    # Bins\n\n    def recompute_binnings(self):\n        self.binnings = []\n        max_bins = 0\n        if self.is_valid and self.var.is_continuous:\n            # binning is computed on valid var data, ignoring any cvar nans\n            column = self.data.get_column_view(self.var)[0].astype(float)\n            if np.any(np.isfinite(column)):\n                self.binnings = decimal_binnings(\n                    column, min_width=self.min_var_resolution(self.var),\n                    add_unique=10, min_unique=5)[::-1]\n                max_bins = len(self.binnings) - 1\n\n        self.controls.number_of_bins.setMaximum(max_bins)\n        self.number_of_bins = min(\n            max_bins, self._user_var_bins.get(self.var, self.number_of_bins))\n        self._set_bin_width_slider_label()\n\n    @staticmethod\n    def min_var_resolution(var):\n        # pylint: disable=unidiomatic-typecheck\n        if type(var) is not ContinuousVariable:\n            return 0\n        return 10 ** -var.number_of_decimals\n\n    def str_int(self, x0, x1, first, last):\n        var = self.var\n        sx0, sx1 = var.repr_val(x0), var.repr_val(x1)\n        if self.cumulative_distr:\n            return f\"{var.name} < {sx1}\"\n        elif first and last:\n            return f\"{var.name} = {sx0}\"\n        elif first:\n            return f\"{var.name} < {sx1}\"\n        elif last:\n            return f\"{var.name} ≥ {sx0}\"\n        elif sx0 == sx1 or x1 - x0 <= self.min_var_resolution(var):\n            return f\"{var.name} = {sx0}\"\n        else:\n            return f\"{sx0} ≤ {var.name} < {sx1}\"\n\n    # -----------------------------\n    # Selection\n\n    def _on_item_clicked(self, item, modifiers, drag):\n        def add_or_remove(idx, add):\n            self.drag_operation = [self.DragRemove, self.DragAdd][add]\n            if add:\n                self.selection.add(idx)\n            else:\n                if idx in self.selection:\n                    # This can be False when removing with dragging and the\n                    # mouse crosses unselected items\n                    self.selection.remove(idx)\n\n        def add_range(add):\n            if self.last_click_idx is None:\n                add = True\n                idx_range = {idx}\n            else:\n                from_idx, to_idx = sorted((self.last_click_idx, idx))\n                idx_range = set(range(from_idx, to_idx + 1))\n            self.drag_operation = [self.DragRemove, self.DragAdd][add]\n            if add:\n                self.selection |= idx_range\n            else:\n                self.selection -= idx_range\n\n        self.key_operation = None\n        if item is None:\n            self.reset_select()\n            return\n\n        idx = self.bar_items.index(item)\n        if drag:\n            # Dragging has to add a range, otherwise fast dragging skips bars\n            add_range(self.drag_operation == self.DragAdd)\n        else:\n            if modifiers & Qt.ShiftModifier:\n                add_range(self.drag_operation == self.DragAdd)\n            elif modifiers & Qt.ControlModifier:\n                add_or_remove(idx, add=idx not in self.selection)\n            else:\n                if self.selection == {idx}:\n                    # Clicking on a single selected bar  deselects it,\n                    # but dragging from here will select\n                    add_or_remove(idx, add=False)\n                    self.drag_operation = self.DragAdd\n                else:\n                    self.selection.clear()\n                    add_or_remove(idx, add=True)\n        self.last_click_idx = idx\n\n        self.show_selection()\n\n    def _on_blank_clicked(self):\n        self.reset_select()\n\n    def reset_select(self):\n        self.selection.clear()\n        self.last_click_idx = None\n        self.drag_operation = None\n        self.key_operation = None\n        self.show_selection()\n\n    def _on_end_selecting(self):\n        self.apply()\n\n    def show_selection(self):\n        self.plot_mark.clear()\n        if not self.is_valid:  # though if it's not, selection is empty anyway\n            return\n\n        blue = QColor(Qt.blue)\n        pen = QPen(QBrush(blue), 3)\n        pen.setCosmetic(True)\n        brush = QBrush(blue.lighter(190))\n\n        for group in self.grouped_selection():\n            group = list(group)\n            left_idx, right_idx = group[0], group[-1]\n            left_pad, right_pad = self._determine_padding(left_idx, right_idx)\n            x0 = self.bar_items[left_idx].x0 - left_pad\n            x1 = self.bar_items[right_idx].x1 + right_pad\n            item = QGraphicsRectItem(x0, 0, x1 - x0, 1)\n            item.setPen(pen)\n            item.setBrush(brush)\n            if self.var.is_continuous:\n                valname = self.str_int(\n                    x0, x1, not left_idx, right_idx == len(self.bar_items) - 1)\n                inside = sum(np.sum(self.bar_items[i].freqs) for i in group)\n                total = len(self.valid_data)\n                item.setToolTip(\n                    \"<p style='white-space:pre;'>\"\n                    f\"<b>{escape(valname)}</b>: \"\n                    f\"{inside} ({100 * inside / total:.2f} %)\")\n            self.plot_mark.addItem(item)\n\n    def _determine_padding(self, left_idx, right_idx):\n        def _padding(i):\n            return (self.bar_items[i + 1].x0 - self.bar_items[i].x1) / 2\n\n        if len(self.bar_items) == 1:\n            return 6, 6\n        if left_idx == 0 and right_idx == len(self.bar_items) - 1:\n            return (_padding(0), ) * 2\n\n        if left_idx > 0:\n            left_pad = _padding(left_idx - 1)\n        if right_idx < len(self.bar_items) - 1:\n            right_pad = _padding(right_idx)\n        else:\n            right_pad = left_pad\n        if left_idx == 0:\n            left_pad = right_pad\n        return left_pad, right_pad\n\n    def grouped_selection(self):\n        return [[g[1] for g in group]\n                for _, group in groupby(enumerate(sorted(self.selection)),\n                                        key=lambda x: x[1] - x[0])]\n\n    def keyPressEvent(self, e):\n        def on_nothing_selected():\n            if e.key() == Qt.Key_Left:\n                self.last_click_idx = len(self.bar_items) - 1\n            else:\n                self.last_click_idx = 0\n            self.selection.add(self.last_click_idx)\n\n        def on_key_left():\n            if e.modifiers() & Qt.ShiftModifier:\n                if self.key_operation == Qt.Key_Right and first != last:\n                    self.selection.remove(last)\n                    self.last_click_idx = last - 1\n                elif first:\n                    self.key_operation = Qt.Key_Left\n                    self.selection.add(first - 1)\n                    self.last_click_idx = first - 1\n            else:\n                self.selection.clear()\n                self.last_click_idx = max(first - 1, 0)\n                self.selection.add(self.last_click_idx)\n\n        def on_key_right():\n            if e.modifiers() & Qt.ShiftModifier:\n                if self.key_operation == Qt.Key_Left and first != last:\n                    self.selection.remove(first)\n                    self.last_click_idx = first + 1\n                elif not self._is_last_bar(last):\n                    self.key_operation = Qt.Key_Right\n                    self.selection.add(last + 1)\n                    self.last_click_idx = last + 1\n            else:\n                self.selection.clear()\n                self.last_click_idx = min(last + 1, len(self.bar_items) - 1)\n                self.selection.add(self.last_click_idx)\n\n        if not self.is_valid or not self.bar_items \\\n                or e.key() not in (Qt.Key_Left, Qt.Key_Right):\n            super().keyPressEvent(e)\n            return\n\n        prev_selection = self.selection.copy()\n        if not self.selection:\n            on_nothing_selected()\n        else:\n            first, last = min(self.selection), max(self.selection)\n            if e.key() == Qt.Key_Left:\n                on_key_left()\n            else:\n                on_key_right()\n\n        if self.selection != prev_selection:\n            self.drag_operation = self.DragAdd\n            self.show_selection()\n            self.apply()\n\n    def keyReleaseEvent(self, ev):\n        if ev.key() == Qt.Key_Shift:\n            self.key_operation = None\n        super().keyReleaseEvent(ev)\n\n\n    # -----------------------------\n    # Output\n\n    def apply(self):\n        data = self.data\n        selected_data = annotated_data = histogram_data = None\n        if self.is_valid:\n            if self.var.is_discrete:\n                group_indices, values = self._get_output_indices_disc()\n            else:\n                group_indices, values = self._get_output_indices_cont()\n                hist_indices, hist_values = self._get_histogram_indices()\n                histogram_data = create_groups_table(\n                    data, hist_indices, values=hist_values)\n            selected = np.nonzero(group_indices)[0]\n            if selected.size:\n                selected_data = create_groups_table(\n                    data, group_indices,\n                    include_unselected=False, values=values)\n                annotated_data = create_annotated_table(data, selected)\n\n        self.Outputs.selected_data.send(selected_data)\n        self.Outputs.annotated_data.send(annotated_data)\n        self.Outputs.histogram_data.send(histogram_data)\n\n    def _get_output_indices_disc(self):\n        group_indices = np.zeros(len(self.data), dtype=np.int32)\n        col = self.data.get_column_view(self.var)[0].astype(float)\n        for group_idx, val_idx in enumerate(self.selection, start=1):\n            group_indices[col == val_idx] = group_idx\n        values = [self.var.values[i] for i in self.selection]\n        return group_indices, values\n\n    def _get_output_indices_cont(self):\n        group_indices = np.zeros(len(self.data), dtype=np.int32)\n        col = self.data.get_column_view(self.var)[0].astype(float)\n        values = []\n        for group_idx, group in enumerate(self.grouped_selection(), start=1):\n            x0 = x1 = None\n            for bar_idx in group:\n                minx, maxx, mask = self._get_cont_baritem_indices(col, bar_idx)\n                if x0 is None:\n                    x0 = minx\n                x1 = maxx\n                group_indices[mask] = group_idx\n            # pylint: disable=undefined-loop-variable\n            values.append(\n                self.str_int(x0, x1, not bar_idx, self._is_last_bar(bar_idx)))\n        return group_indices, values\n\n    def _get_histogram_indices(self):\n        group_indices = np.zeros(len(self.data), dtype=np.int32)\n        col = self.data.get_column_view(self.var)[0].astype(float)\n        values = []\n        for bar_idx in range(len(self.bar_items)):\n            x0, x1, mask = self._get_cont_baritem_indices(col, bar_idx)\n            group_indices[mask] = bar_idx + 1\n            values.append(\n                self.str_int(x0, x1, not bar_idx, self._is_last_bar(bar_idx)))\n        return group_indices, values\n\n    def _get_cont_baritem_indices(self, col, bar_idx):\n        bar_item = self.bar_items[bar_idx]\n        minx = bar_item.x0\n        maxx = bar_item.x1 + (bar_idx == len(self.bar_items) - 1)\n        with np.errstate(invalid=\"ignore\"):\n            return minx, maxx, (col >= minx) * (col < maxx)\n\n    def _is_last_bar(self, idx):\n        return idx == len(self.bar_items) - 1\n\n    # -----------------------------\n    # Report\n\n    def get_widget_name_extension(self):\n        return self.var\n\n    def send_report(self):\n        self.plotview.scene().setSceneRect(self.plotview.sceneRect())\n        if not self.is_valid:\n            return\n        self.report_plot()\n        if self.cumulative_distr:\n            text = f\"Cummulative distribution of '{self.var.name}'\"\n        else:\n            text = f\"Distribution of '{self.var.name}'\"\n        if self.cvar:\n            text += f\" with columns split by '{self.cvar.name}'\"\n        self.report_caption(text)\n\n\nif __name__ == \"__main__\":  # pragma: no cover\n    WidgetPreview(OWDistributions).run(Table(\"heart_disease.tab\"))\n",
            "header": {
                "file": {
                    "path": "Orange/widgets/visualize/owdistributions.py"
                },
                "misc_line": null
            },
            "index_line": {
                "old_commit_hash": "0bac00e0a",
                "new_commit_hash": "820c0ea47",
                "mode": "100644"
            },
            "is_binary_file": false,
            "binary_line": null,
            "minus_file": {
                "path": "a/Orange/widgets/visualize/owdistributions.py"
            },
            "plus_file": {
                "path": "b/Orange/widgets/visualize/owdistributions.py"
            },
            "hunks": [
                {
                    "descriptor": {
                        "old_range": {
                            "start": 710,
                            "length": 7
                        },
                        "new_range": {
                            "start": 710,
                            "length": 7
                        },
                        "section": "class OWDistributions(OWWidget):"
                    },
                    "line_group": {
                        "all_lines": [
                            {
                                "content": "            if np.any(np.isfinite(column)):",
                                "type": "context"
                            },
                            {
                                "content": "                self.binnings = decimal_binnings(",
                                "type": "context"
                            },
                            {
                                "content": "                    column, min_width=self.min_var_resolution(self.var),",
                                "type": "context"
                            },
                            {
                                "content": "                    add_unique=10, min_unique=5)",
                                "type": "deleted"
                            },
                            {
                                "content": "                    add_unique=10, min_unique=5)[::-1]",
                                "type": "added"
                            },
                            {
                                "content": "                max_bins = len(self.binnings) - 1",
                                "type": "context"
                            },
                            {
                                "content": "",
                                "type": "context"
                            },
                            {
                                "content": "        self.controls.number_of_bins.setMaximum(max_bins)",
                                "type": "context"
                            }
                        ]
                    },
                    "modified_entities": [
                        {
                            "file_name": "Orange/widgets/visualize/owdistributions.py",
                            "type": "class",
                            "name": "OWDistributions",
                            "content": "class OWDistributions(OWWidget):\n    name = \"Distributions\"\n    description = \"Display value distributions of a data feature in a graph.\"\n    icon = \"icons/Distribution.svg\"\n    priority = 120\n    keywords = []\n\n    class Inputs:\n        data = Input(\"Data\", Table, doc=\"Set the input dataset\")\n\n    class Outputs:\n        selected_data = Output(\"Selected Data\", Table, default=True)\n        annotated_data = Output(ANNOTATED_DATA_SIGNAL_NAME, Table)\n        histogram_data = Output(\"Histogram Data\", Table)\n\n    class Error(OWWidget.Error):\n        no_defined_values_var = \\\n            Msg(\"Variable '{}' does not have any defined values\")\n        no_defined_values_pair = \\\n            Msg(\"No data instances with '{}' and '{}' defined\")\n\n    class Warning(OWWidget.Warning):\n        ignored_nans = Msg(\"Data instances with missing values are ignored\")\n\n    settingsHandler = settings.DomainContextHandler()\n    var = settings.ContextSetting(None)\n    cvar = settings.ContextSetting(None)\n    selection = settings.ContextSetting(set(), schema_only=True)\n    # number_of_bins must be a context setting because selection depends on it\n    number_of_bins = settings.ContextSetting(5, schema_only=True)\n\n    fitted_distribution = settings.Setting(0)\n    show_probs = settings.Setting(False)\n    stacked_columns = settings.Setting(False)\n    cumulative_distr = settings.Setting(False)\n\n    auto_apply = settings.Setting(True)\n\n    graph_name = \"plot\"\n\n    Fitters = (\n        (\"None\", None, (), ()),\n        (\"Normal\", norm, (\"loc\", \"scale\"), (\"μ\", \"σ²\")),\n        (\"Beta\", beta, (\"a\", \"b\", \"loc\", \"scale\"),\n         (\"α\", \"β\", \"-loc\", \"-scale\")),\n        (\"Gamma\", gamma, (\"a\", \"loc\", \"scale\"), (\"α\", \"β\", \"-loc\", \"-scale\")),\n        (\"Rayleigh\", rayleigh, (\"loc\", \"scale\"), (\"-loc\", \"σ²\")),\n        (\"Pareto\", pareto, (\"b\", \"loc\", \"scale\"), (\"α\", \"-loc\", \"-scale\")),\n        (\"Exponential\", expon, (\"loc\", \"scale\"), (\"-loc\", \"λ\")),\n    )\n\n    DragNone, DragAdd, DragRemove = range(3)\n\n    def __init__(self):\n        super().__init__()\n        self.data = None\n        self.valid_data = self.valid_group_data = None\n        self.bar_items = []\n        self.curve_descriptions = None\n        self.binnings = []\n\n        self.last_click_idx = None\n        self.drag_operation = self.DragNone\n        self.key_operation = None\n        self._user_var_bins = {}\n\n        gui.listView(\n            self.controlArea, self, \"var\", box=\"Variable\",\n            model=DomainModel(valid_types=DomainModel.PRIMITIVE,\n                              separators=False),\n            callback=self._on_var_changed)\n\n        box = self.continuous_box = gui.vBox(self.controlArea, \"Distribution\")\n        slider = gui.hSlider(\n            box, self, \"number_of_bins\",\n            label=\"Bin width\", orientation=Qt.Horizontal,\n            minValue=0, maxValue=max(1, len(self.binnings) - 1),\n            createLabel=False, callback=self._on_bins_changed)\n        self.bin_width_label = gui.widgetLabel(slider.box)\n        self.bin_width_label.setFixedWidth(35)\n        self.bin_width_label.setAlignment(Qt.AlignRight)\n        slider.sliderReleased.connect(self._on_bin_slider_released)\n        gui.comboBox(\n            box, self, \"fitted_distribution\", label=\"Fitted distribution\",\n            orientation=Qt.Horizontal, items=(name[0] for name in self.Fitters),\n            callback=self.replot)\n        gui.checkBox(\n            box, self, \"cumulative_distr\", \"Show cumulative distribution\",\n            callback=self.replot)\n\n        box = gui.vBox(self.controlArea, \"Columns\")\n        gui.comboBox(\n            box, self, \"cvar\", label=\"Split by\", orientation=Qt.Horizontal,\n            model=DomainModel(placeholder=\"(None)\",\n                              valid_types=(DiscreteVariable), ),\n            callback=self._on_cvar_changed, contentsLength=18)\n        box2 = gui.indentedBox(box, sep=12)\n        gui.checkBox(\n            box2, self, \"stacked_columns\", \"Stack columns\",\n            callback=self.replot)\n        gui.checkBox(\n            box2, self, \"show_probs\", \"Show probabilities\",\n            callback=self._on_show_probabilities_changed)\n\n        gui.auto_commit(\n            self.controlArea, self, \"auto_apply\", \"&Apply\", commit=self.apply)\n\n        self._setup_plots()\n        self._setup_legend()\n\n    def _setup_plots(self):\n        def add_new_plot(zvalue):\n            plot = pg.ViewBox(enableMouse=False, enableMenu=False)\n            self.ploti.scene().addItem(plot)\n            pg.AxisItem(\"right\").linkToView(plot)\n            plot.setXLink(self.ploti)\n            plot.setZValue(zvalue)\n            return plot\n\n        self.plotview = DistributionWidget(background=None)\n        self.plotview.item_clicked.connect(self._on_item_clicked)\n        self.plotview.blank_clicked.connect(self._on_blank_clicked)\n        self.plotview.mouse_released.connect(self._on_end_selecting)\n        self.plotview.setRenderHint(QPainter.Antialiasing)\n        self.mainArea.layout().addWidget(self.plotview)\n        self.ploti = pg.PlotItem(\n            enableMenu=False, enableMouse=False,\n            axisItems={\"bottom\": ElidedLabelsAxis(\"bottom\")})\n        self.plot = self.ploti.vb\n        self.plot.setMouseEnabled(False, False)\n        self.ploti.hideButtons()\n        self.plotview.setCentralItem(self.ploti)\n\n        self.plot_pdf = add_new_plot(10)\n        self.plot_mark = add_new_plot(-10)\n        self.plot_mark.setYRange(0, 1)\n        self.ploti.vb.sigResized.connect(self.update_views)\n        self.update_views()\n\n        pen = QPen(self.palette().color(QPalette.Text))\n        self.ploti.getAxis(\"bottom\").setPen(pen)\n        left = self.ploti.getAxis(\"left\")\n        left.setPen(pen)\n        left.setStyle(stopAxisAtTick=(True, True))\n\n    def _setup_legend(self):\n        self._legend = LegendItem()\n        self._legend.setParentItem(self.plot)\n        self._legend.hide()\n        self._legend.anchor((1, 0), (1, 0))\n\n    # -----------------------------\n    # Event and signal handlers\n\n    def update_views(self):\n        for plot in (self.plot_pdf, self.plot_mark):\n            plot.setGeometry(self.plot.sceneBoundingRect())\n            plot.linkedViewChanged(self.plot, plot.XAxis)\n\n    def onDeleteWidget(self):\n        self.plot.clear()\n        self.plot_pdf.clear()\n        self.plot_mark.clear()\n        super().onDeleteWidget()\n\n    @Inputs.data\n    def set_data(self, data):\n        self.closeContext()\n        self.var = self.cvar = None\n        self.data = data\n        domain = self.data.domain if self.data else None\n        varmodel = self.controls.var.model()\n        cvarmodel = self.controls.cvar.model()\n        varmodel.set_domain(domain)\n        cvarmodel.set_domain(domain)\n        if varmodel:\n            self.var = varmodel[min(len(domain.class_vars), len(varmodel) - 1)]\n        if domain is not None and domain.has_discrete_class:\n            self.cvar = domain.class_var\n        self.reset_select()\n        self._user_var_bins.clear()\n        self.openContext(domain)\n        self.set_valid_data()\n        self.recompute_binnings()\n        self.replot()\n        self.apply()\n\n    def _on_var_changed(self):\n        self.reset_select()\n        self.set_valid_data()\n        self.recompute_binnings()\n        self.replot()\n        self.apply()\n\n    def _on_cvar_changed(self):\n        self.set_valid_data()\n        self.replot()\n        self.apply()\n\n    def _on_bins_changed(self):\n        self.reset_select()\n        self._set_bin_width_slider_label()\n        self.replot()\n        # this is triggered when dragging, so don't call apply here;\n        # apply is called on sliderReleased\n\n    def _on_bin_slider_released(self):\n        self._user_var_bins[self.var] = self.number_of_bins\n        self.apply()\n\n    def _set_bin_width_slider_label(self):\n        text = \"\"\n        if self.number_of_bins < len(self.binnings):\n            bins = self.binnings[self.number_of_bins]\n            if len(bins) > 1:\n                text = self.var.repr_val(bins[1] - bins[0])\n        self.bin_width_label.setText(text)\n\n    def _on_show_probabilities_changed(self):\n        label = self.controls.fitted_distribution.label\n        if self.show_probs:\n            label.setText(\"Fitted probability\")\n            label.setToolTip(\n                \"Chosen distribution is used to compute Bayesian probabilities\")\n        else:\n            label.setText(\"Fitted distribution\")\n            label.setToolTip(\"\")\n        self.replot()\n\n    @property\n    def is_valid(self):\n        return self.valid_data is not None\n\n    def set_valid_data(self):\n        err_def_var = self.Error.no_defined_values_var\n        err_def_pair = self.Error.no_defined_values_pair\n        err_def_var.clear()\n        err_def_pair.clear()\n        self.Warning.ignored_nans.clear()\n\n        self.valid_data = self.valid_group_data = None\n        if self.var is None:\n            return\n\n        column = self.data.get_column_view(self.var)[0].astype(float)\n        valid_mask = np.isfinite(column)\n        if not np.any(valid_mask):\n            self.Error.no_defined_values_var(self.var.name)\n            return\n        if self.cvar:\n            ccolumn = self.data.get_column_view(self.cvar)[0].astype(float)\n            valid_mask *= np.isfinite(ccolumn)\n            if not np.any(valid_mask):\n                self.Error.no_defined_values_pair(self.var.name, self.cvar.name)\n                return\n            self.valid_group_data = ccolumn[valid_mask]\n        if not np.all(valid_mask):\n            self.Warning.ignored_nans()\n        self.valid_data = column[valid_mask]\n\n    # -----------------------------\n    # Plotting\n\n    def replot(self):\n        self._clear_plot()\n        if self.is_valid:\n            self._set_axis_names()\n            self._update_controls_state()\n            self._call_plotting()\n            self._display_legend()\n        self.show_selection()\n\n    def _clear_plot(self):\n        self.plot.clear()\n        self.plot_pdf.clear()\n        self.plot_mark.clear()\n        self.bar_items = []\n        self._legend.clear()\n        self._legend.hide()\n\n    def _set_axis_names(self):\n        assert self.is_valid  # called only from replot, so assumes data is OK\n        bottomaxis = self.ploti.getAxis(\"bottom\")\n        bottomaxis.setLabel(self.var and self.var.name)\n\n        leftaxis = self.ploti.getAxis(\"left\")\n        if self.show_probs and self.cvar:\n            leftaxis.setLabel(\n                f\"Probability of '{self.cvar.name}' at given '{self.var.name}'\")\n        else:\n            leftaxis.setLabel(\"Frequency\")\n        leftaxis.resizeEvent()\n\n    def _update_controls_state(self):\n        assert self.is_valid  # called only from replot, so assumes data is OK\n        self.continuous_box.setDisabled(self.var.is_discrete)\n        self.controls.show_probs.setDisabled(self.cvar is None)\n        self.controls.stacked_columns.setDisabled(self.cvar is None)\n\n    def _call_plotting(self):\n        assert self.is_valid  # called only from replot, so assumes data is OK\n        self.curve_descriptions = None\n        if self.var.is_discrete:\n            if self.cvar:\n                self._disc_split_plot()\n            else:\n                self._disc_plot()\n        else:\n            if self.cvar:\n                self._cont_split_plot()\n            else:\n                self._cont_plot()\n        self.plot.autoRange()\n\n    def _add_bar(self, x, width, padding, freqs, colors, stacked, expanded,\n                 tooltip):\n        item = DistributionBarItem(\n            x, width, padding, freqs, colors, stacked, expanded, tooltip)\n        self.plot.addItem(item)\n        self.bar_items.append(item)\n\n    def _disc_plot(self):\n        var = self.var\n        self.ploti.getAxis(\"bottom\").setTicks([list(enumerate(var.values))])\n        colors = [QColor(0, 128, 255)]\n        dist = distribution.get_distribution(self.data, self.var)\n        for i, freq in enumerate(dist):\n            tooltip = \\\n                \"<p style='white-space:pre;'>\" \\\n                f\"<b>{escape(var.values[i])}</b>: {int(freq)} \" \\\n                f\"({100 * freq / len(self.valid_data):.2f} %) \"\n            self._add_bar(\n                i - 0.5, 1, 0.1, [freq], colors,\n                stacked=False, expanded=False, tooltip=tooltip)\n\n    def _disc_split_plot(self):\n        var = self.var\n        self.ploti.getAxis(\"bottom\").setTicks([list(enumerate(var.values))])\n        gcolors = [QColor(*col) for col in self.cvar.colors]\n        gvalues = self.cvar.values\n        conts = contingency.get_contingency(self.data, self.cvar, self.var)\n        total = len(self.data)\n        for i, freqs in enumerate(conts):\n            self._add_bar(\n                i - 0.5, 1, 0.1, freqs, gcolors,\n                stacked=self.stacked_columns, expanded=self.show_probs,\n                tooltip=self._split_tooltip(\n                    var.values[i], np.sum(freqs), total, gvalues, freqs))\n\n    def _cont_plot(self):\n        self.ploti.getAxis(\"bottom\").setTicks(None)\n        data = self.valid_data\n        y, x = np.histogram(data, bins=self.binnings[self.number_of_bins])\n        total = len(data)\n        colors = [QColor(0, 128, 255)]\n        if self.fitted_distribution:\n            colors[0] = colors[0].lighter(130)\n\n        tot_freq = 0\n        lasti = len(y) - 1\n        for i, (x0, x1), freq in zip(count(), zip(x, x[1:]), y):\n            tot_freq += freq\n            tooltip = \\\n                \"<p style='white-space:pre;'>\" \\\n                f\"<b>{escape(self.str_int(x0, x1, not i, i == lasti))}</b>: \" \\\n                f\"{freq} ({100 * freq / total:.2f} %)</p>\"\n            self._add_bar(\n                x0, x1 - x0, 0, [tot_freq if self.cumulative_distr else freq],\n                colors, stacked=False, expanded=False, tooltip=tooltip)\n\n        if self.fitted_distribution:\n            self._plot_approximations(\n                x[0], x[-1], [self._fit_approximation(data)],\n                [QColor(0, 0, 0)], (1,))\n\n    def _cont_split_plot(self):\n        self.ploti.getAxis(\"bottom\").setTicks(None)\n        data = self.valid_data\n        _, bins = np.histogram(data, bins=self.binnings[self.number_of_bins])\n        gvalues = self.cvar.values\n        varcolors = [QColor(*col) for col in self.cvar.colors]\n        if self.fitted_distribution:\n            gcolors = [c.lighter(130) for c in varcolors]\n        else:\n            gcolors = varcolors\n        nvalues = len(gvalues)\n        ys = []\n        fitters = []\n        prior_sizes = []\n        for val_idx in range(nvalues):\n            group_data = data[self.valid_group_data == val_idx]\n            prior_sizes.append(len(group_data))\n            ys.append(np.histogram(group_data, bins)[0])\n            if self.fitted_distribution:\n                fitters.append(self._fit_approximation(group_data))\n        total = len(data)\n        prior_sizes = np.array(prior_sizes)\n        tot_freqs = np.zeros(len(ys))\n\n        lasti = len(ys[0]) - 1\n        for i, x0, x1, freqs in zip(count(), bins, bins[1:], zip(*ys)):\n            tot_freqs += freqs\n            plotfreqs = tot_freqs.copy() if self.cumulative_distr else freqs\n            self._add_bar(\n                x0, x1 - x0, 0 if self.stacked_columns else 0.1, plotfreqs,\n                gcolors, stacked=self.stacked_columns, expanded=self.show_probs,\n                tooltip=self._split_tooltip(\n                    self.str_int(x0, x1, not i, i == lasti),\n                    np.sum(plotfreqs), total, gvalues, plotfreqs))\n\n        if fitters:\n            self._plot_approximations(bins[0], bins[-1], fitters, varcolors,\n                                      prior_sizes / len(data))\n\n    def _fit_approximation(self, y):\n        def join_pars(pairs):\n            strv = self.var.str_val\n            return \", \".join(f\"{sname}={strv(val)}\" for sname, val in pairs)\n\n        def str_params():\n            s = join_pars(\n                (sname, val) for sname, val in zip(str_names, fitted)\n                if sname[0] != \"-\")\n            par = join_pars(\n                (sname[1:], val) for sname, val in zip(str_names, fitted)\n                if sname[0] == \"-\")\n            if par:\n                s += f\" ({par})\"\n            return s\n\n        _, dist, names, str_names = self.Fitters[self.fitted_distribution]\n        fitted = dist.fit(y)\n        params = {name: val for name, val in zip(names, fitted)}\n        return partial(dist.pdf, **params), str_params()\n\n    def _plot_approximations(self, x0, x1, fitters, colors, prior_probs=0):\n        x = np.linspace(x0, x1, 100)\n        ys = np.empty((len(fitters), 100))\n        self.curve_descriptions = [s for _, s in fitters]\n        for y, (fitter, _), color in zip(ys, fitters, colors):\n            y[:] = fitter(x)\n            if self.cumulative_distr:\n                y[:] = np.cumsum(y)\n        tots = np.sum(ys, axis=0)\n\n        show_probs = self.show_probs and self.cvar is not None\n        plot = self.ploti if show_probs else self.plot_pdf\n\n        for y, prior_prob, color in zip(ys, prior_probs, colors):\n            if show_probs:\n                y_p = y * prior_prob\n                y = y_p / (y_p + (tots - y) * (1 - prior_prob))\n            plot.addItem(pg.PlotCurveItem(\n                x=x, y=y,\n                pen=pg.mkPen(width=5, color=color),\n                shadowPen=pg.mkPen(width=8, color=color.darker(120))))\n        if not show_probs:\n            self.plot_pdf.autoRange()\n\n    @staticmethod\n    def _split_tooltip(valname, tot_group, total, gvalues, freqs):\n        div_group = tot_group or 1\n        cs = \"white-space:pre; text-align: right;\"\n        s = f\"style='{cs} padding-left: 1em'\"\n        snp = f\"style='{cs}'\"\n        return f\"<table style='border-collapse: collapse'>\" \\\n               f\"<tr><th {s}>{escape(valname)}:</th>\" \\\n               f\"<td {snp}><b>{int(tot_group)}</b></td>\" \\\n               \"<td/>\" \\\n               f\"<td {s}><b>{100 * tot_group / total:.2f} %</b></td></tr>\" + \\\n               f\"<tr><td/><td/><td {s}>(in group)</td><td {s}>(overall)</td>\" \\\n               \"</tr>\" + \\\n               \"\".join(\n                   \"<tr>\"\n                   f\"<th {s}>{value}:</th>\"\n                   f\"<td {snp}><b>{int(freq)}</b></td>\"\n                   f\"<td {s}>{100 * freq / div_group:.2f} %</td>\"\n                   f\"<td {s}>{100 * freq / total:.2f} %</td>\"\n                   \"</tr>\"\n                   for value, freq in zip(gvalues, freqs)) + \\\n               \"</table>\"\n\n    def _display_legend(self):\n        assert self.is_valid  # called only from replot, so assumes data is OK\n        if self.cvar is None:\n            if not self.curve_descriptions:\n                self._legend.hide()\n                return\n            self._legend.addItem(\n                pg.PlotCurveItem(pen=pg.mkPen(width=5, color=0.0)),\n                self.curve_descriptions[0])\n        else:\n            cvar_values = self.cvar.values\n            colors = [QColor(*col) for col in self.cvar.colors]\n            descriptions = self.curve_descriptions or repeat(None)\n            for color, name, desc in zip(colors, cvar_values, descriptions):\n                self._legend.addItem(\n                    ScatterPlotItem(pen=color, brush=color, size=10, shape=\"s\"),\n                    escape(name + (f\" ({desc})\" if desc else \"\")))\n        self._legend.show()\n\n    # -----------------------------\n    # Bins\n\n    def recompute_binnings(self):\n        self.binnings = []\n        max_bins = 0\n        if self.is_valid and self.var.is_continuous:\n            # binning is computed on valid var data, ignoring any cvar nans\n            column = self.data.get_column_view(self.var)[0].astype(float)\n            if np.any(np.isfinite(column)):\n                self.binnings = decimal_binnings(\n                    column, min_width=self.min_var_resolution(self.var),\n                    add_unique=10, min_unique=5)\n                max_bins = len(self.binnings) - 1\n\n        self.controls.number_of_bins.setMaximum(max_bins)\n        self.number_of_bins = min(\n            max_bins, self._user_var_bins.get(self.var, self.number_of_bins))\n        self._set_bin_width_slider_label()\n\n    @staticmethod\n    def min_var_resolution(var):\n        # pylint: disable=unidiomatic-typecheck\n        if type(var) is not ContinuousVariable:\n            return 0\n        return 10 ** -var.number_of_decimals\n\n    def str_int(self, x0, x1, first, last):\n        var = self.var\n        sx0, sx1 = var.repr_val(x0), var.repr_val(x1)\n        if self.cumulative_distr:\n            return f\"{var.name} < {sx1}\"\n        elif first and last:\n            return f\"{var.name} = {sx0}\"\n        elif first:\n            return f\"{var.name} < {sx1}\"\n        elif last:\n            return f\"{var.name} ≥ {sx0}\"\n        elif sx0 == sx1 or x1 - x0 <= self.min_var_resolution(var):\n            return f\"{var.name} = {sx0}\"\n        else:\n            return f\"{sx0} ≤ {var.name} < {sx1}\"\n\n    # -----------------------------\n    # Selection\n\n    def _on_item_clicked(self, item, modifiers, drag):\n        def add_or_remove(idx, add):\n            self.drag_operation = [self.DragRemove, self.DragAdd][add]\n            if add:\n                self.selection.add(idx)\n            else:\n                if idx in self.selection:\n                    # This can be False when removing with dragging and the\n                    # mouse crosses unselected items\n                    self.selection.remove(idx)\n\n        def add_range(add):\n            if self.last_click_idx is None:\n                add = True\n                idx_range = {idx}\n            else:\n                from_idx, to_idx = sorted((self.last_click_idx, idx))\n                idx_range = set(range(from_idx, to_idx + 1))\n            self.drag_operation = [self.DragRemove, self.DragAdd][add]\n            if add:\n                self.selection |= idx_range\n            else:\n                self.selection -= idx_range\n\n        self.key_operation = None\n        if item is None:\n            self.reset_select()\n            return\n\n        idx = self.bar_items.index(item)\n        if drag:\n            # Dragging has to add a range, otherwise fast dragging skips bars\n            add_range(self.drag_operation == self.DragAdd)\n        else:\n            if modifiers & Qt.ShiftModifier:\n                add_range(self.drag_operation == self.DragAdd)\n            elif modifiers & Qt.ControlModifier:\n                add_or_remove(idx, add=idx not in self.selection)\n            else:\n                if self.selection == {idx}:\n                    # Clicking on a single selected bar  deselects it,\n                    # but dragging from here will select\n                    add_or_remove(idx, add=False)\n                    self.drag_operation = self.DragAdd\n                else:\n                    self.selection.clear()\n                    add_or_remove(idx, add=True)\n        self.last_click_idx = idx\n\n        self.show_selection()\n\n    def _on_blank_clicked(self):\n        self.reset_select()\n\n    def reset_select(self):\n        self.selection.clear()\n        self.last_click_idx = None\n        self.drag_operation = None\n        self.key_operation = None\n        self.show_selection()\n\n    def _on_end_selecting(self):\n        self.apply()\n\n    def show_selection(self):\n        self.plot_mark.clear()\n        if not self.is_valid:  # though if it's not, selection is empty anyway\n            return\n\n        blue = QColor(Qt.blue)\n        pen = QPen(QBrush(blue), 3)\n        pen.setCosmetic(True)\n        brush = QBrush(blue.lighter(190))\n\n        for group in self.grouped_selection():\n            group = list(group)\n            left_idx, right_idx = group[0], group[-1]\n            left_pad, right_pad = self._determine_padding(left_idx, right_idx)\n            x0 = self.bar_items[left_idx].x0 - left_pad\n            x1 = self.bar_items[right_idx].x1 + right_pad\n            item = QGraphicsRectItem(x0, 0, x1 - x0, 1)\n            item.setPen(pen)\n            item.setBrush(brush)\n            if self.var.is_continuous:\n                valname = self.str_int(\n                    x0, x1, not left_idx, right_idx == len(self.bar_items) - 1)\n                inside = sum(np.sum(self.bar_items[i].freqs) for i in group)\n                total = len(self.valid_data)\n                item.setToolTip(\n                    \"<p style='white-space:pre;'>\"\n                    f\"<b>{escape(valname)}</b>: \"\n                    f\"{inside} ({100 * inside / total:.2f} %)\")\n            self.plot_mark.addItem(item)\n\n    def _determine_padding(self, left_idx, right_idx):\n        def _padding(i):\n            return (self.bar_items[i + 1].x0 - self.bar_items[i].x1) / 2\n\n        if len(self.bar_items) == 1:\n            return 6, 6\n        if left_idx == 0 and right_idx == len(self.bar_items) - 1:\n            return (_padding(0), ) * 2\n\n        if left_idx > 0:\n            left_pad = _padding(left_idx - 1)\n        if right_idx < len(self.bar_items) - 1:\n            right_pad = _padding(right_idx)\n        else:\n            right_pad = left_pad\n        if left_idx == 0:\n            left_pad = right_pad\n        return left_pad, right_pad\n\n    def grouped_selection(self):\n        return [[g[1] for g in group]\n                for _, group in groupby(enumerate(sorted(self.selection)),\n                                        key=lambda x: x[1] - x[0])]\n\n    def keyPressEvent(self, e):\n        def on_nothing_selected():\n            if e.key() == Qt.Key_Left:\n                self.last_click_idx = len(self.bar_items) - 1\n            else:\n                self.last_click_idx = 0\n            self.selection.add(self.last_click_idx)\n\n        def on_key_left():\n            if e.modifiers() & Qt.ShiftModifier:\n                if self.key_operation == Qt.Key_Right and first != last:\n                    self.selection.remove(last)\n                    self.last_click_idx = last - 1\n                elif first:\n                    self.key_operation = Qt.Key_Left\n                    self.selection.add(first - 1)\n                    self.last_click_idx = first - 1\n            else:\n                self.selection.clear()\n                self.last_click_idx = max(first - 1, 0)\n                self.selection.add(self.last_click_idx)\n\n        def on_key_right():\n            if e.modifiers() & Qt.ShiftModifier:\n                if self.key_operation == Qt.Key_Left and first != last:\n                    self.selection.remove(first)\n                    self.last_click_idx = first + 1\n                elif not self._is_last_bar(last):\n                    self.key_operation = Qt.Key_Right\n                    self.selection.add(last + 1)\n                    self.last_click_idx = last + 1\n            else:\n                self.selection.clear()\n                self.last_click_idx = min(last + 1, len(self.bar_items) - 1)\n                self.selection.add(self.last_click_idx)\n\n        if not self.is_valid or not self.bar_items \\\n                or e.key() not in (Qt.Key_Left, Qt.Key_Right):\n            super().keyPressEvent(e)\n            return\n\n        prev_selection = self.selection.copy()\n        if not self.selection:\n            on_nothing_selected()\n        else:\n            first, last = min(self.selection), max(self.selection)\n            if e.key() == Qt.Key_Left:\n                on_key_left()\n            else:\n                on_key_right()\n\n        if self.selection != prev_selection:\n            self.drag_operation = self.DragAdd\n            self.show_selection()\n            self.apply()\n\n    def keyReleaseEvent(self, ev):\n        if ev.key() == Qt.Key_Shift:\n            self.key_operation = None\n        super().keyReleaseEvent(ev)\n\n\n    # -----------------------------\n    # Output\n\n    def apply(self):\n        data = self.data\n        selected_data = annotated_data = histogram_data = None\n        if self.is_valid:\n            if self.var.is_discrete:\n                group_indices, values = self._get_output_indices_disc()\n            else:\n                group_indices, values = self._get_output_indices_cont()\n                hist_indices, hist_values = self._get_histogram_indices()\n                histogram_data = create_groups_table(\n                    data, hist_indices, values=hist_values)\n            selected = np.nonzero(group_indices)[0]\n            if selected.size:\n                selected_data = create_groups_table(\n                    data, group_indices,\n                    include_unselected=False, values=values)\n                annotated_data = create_annotated_table(data, selected)\n\n        self.Outputs.selected_data.send(selected_data)\n        self.Outputs.annotated_data.send(annotated_data)\n        self.Outputs.histogram_data.send(histogram_data)\n\n    def _get_output_indices_disc(self):\n        group_indices = np.zeros(len(self.data), dtype=np.int32)\n        col = self.data.get_column_view(self.var)[0].astype(float)\n        for group_idx, val_idx in enumerate(self.selection, start=1):\n            group_indices[col == val_idx] = group_idx\n        values = [self.var.values[i] for i in self.selection]\n        return group_indices, values\n\n    def _get_output_indices_cont(self):\n        group_indices = np.zeros(len(self.data), dtype=np.int32)\n        col = self.data.get_column_view(self.var)[0].astype(float)\n        values = []\n        for group_idx, group in enumerate(self.grouped_selection(), start=1):\n            x0 = x1 = None\n            for bar_idx in group:\n                minx, maxx, mask = self._get_cont_baritem_indices(col, bar_idx)\n                if x0 is None:\n                    x0 = minx\n                x1 = maxx\n                group_indices[mask] = group_idx\n            # pylint: disable=undefined-loop-variable\n            values.append(\n                self.str_int(x0, x1, not bar_idx, self._is_last_bar(bar_idx)))\n        return group_indices, values\n\n    def _get_histogram_indices(self):\n        group_indices = np.zeros(len(self.data), dtype=np.int32)\n        col = self.data.get_column_view(self.var)[0].astype(float)\n        values = []\n        for bar_idx in range(len(self.bar_items)):\n            x0, x1, mask = self._get_cont_baritem_indices(col, bar_idx)\n            group_indices[mask] = bar_idx + 1\n            values.append(\n                self.str_int(x0, x1, not bar_idx, self._is_last_bar(bar_idx)))\n        return group_indices, values\n\n    def _get_cont_baritem_indices(self, col, bar_idx):\n        bar_item = self.bar_items[bar_idx]\n        minx = bar_item.x0\n        maxx = bar_item.x1 + (bar_idx == len(self.bar_items) - 1)\n        with np.errstate(invalid=\"ignore\"):\n            return minx, maxx, (col >= minx) * (col < maxx)\n\n    def _is_last_bar(self, idx):\n        return idx == len(self.bar_items) - 1\n\n    # -----------------------------\n    # Report\n\n    def get_widget_name_extension(self):\n        return self.var\n\n    def send_report(self):\n        self.plotview.scene().setSceneRect(self.plotview.sceneRect())\n        if not self.is_valid:\n            return\n        self.report_plot()\n        if self.cumulative_distr:\n            text = f\"Cummulative distribution of '{self.var.name}'\"\n        else:\n            text = f\"Distribution of '{self.var.name}'\"\n        if self.cvar:\n            text += f\" with columns split by '{self.cvar.name}'\"\n        self.report_caption(text)",
                            "ast_type_str": "ClassDef",
                            "start_lineno": 200,
                            "end_lineno": 1015,
                            "parent": null
                        },
                        {
                            "file_name": "Orange/widgets/visualize/owdistributions.py",
                            "type": "method",
                            "name": "OWDistributions.recompute_binnings",
                            "content": "class OWDistributions(OWWidget):\n    name = \"Distributions\"\n    description = \"Display value distributions of a data feature in a graph.\"\n    icon = \"icons/Distribution.svg\"\n    priority = 120\n    keywords = []\n\n    class Inputs:\n        data = Input(\"Data\", Table, doc=\"Set the input dataset\")\n\n    class Outputs:\n        selected_data = Output(\"Selected Data\", Table, default=True)\n        annotated_data = Output(ANNOTATED_DATA_SIGNAL_NAME, Table)\n        histogram_data = Output(\"Histogram Data\", Table)\n\n    class Error(OWWidget.Error):\n        no_defined_values_var = \\\n            Msg(\"Variable '{}' does not have any defined values\")\n        no_defined_values_pair = \\\n            Msg(\"No data instances with '{}' and '{}' defined\")\n\n    class Warning(OWWidget.Warning):\n        ignored_nans = Msg(\"Data instances with missing values are ignored\")\n\n    settingsHandler = settings.DomainContextHandler()\n    var = settings.ContextSetting(None)\n    cvar = settings.ContextSetting(None)\n    selection = settings.ContextSetting(set(), schema_only=True)\n    # number_of_bins must be a context setting because selection depends on it\n    number_of_bins = settings.ContextSetting(5, schema_only=True)\n\n    fitted_distribution = settings.Setting(0)\n    show_probs = settings.Setting(False)\n    stacked_columns = settings.Setting(False)\n    cumulative_distr = settings.Setting(False)\n\n    auto_apply = settings.Setting(True)\n\n    graph_name = \"plot\"\n\n    Fitters = (\n        (\"None\", None, (), ()),\n        (\"Normal\", norm, (\"loc\", \"scale\"), (\"μ\", \"σ²\")),\n        (\"Beta\", beta, (\"a\", \"b\", \"loc\", \"scale\"),\n         (\"α\", \"β\", \"-loc\", \"-scale\")),\n        (\"Gamma\", gamma, (\"a\", \"loc\", \"scale\"), (\"α\", \"β\", \"-loc\", \"-scale\")),\n        (\"Rayleigh\", rayleigh, (\"loc\", \"scale\"), (\"-loc\", \"σ²\")),\n        (\"Pareto\", pareto, (\"b\", \"loc\", \"scale\"), (\"α\", \"-loc\", \"-scale\")),\n        (\"Exponential\", expon, (\"loc\", \"scale\"), (\"-loc\", \"λ\")),\n    )\n\n    DragNone, DragAdd, DragRemove = range(3)\n\n    def __init__(self):\n        super().__init__()\n        self.data = None\n        self.valid_data = self.valid_group_data = None\n        self.bar_items = []\n        self.curve_descriptions = None\n        self.binnings = []\n\n        self.last_click_idx = None\n        self.drag_operation = self.DragNone\n        self.key_operation = None\n        self._user_var_bins = {}\n\n        gui.listView(\n            self.controlArea, self, \"var\", box=\"Variable\",\n            model=DomainModel(valid_types=DomainModel.PRIMITIVE,\n                              separators=False),\n            callback=self._on_var_changed)\n\n        box = self.continuous_box = gui.vBox(self.controlArea, \"Distribution\")\n        slider = gui.hSlider(\n            box, self, \"number_of_bins\",\n            label=\"Bin width\", orientation=Qt.Horizontal,\n            minValue=0, maxValue=max(1, len(self.binnings) - 1),\n            createLabel=False, callback=self._on_bins_changed)\n        self.bin_width_label = gui.widgetLabel(slider.box)\n        self.bin_width_label.setFixedWidth(35)\n        self.bin_width_label.setAlignment(Qt.AlignRight)\n        slider.sliderReleased.connect(self._on_bin_slider_released)\n        gui.comboBox(\n            box, self, \"fitted_distribution\", label=\"Fitted distribution\",\n            orientation=Qt.Horizontal, items=(name[0] for name in self.Fitters),\n            callback=self.replot)\n        gui.checkBox(\n            box, self, \"cumulative_distr\", \"Show cumulative distribution\",\n            callback=self.replot)\n\n        box = gui.vBox(self.controlArea, \"Columns\")\n        gui.comboBox(\n            box, self, \"cvar\", label=\"Split by\", orientation=Qt.Horizontal,\n            model=DomainModel(placeholder=\"(None)\",\n                              valid_types=(DiscreteVariable), ),\n            callback=self._on_cvar_changed, contentsLength=18)\n        box2 = gui.indentedBox(box, sep=12)\n        gui.checkBox(\n            box2, self, \"stacked_columns\", \"Stack columns\",\n            callback=self.replot)\n        gui.checkBox(\n            box2, self, \"show_probs\", \"Show probabilities\",\n            callback=self._on_show_probabilities_changed)\n\n        gui.auto_commit(\n            self.controlArea, self, \"auto_apply\", \"&Apply\", commit=self.apply)\n\n        self._setup_plots()\n        self._setup_legend()\n\n    def _setup_plots(self):\n        def add_new_plot(zvalue):\n            plot = pg.ViewBox(enableMouse=False, enableMenu=False)\n            self.ploti.scene().addItem(plot)\n            pg.AxisItem(\"right\").linkToView(plot)\n            plot.setXLink(self.ploti)\n            plot.setZValue(zvalue)\n            return plot\n\n        self.plotview = DistributionWidget(background=None)\n        self.plotview.item_clicked.connect(self._on_item_clicked)\n        self.plotview.blank_clicked.connect(self._on_blank_clicked)\n        self.plotview.mouse_released.connect(self._on_end_selecting)\n        self.plotview.setRenderHint(QPainter.Antialiasing)\n        self.mainArea.layout().addWidget(self.plotview)\n        self.ploti = pg.PlotItem(\n            enableMenu=False, enableMouse=False,\n            axisItems={\"bottom\": ElidedLabelsAxis(\"bottom\")})\n        self.plot = self.ploti.vb\n        self.plot.setMouseEnabled(False, False)\n        self.ploti.hideButtons()\n        self.plotview.setCentralItem(self.ploti)\n\n        self.plot_pdf = add_new_plot(10)\n        self.plot_mark = add_new_plot(-10)\n        self.plot_mark.setYRange(0, 1)\n        self.ploti.vb.sigResized.connect(self.update_views)\n        self.update_views()\n\n        pen = QPen(self.palette().color(QPalette.Text))\n        self.ploti.getAxis(\"bottom\").setPen(pen)\n        left = self.ploti.getAxis(\"left\")\n        left.setPen(pen)\n        left.setStyle(stopAxisAtTick=(True, True))\n\n    def _setup_legend(self):\n        self._legend = LegendItem()\n        self._legend.setParentItem(self.plot)\n        self._legend.hide()\n        self._legend.anchor((1, 0), (1, 0))\n\n    # -----------------------------\n    # Event and signal handlers\n\n    def update_views(self):\n        for plot in (self.plot_pdf, self.plot_mark):\n            plot.setGeometry(self.plot.sceneBoundingRect())\n            plot.linkedViewChanged(self.plot, plot.XAxis)\n\n    def onDeleteWidget(self):\n        self.plot.clear()\n        self.plot_pdf.clear()\n        self.plot_mark.clear()\n        super().onDeleteWidget()\n\n    @Inputs.data\n    def set_data(self, data):\n        self.closeContext()\n        self.var = self.cvar = None\n        self.data = data\n        domain = self.data.domain if self.data else None\n        varmodel = self.controls.var.model()\n        cvarmodel = self.controls.cvar.model()\n        varmodel.set_domain(domain)\n        cvarmodel.set_domain(domain)\n        if varmodel:\n            self.var = varmodel[min(len(domain.class_vars), len(varmodel) - 1)]\n        if domain is not None and domain.has_discrete_class:\n            self.cvar = domain.class_var\n        self.reset_select()\n        self._user_var_bins.clear()\n        self.openContext(domain)\n        self.set_valid_data()\n        self.recompute_binnings()\n        self.replot()\n        self.apply()\n\n    def _on_var_changed(self):\n        self.reset_select()\n        self.set_valid_data()\n        self.recompute_binnings()\n        self.replot()\n        self.apply()\n\n    def _on_cvar_changed(self):\n        self.set_valid_data()\n        self.replot()\n        self.apply()\n\n    def _on_bins_changed(self):\n        self.reset_select()\n        self._set_bin_width_slider_label()\n        self.replot()\n        # this is triggered when dragging, so don't call apply here;\n        # apply is called on sliderReleased\n\n    def _on_bin_slider_released(self):\n        self._user_var_bins[self.var] = self.number_of_bins\n        self.apply()\n\n    def _set_bin_width_slider_label(self):\n        text = \"\"\n        if self.number_of_bins < len(self.binnings):\n            bins = self.binnings[self.number_of_bins]\n            if len(bins) > 1:\n                text = self.var.repr_val(bins[1] - bins[0])\n        self.bin_width_label.setText(text)\n\n    def _on_show_probabilities_changed(self):\n        label = self.controls.fitted_distribution.label\n        if self.show_probs:\n            label.setText(\"Fitted probability\")\n            label.setToolTip(\n                \"Chosen distribution is used to compute Bayesian probabilities\")\n        else:\n            label.setText(\"Fitted distribution\")\n            label.setToolTip(\"\")\n        self.replot()\n\n    @property\n    def is_valid(self):\n        return self.valid_data is not None\n\n    def set_valid_data(self):\n        err_def_var = self.Error.no_defined_values_var\n        err_def_pair = self.Error.no_defined_values_pair\n        err_def_var.clear()\n        err_def_pair.clear()\n        self.Warning.ignored_nans.clear()\n\n        self.valid_data = self.valid_group_data = None\n        if self.var is None:\n            return\n\n        column = self.data.get_column_view(self.var)[0].astype(float)\n        valid_mask = np.isfinite(column)\n        if not np.any(valid_mask):\n            self.Error.no_defined_values_var(self.var.name)\n            return\n        if self.cvar:\n            ccolumn = self.data.get_column_view(self.cvar)[0].astype(float)\n            valid_mask *= np.isfinite(ccolumn)\n            if not np.any(valid_mask):\n                self.Error.no_defined_values_pair(self.var.name, self.cvar.name)\n                return\n            self.valid_group_data = ccolumn[valid_mask]\n        if not np.all(valid_mask):\n            self.Warning.ignored_nans()\n        self.valid_data = column[valid_mask]\n\n    # -----------------------------\n    # Plotting\n\n    def replot(self):\n        self._clear_plot()\n        if self.is_valid:\n            self._set_axis_names()\n            self._update_controls_state()\n            self._call_plotting()\n            self._display_legend()\n        self.show_selection()\n\n    def _clear_plot(self):\n        self.plot.clear()\n        self.plot_pdf.clear()\n        self.plot_mark.clear()\n        self.bar_items = []\n        self._legend.clear()\n        self._legend.hide()\n\n    def _set_axis_names(self):\n        assert self.is_valid  # called only from replot, so assumes data is OK\n        bottomaxis = self.ploti.getAxis(\"bottom\")\n        bottomaxis.setLabel(self.var and self.var.name)\n\n        leftaxis = self.ploti.getAxis(\"left\")\n        if self.show_probs and self.cvar:\n            leftaxis.setLabel(\n                f\"Probability of '{self.cvar.name}' at given '{self.var.name}'\")\n        else:\n            leftaxis.setLabel(\"Frequency\")\n        leftaxis.resizeEvent()\n\n    def _update_controls_state(self):\n        assert self.is_valid  # called only from replot, so assumes data is OK\n        self.continuous_box.setDisabled(self.var.is_discrete)\n        self.controls.show_probs.setDisabled(self.cvar is None)\n        self.controls.stacked_columns.setDisabled(self.cvar is None)\n\n    def _call_plotting(self):\n        assert self.is_valid  # called only from replot, so assumes data is OK\n        self.curve_descriptions = None\n        if self.var.is_discrete:\n            if self.cvar:\n                self._disc_split_plot()\n            else:\n                self._disc_plot()\n        else:\n            if self.cvar:\n                self._cont_split_plot()\n            else:\n                self._cont_plot()\n        self.plot.autoRange()\n\n    def _add_bar(self, x, width, padding, freqs, colors, stacked, expanded,\n                 tooltip):\n        item = DistributionBarItem(\n            x, width, padding, freqs, colors, stacked, expanded, tooltip)\n        self.plot.addItem(item)\n        self.bar_items.append(item)\n\n    def _disc_plot(self):\n        var = self.var\n        self.ploti.getAxis(\"bottom\").setTicks([list(enumerate(var.values))])\n        colors = [QColor(0, 128, 255)]\n        dist = distribution.get_distribution(self.data, self.var)\n        for i, freq in enumerate(dist):\n            tooltip = \\\n                \"<p style='white-space:pre;'>\" \\\n                f\"<b>{escape(var.values[i])}</b>: {int(freq)} \" \\\n                f\"({100 * freq / len(self.valid_data):.2f} %) \"\n            self._add_bar(\n                i - 0.5, 1, 0.1, [freq], colors,\n                stacked=False, expanded=False, tooltip=tooltip)\n\n    def _disc_split_plot(self):\n        var = self.var\n        self.ploti.getAxis(\"bottom\").setTicks([list(enumerate(var.values))])\n        gcolors = [QColor(*col) for col in self.cvar.colors]\n        gvalues = self.cvar.values\n        conts = contingency.get_contingency(self.data, self.cvar, self.var)\n        total = len(self.data)\n        for i, freqs in enumerate(conts):\n            self._add_bar(\n                i - 0.5, 1, 0.1, freqs, gcolors,\n                stacked=self.stacked_columns, expanded=self.show_probs,\n                tooltip=self._split_tooltip(\n                    var.values[i], np.sum(freqs), total, gvalues, freqs))\n\n    def _cont_plot(self):\n        self.ploti.getAxis(\"bottom\").setTicks(None)\n        data = self.valid_data\n        y, x = np.histogram(data, bins=self.binnings[self.number_of_bins])\n        total = len(data)\n        colors = [QColor(0, 128, 255)]\n        if self.fitted_distribution:\n            colors[0] = colors[0].lighter(130)\n\n        tot_freq = 0\n        lasti = len(y) - 1\n        for i, (x0, x1), freq in zip(count(), zip(x, x[1:]), y):\n            tot_freq += freq\n            tooltip = \\\n                \"<p style='white-space:pre;'>\" \\\n                f\"<b>{escape(self.str_int(x0, x1, not i, i == lasti))}</b>: \" \\\n                f\"{freq} ({100 * freq / total:.2f} %)</p>\"\n            self._add_bar(\n                x0, x1 - x0, 0, [tot_freq if self.cumulative_distr else freq],\n                colors, stacked=False, expanded=False, tooltip=tooltip)\n\n        if self.fitted_distribution:\n            self._plot_approximations(\n                x[0], x[-1], [self._fit_approximation(data)],\n                [QColor(0, 0, 0)], (1,))\n\n    def _cont_split_plot(self):\n        self.ploti.getAxis(\"bottom\").setTicks(None)\n        data = self.valid_data\n        _, bins = np.histogram(data, bins=self.binnings[self.number_of_bins])\n        gvalues = self.cvar.values\n        varcolors = [QColor(*col) for col in self.cvar.colors]\n        if self.fitted_distribution:\n            gcolors = [c.lighter(130) for c in varcolors]\n        else:\n            gcolors = varcolors\n        nvalues = len(gvalues)\n        ys = []\n        fitters = []\n        prior_sizes = []\n        for val_idx in range(nvalues):\n            group_data = data[self.valid_group_data == val_idx]\n            prior_sizes.append(len(group_data))\n            ys.append(np.histogram(group_data, bins)[0])\n            if self.fitted_distribution:\n                fitters.append(self._fit_approximation(group_data))\n        total = len(data)\n        prior_sizes = np.array(prior_sizes)\n        tot_freqs = np.zeros(len(ys))\n\n        lasti = len(ys[0]) - 1\n        for i, x0, x1, freqs in zip(count(), bins, bins[1:], zip(*ys)):\n            tot_freqs += freqs\n            plotfreqs = tot_freqs.copy() if self.cumulative_distr else freqs\n            self._add_bar(\n                x0, x1 - x0, 0 if self.stacked_columns else 0.1, plotfreqs,\n                gcolors, stacked=self.stacked_columns, expanded=self.show_probs,\n                tooltip=self._split_tooltip(\n                    self.str_int(x0, x1, not i, i == lasti),\n                    np.sum(plotfreqs), total, gvalues, plotfreqs))\n\n        if fitters:\n            self._plot_approximations(bins[0], bins[-1], fitters, varcolors,\n                                      prior_sizes / len(data))\n\n    def _fit_approximation(self, y):\n        def join_pars(pairs):\n            strv = self.var.str_val\n            return \", \".join(f\"{sname}={strv(val)}\" for sname, val in pairs)\n\n        def str_params():\n            s = join_pars(\n                (sname, val) for sname, val in zip(str_names, fitted)\n                if sname[0] != \"-\")\n            par = join_pars(\n                (sname[1:], val) for sname, val in zip(str_names, fitted)\n                if sname[0] == \"-\")\n            if par:\n                s += f\" ({par})\"\n            return s\n\n        _, dist, names, str_names = self.Fitters[self.fitted_distribution]\n        fitted = dist.fit(y)\n        params = {name: val for name, val in zip(names, fitted)}\n        return partial(dist.pdf, **params), str_params()\n\n    def _plot_approximations(self, x0, x1, fitters, colors, prior_probs=0):\n        x = np.linspace(x0, x1, 100)\n        ys = np.empty((len(fitters), 100))\n        self.curve_descriptions = [s for _, s in fitters]\n        for y, (fitter, _), color in zip(ys, fitters, colors):\n            y[:] = fitter(x)\n            if self.cumulative_distr:\n                y[:] = np.cumsum(y)\n        tots = np.sum(ys, axis=0)\n\n        show_probs = self.show_probs and self.cvar is not None\n        plot = self.ploti if show_probs else self.plot_pdf\n\n        for y, prior_prob, color in zip(ys, prior_probs, colors):\n            if show_probs:\n                y_p = y * prior_prob\n                y = y_p / (y_p + (tots - y) * (1 - prior_prob))\n            plot.addItem(pg.PlotCurveItem(\n                x=x, y=y,\n                pen=pg.mkPen(width=5, color=color),\n                shadowPen=pg.mkPen(width=8, color=color.darker(120))))\n        if not show_probs:\n            self.plot_pdf.autoRange()\n\n    @staticmethod\n    def _split_tooltip(valname, tot_group, total, gvalues, freqs):\n        div_group = tot_group or 1\n        cs = \"white-space:pre; text-align: right;\"\n        s = f\"style='{cs} padding-left: 1em'\"\n        snp = f\"style='{cs}'\"\n        return f\"<table style='border-collapse: collapse'>\" \\\n               f\"<tr><th {s}>{escape(valname)}:</th>\" \\\n               f\"<td {snp}><b>{int(tot_group)}</b></td>\" \\\n               \"<td/>\" \\\n               f\"<td {s}><b>{100 * tot_group / total:.2f} %</b></td></tr>\" + \\\n               f\"<tr><td/><td/><td {s}>(in group)</td><td {s}>(overall)</td>\" \\\n               \"</tr>\" + \\\n               \"\".join(\n                   \"<tr>\"\n                   f\"<th {s}>{value}:</th>\"\n                   f\"<td {snp}><b>{int(freq)}</b></td>\"\n                   f\"<td {s}>{100 * freq / div_group:.2f} %</td>\"\n                   f\"<td {s}>{100 * freq / total:.2f} %</td>\"\n                   \"</tr>\"\n                   for value, freq in zip(gvalues, freqs)) + \\\n               \"</table>\"\n\n    def _display_legend(self):\n        assert self.is_valid  # called only from replot, so assumes data is OK\n        if self.cvar is None:\n            if not self.curve_descriptions:\n                self._legend.hide()\n                return\n            self._legend.addItem(\n                pg.PlotCurveItem(pen=pg.mkPen(width=5, color=0.0)),\n                self.curve_descriptions[0])\n        else:\n            cvar_values = self.cvar.values\n            colors = [QColor(*col) for col in self.cvar.colors]\n            descriptions = self.curve_descriptions or repeat(None)\n            for color, name, desc in zip(colors, cvar_values, descriptions):\n                self._legend.addItem(\n                    ScatterPlotItem(pen=color, brush=color, size=10, shape=\"s\"),\n                    escape(name + (f\" ({desc})\" if desc else \"\")))\n        self._legend.show()\n\n    # -----------------------------\n    # Bins\n\n    def recompute_binnings(self):\n        self.binnings = []\n        max_bins = 0\n        if self.is_valid and self.var.is_continuous:\n            # binning is computed on valid var data, ignoring any cvar nans\n            column = self.data.get_column_view(self.var)[0].astype(float)\n            if np.any(np.isfinite(column)):\n                self.binnings = decimal_binnings(\n                    column, min_width=self.min_var_resolution(self.var),\n                    add_unique=10, min_unique=5)\n                max_bins = len(self.binnings) - 1\n\n        self.controls.number_of_bins.setMaximum(max_bins)\n        self.number_of_bins = min(\n            max_bins, self._user_var_bins.get(self.var, self.number_of_bins))\n        self._set_bin_width_slider_label()\n\n    @staticmethod\n    def min_var_resolution(var):\n        # pylint: disable=unidiomatic-typecheck\n        if type(var) is not ContinuousVariable:\n            return 0\n        return 10 ** -var.number_of_decimals\n\n    def str_int(self, x0, x1, first, last):\n        var = self.var\n        sx0, sx1 = var.repr_val(x0), var.repr_val(x1)\n        if self.cumulative_distr:\n            return f\"{var.name} < {sx1}\"\n        elif first and last:\n            return f\"{var.name} = {sx0}\"\n        elif first:\n            return f\"{var.name} < {sx1}\"\n        elif last:\n            return f\"{var.name} ≥ {sx0}\"\n        elif sx0 == sx1 or x1 - x0 <= self.min_var_resolution(var):\n            return f\"{var.name} = {sx0}\"\n        else:\n            return f\"{sx0} ≤ {var.name} < {sx1}\"\n\n    # -----------------------------\n    # Selection\n\n    def _on_item_clicked(self, item, modifiers, drag):\n        def add_or_remove(idx, add):\n            self.drag_operation = [self.DragRemove, self.DragAdd][add]\n            if add:\n                self.selection.add(idx)\n            else:\n                if idx in self.selection:\n                    # This can be False when removing with dragging and the\n                    # mouse crosses unselected items\n                    self.selection.remove(idx)\n\n        def add_range(add):\n            if self.last_click_idx is None:\n                add = True\n                idx_range = {idx}\n            else:\n                from_idx, to_idx = sorted((self.last_click_idx, idx))\n                idx_range = set(range(from_idx, to_idx + 1))\n            self.drag_operation = [self.DragRemove, self.DragAdd][add]\n            if add:\n                self.selection |= idx_range\n            else:\n                self.selection -= idx_range\n\n        self.key_operation = None\n        if item is None:\n            self.reset_select()\n            return\n\n        idx = self.bar_items.index(item)\n        if drag:\n            # Dragging has to add a range, otherwise fast dragging skips bars\n            add_range(self.drag_operation == self.DragAdd)\n        else:\n            if modifiers & Qt.ShiftModifier:\n                add_range(self.drag_operation == self.DragAdd)\n            elif modifiers & Qt.ControlModifier:\n                add_or_remove(idx, add=idx not in self.selection)\n            else:\n                if self.selection == {idx}:\n                    # Clicking on a single selected bar  deselects it,\n                    # but dragging from here will select\n                    add_or_remove(idx, add=False)\n                    self.drag_operation = self.DragAdd\n                else:\n                    self.selection.clear()\n                    add_or_remove(idx, add=True)\n        self.last_click_idx = idx\n\n        self.show_selection()\n\n    def _on_blank_clicked(self):\n        self.reset_select()\n\n    def reset_select(self):\n        self.selection.clear()\n        self.last_click_idx = None\n        self.drag_operation = None\n        self.key_operation = None\n        self.show_selection()\n\n    def _on_end_selecting(self):\n        self.apply()\n\n    def show_selection(self):\n        self.plot_mark.clear()\n        if not self.is_valid:  # though if it's not, selection is empty anyway\n            return\n\n        blue = QColor(Qt.blue)\n        pen = QPen(QBrush(blue), 3)\n        pen.setCosmetic(True)\n        brush = QBrush(blue.lighter(190))\n\n        for group in self.grouped_selection():\n            group = list(group)\n            left_idx, right_idx = group[0], group[-1]\n            left_pad, right_pad = self._determine_padding(left_idx, right_idx)\n            x0 = self.bar_items[left_idx].x0 - left_pad\n            x1 = self.bar_items[right_idx].x1 + right_pad\n            item = QGraphicsRectItem(x0, 0, x1 - x0, 1)\n            item.setPen(pen)\n            item.setBrush(brush)\n            if self.var.is_continuous:\n                valname = self.str_int(\n                    x0, x1, not left_idx, right_idx == len(self.bar_items) - 1)\n                inside = sum(np.sum(self.bar_items[i].freqs) for i in group)\n                total = len(self.valid_data)\n                item.setToolTip(\n                    \"<p style='white-space:pre;'>\"\n                    f\"<b>{escape(valname)}</b>: \"\n                    f\"{inside} ({100 * inside / total:.2f} %)\")\n            self.plot_mark.addItem(item)\n\n    def _determine_padding(self, left_idx, right_idx):\n        def _padding(i):\n            return (self.bar_items[i + 1].x0 - self.bar_items[i].x1) / 2\n\n        if len(self.bar_items) == 1:\n            return 6, 6\n        if left_idx == 0 and right_idx == len(self.bar_items) - 1:\n            return (_padding(0), ) * 2\n\n        if left_idx > 0:\n            left_pad = _padding(left_idx - 1)\n        if right_idx < len(self.bar_items) - 1:\n            right_pad = _padding(right_idx)\n        else:\n            right_pad = left_pad\n        if left_idx == 0:\n            left_pad = right_pad\n        return left_pad, right_pad\n\n    def grouped_selection(self):\n        return [[g[1] for g in group]\n                for _, group in groupby(enumerate(sorted(self.selection)),\n                                        key=lambda x: x[1] - x[0])]\n\n    def keyPressEvent(self, e):\n        def on_nothing_selected():\n            if e.key() == Qt.Key_Left:\n                self.last_click_idx = len(self.bar_items) - 1\n            else:\n                self.last_click_idx = 0\n            self.selection.add(self.last_click_idx)\n\n        def on_key_left():\n            if e.modifiers() & Qt.ShiftModifier:\n                if self.key_operation == Qt.Key_Right and first != last:\n                    self.selection.remove(last)\n                    self.last_click_idx = last - 1\n                elif first:\n                    self.key_operation = Qt.Key_Left\n                    self.selection.add(first - 1)\n                    self.last_click_idx = first - 1\n            else:\n                self.selection.clear()\n                self.last_click_idx = max(first - 1, 0)\n                self.selection.add(self.last_click_idx)\n\n        def on_key_right():\n            if e.modifiers() & Qt.ShiftModifier:\n                if self.key_operation == Qt.Key_Left and first != last:\n                    self.selection.remove(first)\n                    self.last_click_idx = first + 1\n                elif not self._is_last_bar(last):\n                    self.key_operation = Qt.Key_Right\n                    self.selection.add(last + 1)\n                    self.last_click_idx = last + 1\n            else:\n                self.selection.clear()\n                self.last_click_idx = min(last + 1, len(self.bar_items) - 1)\n                self.selection.add(self.last_click_idx)\n\n        if not self.is_valid or not self.bar_items \\\n                or e.key() not in (Qt.Key_Left, Qt.Key_Right):\n            super().keyPressEvent(e)\n            return\n\n        prev_selection = self.selection.copy()\n        if not self.selection:\n            on_nothing_selected()\n        else:\n            first, last = min(self.selection), max(self.selection)\n            if e.key() == Qt.Key_Left:\n                on_key_left()\n            else:\n                on_key_right()\n\n        if self.selection != prev_selection:\n            self.drag_operation = self.DragAdd\n            self.show_selection()\n            self.apply()\n\n    def keyReleaseEvent(self, ev):\n        if ev.key() == Qt.Key_Shift:\n            self.key_operation = None\n        super().keyReleaseEvent(ev)\n\n\n    # -----------------------------\n    # Output\n\n    def apply(self):\n        data = self.data\n        selected_data = annotated_data = histogram_data = None\n        if self.is_valid:\n            if self.var.is_discrete:\n                group_indices, values = self._get_output_indices_disc()\n            else:\n                group_indices, values = self._get_output_indices_cont()\n                hist_indices, hist_values = self._get_histogram_indices()\n                histogram_data = create_groups_table(\n                    data, hist_indices, values=hist_values)\n            selected = np.nonzero(group_indices)[0]\n            if selected.size:\n                selected_data = create_groups_table(\n                    data, group_indices,\n                    include_unselected=False, values=values)\n                annotated_data = create_annotated_table(data, selected)\n\n        self.Outputs.selected_data.send(selected_data)\n        self.Outputs.annotated_data.send(annotated_data)\n        self.Outputs.histogram_data.send(histogram_data)\n\n    def _get_output_indices_disc(self):\n        group_indices = np.zeros(len(self.data), dtype=np.int32)\n        col = self.data.get_column_view(self.var)[0].astype(float)\n        for group_idx, val_idx in enumerate(self.selection, start=1):\n            group_indices[col == val_idx] = group_idx\n        values = [self.var.values[i] for i in self.selection]\n        return group_indices, values\n\n    def _get_output_indices_cont(self):\n        group_indices = np.zeros(len(self.data), dtype=np.int32)\n        col = self.data.get_column_view(self.var)[0].astype(float)\n        values = []\n        for group_idx, group in enumerate(self.grouped_selection(), start=1):\n            x0 = x1 = None\n            for bar_idx in group:\n                minx, maxx, mask = self._get_cont_baritem_indices(col, bar_idx)\n                if x0 is None:\n                    x0 = minx\n                x1 = maxx\n                group_indices[mask] = group_idx\n            # pylint: disable=undefined-loop-variable\n            values.append(\n                self.str_int(x0, x1, not bar_idx, self._is_last_bar(bar_idx)))\n        return group_indices, values\n\n    def _get_histogram_indices(self):\n        group_indices = np.zeros(len(self.data), dtype=np.int32)\n        col = self.data.get_column_view(self.var)[0].astype(float)\n        values = []\n        for bar_idx in range(len(self.bar_items)):\n            x0, x1, mask = self._get_cont_baritem_indices(col, bar_idx)\n            group_indices[mask] = bar_idx + 1\n            values.append(\n                self.str_int(x0, x1, not bar_idx, self._is_last_bar(bar_idx)))\n        return group_indices, values\n\n    def _get_cont_baritem_indices(self, col, bar_idx):\n        bar_item = self.bar_items[bar_idx]\n        minx = bar_item.x0\n        maxx = bar_item.x1 + (bar_idx == len(self.bar_items) - 1)\n        with np.errstate(invalid=\"ignore\"):\n            return minx, maxx, (col >= minx) * (col < maxx)\n\n    def _is_last_bar(self, idx):\n        return idx == len(self.bar_items) - 1\n\n    # -----------------------------\n    # Report\n\n    def get_widget_name_extension(self):\n        return self.var\n\n    def send_report(self):\n        self.plotview.scene().setSceneRect(self.plotview.sceneRect())\n        if not self.is_valid:\n            return\n        self.report_plot()\n        if self.cumulative_distr:\n            text = f\"Cummulative distribution of '{self.var.name}'\"\n        else:\n            text = f\"Distribution of '{self.var.name}'\"\n        if self.cvar:\n            text += f\" with columns split by '{self.cvar.name}'\"\n        self.report_caption(text)",
                            "ast_type_str": "ClassDef",
                            "start_lineno": 704,
                            "end_lineno": 719,
                            "parent": {
                                "file_name": "Orange/widgets/visualize/owdistributions.py",
                                "type": "class",
                                "name": "OWDistributions",
                                "content": "class OWDistributions(OWWidget):\n    name = \"Distributions\"\n    description = \"Display value distributions of a data feature in a graph.\"\n    icon = \"icons/Distribution.svg\"\n    priority = 120\n    keywords = []\n\n    class Inputs:\n        data = Input(\"Data\", Table, doc=\"Set the input dataset\")\n\n    class Outputs:\n        selected_data = Output(\"Selected Data\", Table, default=True)\n        annotated_data = Output(ANNOTATED_DATA_SIGNAL_NAME, Table)\n        histogram_data = Output(\"Histogram Data\", Table)\n\n    class Error(OWWidget.Error):\n        no_defined_values_var = \\\n            Msg(\"Variable '{}' does not have any defined values\")\n        no_defined_values_pair = \\\n            Msg(\"No data instances with '{}' and '{}' defined\")\n\n    class Warning(OWWidget.Warning):\n        ignored_nans = Msg(\"Data instances with missing values are ignored\")\n\n    settingsHandler = settings.DomainContextHandler()\n    var = settings.ContextSetting(None)\n    cvar = settings.ContextSetting(None)\n    selection = settings.ContextSetting(set(), schema_only=True)\n    # number_of_bins must be a context setting because selection depends on it\n    number_of_bins = settings.ContextSetting(5, schema_only=True)\n\n    fitted_distribution = settings.Setting(0)\n    show_probs = settings.Setting(False)\n    stacked_columns = settings.Setting(False)\n    cumulative_distr = settings.Setting(False)\n\n    auto_apply = settings.Setting(True)\n\n    graph_name = \"plot\"\n\n    Fitters = (\n        (\"None\", None, (), ()),\n        (\"Normal\", norm, (\"loc\", \"scale\"), (\"μ\", \"σ²\")),\n        (\"Beta\", beta, (\"a\", \"b\", \"loc\", \"scale\"),\n         (\"α\", \"β\", \"-loc\", \"-scale\")),\n        (\"Gamma\", gamma, (\"a\", \"loc\", \"scale\"), (\"α\", \"β\", \"-loc\", \"-scale\")),\n        (\"Rayleigh\", rayleigh, (\"loc\", \"scale\"), (\"-loc\", \"σ²\")),\n        (\"Pareto\", pareto, (\"b\", \"loc\", \"scale\"), (\"α\", \"-loc\", \"-scale\")),\n        (\"Exponential\", expon, (\"loc\", \"scale\"), (\"-loc\", \"λ\")),\n    )\n\n    DragNone, DragAdd, DragRemove = range(3)\n\n    def __init__(self):\n        super().__init__()\n        self.data = None\n        self.valid_data = self.valid_group_data = None\n        self.bar_items = []\n        self.curve_descriptions = None\n        self.binnings = []\n\n        self.last_click_idx = None\n        self.drag_operation = self.DragNone\n        self.key_operation = None\n        self._user_var_bins = {}\n\n        gui.listView(\n            self.controlArea, self, \"var\", box=\"Variable\",\n            model=DomainModel(valid_types=DomainModel.PRIMITIVE,\n                              separators=False),\n            callback=self._on_var_changed)\n\n        box = self.continuous_box = gui.vBox(self.controlArea, \"Distribution\")\n        slider = gui.hSlider(\n            box, self, \"number_of_bins\",\n            label=\"Bin width\", orientation=Qt.Horizontal,\n            minValue=0, maxValue=max(1, len(self.binnings) - 1),\n            createLabel=False, callback=self._on_bins_changed)\n        self.bin_width_label = gui.widgetLabel(slider.box)\n        self.bin_width_label.setFixedWidth(35)\n        self.bin_width_label.setAlignment(Qt.AlignRight)\n        slider.sliderReleased.connect(self._on_bin_slider_released)\n        gui.comboBox(\n            box, self, \"fitted_distribution\", label=\"Fitted distribution\",\n            orientation=Qt.Horizontal, items=(name[0] for name in self.Fitters),\n            callback=self.replot)\n        gui.checkBox(\n            box, self, \"cumulative_distr\", \"Show cumulative distribution\",\n            callback=self.replot)\n\n        box = gui.vBox(self.controlArea, \"Columns\")\n        gui.comboBox(\n            box, self, \"cvar\", label=\"Split by\", orientation=Qt.Horizontal,\n            model=DomainModel(placeholder=\"(None)\",\n                              valid_types=(DiscreteVariable), ),\n            callback=self._on_cvar_changed, contentsLength=18)\n        box2 = gui.indentedBox(box, sep=12)\n        gui.checkBox(\n            box2, self, \"stacked_columns\", \"Stack columns\",\n            callback=self.replot)\n        gui.checkBox(\n            box2, self, \"show_probs\", \"Show probabilities\",\n            callback=self._on_show_probabilities_changed)\n\n        gui.auto_commit(\n            self.controlArea, self, \"auto_apply\", \"&Apply\", commit=self.apply)\n\n        self._setup_plots()\n        self._setup_legend()\n\n    def _setup_plots(self):\n        def add_new_plot(zvalue):\n            plot = pg.ViewBox(enableMouse=False, enableMenu=False)\n            self.ploti.scene().addItem(plot)\n            pg.AxisItem(\"right\").linkToView(plot)\n            plot.setXLink(self.ploti)\n            plot.setZValue(zvalue)\n            return plot\n\n        self.plotview = DistributionWidget(background=None)\n        self.plotview.item_clicked.connect(self._on_item_clicked)\n        self.plotview.blank_clicked.connect(self._on_blank_clicked)\n        self.plotview.mouse_released.connect(self._on_end_selecting)\n        self.plotview.setRenderHint(QPainter.Antialiasing)\n        self.mainArea.layout().addWidget(self.plotview)\n        self.ploti = pg.PlotItem(\n            enableMenu=False, enableMouse=False,\n            axisItems={\"bottom\": ElidedLabelsAxis(\"bottom\")})\n        self.plot = self.ploti.vb\n        self.plot.setMouseEnabled(False, False)\n        self.ploti.hideButtons()\n        self.plotview.setCentralItem(self.ploti)\n\n        self.plot_pdf = add_new_plot(10)\n        self.plot_mark = add_new_plot(-10)\n        self.plot_mark.setYRange(0, 1)\n        self.ploti.vb.sigResized.connect(self.update_views)\n        self.update_views()\n\n        pen = QPen(self.palette().color(QPalette.Text))\n        self.ploti.getAxis(\"bottom\").setPen(pen)\n        left = self.ploti.getAxis(\"left\")\n        left.setPen(pen)\n        left.setStyle(stopAxisAtTick=(True, True))\n\n    def _setup_legend(self):\n        self._legend = LegendItem()\n        self._legend.setParentItem(self.plot)\n        self._legend.hide()\n        self._legend.anchor((1, 0), (1, 0))\n\n    # -----------------------------\n    # Event and signal handlers\n\n    def update_views(self):\n        for plot in (self.plot_pdf, self.plot_mark):\n            plot.setGeometry(self.plot.sceneBoundingRect())\n            plot.linkedViewChanged(self.plot, plot.XAxis)\n\n    def onDeleteWidget(self):\n        self.plot.clear()\n        self.plot_pdf.clear()\n        self.plot_mark.clear()\n        super().onDeleteWidget()\n\n    @Inputs.data\n    def set_data(self, data):\n        self.closeContext()\n        self.var = self.cvar = None\n        self.data = data\n        domain = self.data.domain if self.data else None\n        varmodel = self.controls.var.model()\n        cvarmodel = self.controls.cvar.model()\n        varmodel.set_domain(domain)\n        cvarmodel.set_domain(domain)\n        if varmodel:\n            self.var = varmodel[min(len(domain.class_vars), len(varmodel) - 1)]\n        if domain is not None and domain.has_discrete_class:\n            self.cvar = domain.class_var\n        self.reset_select()\n        self._user_var_bins.clear()\n        self.openContext(domain)\n        self.set_valid_data()\n        self.recompute_binnings()\n        self.replot()\n        self.apply()\n\n    def _on_var_changed(self):\n        self.reset_select()\n        self.set_valid_data()\n        self.recompute_binnings()\n        self.replot()\n        self.apply()\n\n    def _on_cvar_changed(self):\n        self.set_valid_data()\n        self.replot()\n        self.apply()\n\n    def _on_bins_changed(self):\n        self.reset_select()\n        self._set_bin_width_slider_label()\n        self.replot()\n        # this is triggered when dragging, so don't call apply here;\n        # apply is called on sliderReleased\n\n    def _on_bin_slider_released(self):\n        self._user_var_bins[self.var] = self.number_of_bins\n        self.apply()\n\n    def _set_bin_width_slider_label(self):\n        text = \"\"\n        if self.number_of_bins < len(self.binnings):\n            bins = self.binnings[self.number_of_bins]\n            if len(bins) > 1:\n                text = self.var.repr_val(bins[1] - bins[0])\n        self.bin_width_label.setText(text)\n\n    def _on_show_probabilities_changed(self):\n        label = self.controls.fitted_distribution.label\n        if self.show_probs:\n            label.setText(\"Fitted probability\")\n            label.setToolTip(\n                \"Chosen distribution is used to compute Bayesian probabilities\")\n        else:\n            label.setText(\"Fitted distribution\")\n            label.setToolTip(\"\")\n        self.replot()\n\n    @property\n    def is_valid(self):\n        return self.valid_data is not None\n\n    def set_valid_data(self):\n        err_def_var = self.Error.no_defined_values_var\n        err_def_pair = self.Error.no_defined_values_pair\n        err_def_var.clear()\n        err_def_pair.clear()\n        self.Warning.ignored_nans.clear()\n\n        self.valid_data = self.valid_group_data = None\n        if self.var is None:\n            return\n\n        column = self.data.get_column_view(self.var)[0].astype(float)\n        valid_mask = np.isfinite(column)\n        if not np.any(valid_mask):\n            self.Error.no_defined_values_var(self.var.name)\n            return\n        if self.cvar:\n            ccolumn = self.data.get_column_view(self.cvar)[0].astype(float)\n            valid_mask *= np.isfinite(ccolumn)\n            if not np.any(valid_mask):\n                self.Error.no_defined_values_pair(self.var.name, self.cvar.name)\n                return\n            self.valid_group_data = ccolumn[valid_mask]\n        if not np.all(valid_mask):\n            self.Warning.ignored_nans()\n        self.valid_data = column[valid_mask]\n\n    # -----------------------------\n    # Plotting\n\n    def replot(self):\n        self._clear_plot()\n        if self.is_valid:\n            self._set_axis_names()\n            self._update_controls_state()\n            self._call_plotting()\n            self._display_legend()\n        self.show_selection()\n\n    def _clear_plot(self):\n        self.plot.clear()\n        self.plot_pdf.clear()\n        self.plot_mark.clear()\n        self.bar_items = []\n        self._legend.clear()\n        self._legend.hide()\n\n    def _set_axis_names(self):\n        assert self.is_valid  # called only from replot, so assumes data is OK\n        bottomaxis = self.ploti.getAxis(\"bottom\")\n        bottomaxis.setLabel(self.var and self.var.name)\n\n        leftaxis = self.ploti.getAxis(\"left\")\n        if self.show_probs and self.cvar:\n            leftaxis.setLabel(\n                f\"Probability of '{self.cvar.name}' at given '{self.var.name}'\")\n        else:\n            leftaxis.setLabel(\"Frequency\")\n        leftaxis.resizeEvent()\n\n    def _update_controls_state(self):\n        assert self.is_valid  # called only from replot, so assumes data is OK\n        self.continuous_box.setDisabled(self.var.is_discrete)\n        self.controls.show_probs.setDisabled(self.cvar is None)\n        self.controls.stacked_columns.setDisabled(self.cvar is None)\n\n    def _call_plotting(self):\n        assert self.is_valid  # called only from replot, so assumes data is OK\n        self.curve_descriptions = None\n        if self.var.is_discrete:\n            if self.cvar:\n                self._disc_split_plot()\n            else:\n                self._disc_plot()\n        else:\n            if self.cvar:\n                self._cont_split_plot()\n            else:\n                self._cont_plot()\n        self.plot.autoRange()\n\n    def _add_bar(self, x, width, padding, freqs, colors, stacked, expanded,\n                 tooltip):\n        item = DistributionBarItem(\n            x, width, padding, freqs, colors, stacked, expanded, tooltip)\n        self.plot.addItem(item)\n        self.bar_items.append(item)\n\n    def _disc_plot(self):\n        var = self.var\n        self.ploti.getAxis(\"bottom\").setTicks([list(enumerate(var.values))])\n        colors = [QColor(0, 128, 255)]\n        dist = distribution.get_distribution(self.data, self.var)\n        for i, freq in enumerate(dist):\n            tooltip = \\\n                \"<p style='white-space:pre;'>\" \\\n                f\"<b>{escape(var.values[i])}</b>: {int(freq)} \" \\\n                f\"({100 * freq / len(self.valid_data):.2f} %) \"\n            self._add_bar(\n                i - 0.5, 1, 0.1, [freq], colors,\n                stacked=False, expanded=False, tooltip=tooltip)\n\n    def _disc_split_plot(self):\n        var = self.var\n        self.ploti.getAxis(\"bottom\").setTicks([list(enumerate(var.values))])\n        gcolors = [QColor(*col) for col in self.cvar.colors]\n        gvalues = self.cvar.values\n        conts = contingency.get_contingency(self.data, self.cvar, self.var)\n        total = len(self.data)\n        for i, freqs in enumerate(conts):\n            self._add_bar(\n                i - 0.5, 1, 0.1, freqs, gcolors,\n                stacked=self.stacked_columns, expanded=self.show_probs,\n                tooltip=self._split_tooltip(\n                    var.values[i], np.sum(freqs), total, gvalues, freqs))\n\n    def _cont_plot(self):\n        self.ploti.getAxis(\"bottom\").setTicks(None)\n        data = self.valid_data\n        y, x = np.histogram(data, bins=self.binnings[self.number_of_bins])\n        total = len(data)\n        colors = [QColor(0, 128, 255)]\n        if self.fitted_distribution:\n            colors[0] = colors[0].lighter(130)\n\n        tot_freq = 0\n        lasti = len(y) - 1\n        for i, (x0, x1), freq in zip(count(), zip(x, x[1:]), y):\n            tot_freq += freq\n            tooltip = \\\n                \"<p style='white-space:pre;'>\" \\\n                f\"<b>{escape(self.str_int(x0, x1, not i, i == lasti))}</b>: \" \\\n                f\"{freq} ({100 * freq / total:.2f} %)</p>\"\n            self._add_bar(\n                x0, x1 - x0, 0, [tot_freq if self.cumulative_distr else freq],\n                colors, stacked=False, expanded=False, tooltip=tooltip)\n\n        if self.fitted_distribution:\n            self._plot_approximations(\n                x[0], x[-1], [self._fit_approximation(data)],\n                [QColor(0, 0, 0)], (1,))\n\n    def _cont_split_plot(self):\n        self.ploti.getAxis(\"bottom\").setTicks(None)\n        data = self.valid_data\n        _, bins = np.histogram(data, bins=self.binnings[self.number_of_bins])\n        gvalues = self.cvar.values\n        varcolors = [QColor(*col) for col in self.cvar.colors]\n        if self.fitted_distribution:\n            gcolors = [c.lighter(130) for c in varcolors]\n        else:\n            gcolors = varcolors\n        nvalues = len(gvalues)\n        ys = []\n        fitters = []\n        prior_sizes = []\n        for val_idx in range(nvalues):\n            group_data = data[self.valid_group_data == val_idx]\n            prior_sizes.append(len(group_data))\n            ys.append(np.histogram(group_data, bins)[0])\n            if self.fitted_distribution:\n                fitters.append(self._fit_approximation(group_data))\n        total = len(data)\n        prior_sizes = np.array(prior_sizes)\n        tot_freqs = np.zeros(len(ys))\n\n        lasti = len(ys[0]) - 1\n        for i, x0, x1, freqs in zip(count(), bins, bins[1:], zip(*ys)):\n            tot_freqs += freqs\n            plotfreqs = tot_freqs.copy() if self.cumulative_distr else freqs\n            self._add_bar(\n                x0, x1 - x0, 0 if self.stacked_columns else 0.1, plotfreqs,\n                gcolors, stacked=self.stacked_columns, expanded=self.show_probs,\n                tooltip=self._split_tooltip(\n                    self.str_int(x0, x1, not i, i == lasti),\n                    np.sum(plotfreqs), total, gvalues, plotfreqs))\n\n        if fitters:\n            self._plot_approximations(bins[0], bins[-1], fitters, varcolors,\n                                      prior_sizes / len(data))\n\n    def _fit_approximation(self, y):\n        def join_pars(pairs):\n            strv = self.var.str_val\n            return \", \".join(f\"{sname}={strv(val)}\" for sname, val in pairs)\n\n        def str_params():\n            s = join_pars(\n                (sname, val) for sname, val in zip(str_names, fitted)\n                if sname[0] != \"-\")\n            par = join_pars(\n                (sname[1:], val) for sname, val in zip(str_names, fitted)\n                if sname[0] == \"-\")\n            if par:\n                s += f\" ({par})\"\n            return s\n\n        _, dist, names, str_names = self.Fitters[self.fitted_distribution]\n        fitted = dist.fit(y)\n        params = {name: val for name, val in zip(names, fitted)}\n        return partial(dist.pdf, **params), str_params()\n\n    def _plot_approximations(self, x0, x1, fitters, colors, prior_probs=0):\n        x = np.linspace(x0, x1, 100)\n        ys = np.empty((len(fitters), 100))\n        self.curve_descriptions = [s for _, s in fitters]\n        for y, (fitter, _), color in zip(ys, fitters, colors):\n            y[:] = fitter(x)\n            if self.cumulative_distr:\n                y[:] = np.cumsum(y)\n        tots = np.sum(ys, axis=0)\n\n        show_probs = self.show_probs and self.cvar is not None\n        plot = self.ploti if show_probs else self.plot_pdf\n\n        for y, prior_prob, color in zip(ys, prior_probs, colors):\n            if show_probs:\n                y_p = y * prior_prob\n                y = y_p / (y_p + (tots - y) * (1 - prior_prob))\n            plot.addItem(pg.PlotCurveItem(\n                x=x, y=y,\n                pen=pg.mkPen(width=5, color=color),\n                shadowPen=pg.mkPen(width=8, color=color.darker(120))))\n        if not show_probs:\n            self.plot_pdf.autoRange()\n\n    @staticmethod\n    def _split_tooltip(valname, tot_group, total, gvalues, freqs):\n        div_group = tot_group or 1\n        cs = \"white-space:pre; text-align: right;\"\n        s = f\"style='{cs} padding-left: 1em'\"\n        snp = f\"style='{cs}'\"\n        return f\"<table style='border-collapse: collapse'>\" \\\n               f\"<tr><th {s}>{escape(valname)}:</th>\" \\\n               f\"<td {snp}><b>{int(tot_group)}</b></td>\" \\\n               \"<td/>\" \\\n               f\"<td {s}><b>{100 * tot_group / total:.2f} %</b></td></tr>\" + \\\n               f\"<tr><td/><td/><td {s}>(in group)</td><td {s}>(overall)</td>\" \\\n               \"</tr>\" + \\\n               \"\".join(\n                   \"<tr>\"\n                   f\"<th {s}>{value}:</th>\"\n                   f\"<td {snp}><b>{int(freq)}</b></td>\"\n                   f\"<td {s}>{100 * freq / div_group:.2f} %</td>\"\n                   f\"<td {s}>{100 * freq / total:.2f} %</td>\"\n                   \"</tr>\"\n                   for value, freq in zip(gvalues, freqs)) + \\\n               \"</table>\"\n\n    def _display_legend(self):\n        assert self.is_valid  # called only from replot, so assumes data is OK\n        if self.cvar is None:\n            if not self.curve_descriptions:\n                self._legend.hide()\n                return\n            self._legend.addItem(\n                pg.PlotCurveItem(pen=pg.mkPen(width=5, color=0.0)),\n                self.curve_descriptions[0])\n        else:\n            cvar_values = self.cvar.values\n            colors = [QColor(*col) for col in self.cvar.colors]\n            descriptions = self.curve_descriptions or repeat(None)\n            for color, name, desc in zip(colors, cvar_values, descriptions):\n                self._legend.addItem(\n                    ScatterPlotItem(pen=color, brush=color, size=10, shape=\"s\"),\n                    escape(name + (f\" ({desc})\" if desc else \"\")))\n        self._legend.show()\n\n    # -----------------------------\n    # Bins\n\n    def recompute_binnings(self):\n        self.binnings = []\n        max_bins = 0\n        if self.is_valid and self.var.is_continuous:\n            # binning is computed on valid var data, ignoring any cvar nans\n            column = self.data.get_column_view(self.var)[0].astype(float)\n            if np.any(np.isfinite(column)):\n                self.binnings = decimal_binnings(\n                    column, min_width=self.min_var_resolution(self.var),\n                    add_unique=10, min_unique=5)\n                max_bins = len(self.binnings) - 1\n\n        self.controls.number_of_bins.setMaximum(max_bins)\n        self.number_of_bins = min(\n            max_bins, self._user_var_bins.get(self.var, self.number_of_bins))\n        self._set_bin_width_slider_label()\n\n    @staticmethod\n    def min_var_resolution(var):\n        # pylint: disable=unidiomatic-typecheck\n        if type(var) is not ContinuousVariable:\n            return 0\n        return 10 ** -var.number_of_decimals\n\n    def str_int(self, x0, x1, first, last):\n        var = self.var\n        sx0, sx1 = var.repr_val(x0), var.repr_val(x1)\n        if self.cumulative_distr:\n            return f\"{var.name} < {sx1}\"\n        elif first and last:\n            return f\"{var.name} = {sx0}\"\n        elif first:\n            return f\"{var.name} < {sx1}\"\n        elif last:\n            return f\"{var.name} ≥ {sx0}\"\n        elif sx0 == sx1 or x1 - x0 <= self.min_var_resolution(var):\n            return f\"{var.name} = {sx0}\"\n        else:\n            return f\"{sx0} ≤ {var.name} < {sx1}\"\n\n    # -----------------------------\n    # Selection\n\n    def _on_item_clicked(self, item, modifiers, drag):\n        def add_or_remove(idx, add):\n            self.drag_operation = [self.DragRemove, self.DragAdd][add]\n            if add:\n                self.selection.add(idx)\n            else:\n                if idx in self.selection:\n                    # This can be False when removing with dragging and the\n                    # mouse crosses unselected items\n                    self.selection.remove(idx)\n\n        def add_range(add):\n            if self.last_click_idx is None:\n                add = True\n                idx_range = {idx}\n            else:\n                from_idx, to_idx = sorted((self.last_click_idx, idx))\n                idx_range = set(range(from_idx, to_idx + 1))\n            self.drag_operation = [self.DragRemove, self.DragAdd][add]\n            if add:\n                self.selection |= idx_range\n            else:\n                self.selection -= idx_range\n\n        self.key_operation = None\n        if item is None:\n            self.reset_select()\n            return\n\n        idx = self.bar_items.index(item)\n        if drag:\n            # Dragging has to add a range, otherwise fast dragging skips bars\n            add_range(self.drag_operation == self.DragAdd)\n        else:\n            if modifiers & Qt.ShiftModifier:\n                add_range(self.drag_operation == self.DragAdd)\n            elif modifiers & Qt.ControlModifier:\n                add_or_remove(idx, add=idx not in self.selection)\n            else:\n                if self.selection == {idx}:\n                    # Clicking on a single selected bar  deselects it,\n                    # but dragging from here will select\n                    add_or_remove(idx, add=False)\n                    self.drag_operation = self.DragAdd\n                else:\n                    self.selection.clear()\n                    add_or_remove(idx, add=True)\n        self.last_click_idx = idx\n\n        self.show_selection()\n\n    def _on_blank_clicked(self):\n        self.reset_select()\n\n    def reset_select(self):\n        self.selection.clear()\n        self.last_click_idx = None\n        self.drag_operation = None\n        self.key_operation = None\n        self.show_selection()\n\n    def _on_end_selecting(self):\n        self.apply()\n\n    def show_selection(self):\n        self.plot_mark.clear()\n        if not self.is_valid:  # though if it's not, selection is empty anyway\n            return\n\n        blue = QColor(Qt.blue)\n        pen = QPen(QBrush(blue), 3)\n        pen.setCosmetic(True)\n        brush = QBrush(blue.lighter(190))\n\n        for group in self.grouped_selection():\n            group = list(group)\n            left_idx, right_idx = group[0], group[-1]\n            left_pad, right_pad = self._determine_padding(left_idx, right_idx)\n            x0 = self.bar_items[left_idx].x0 - left_pad\n            x1 = self.bar_items[right_idx].x1 + right_pad\n            item = QGraphicsRectItem(x0, 0, x1 - x0, 1)\n            item.setPen(pen)\n            item.setBrush(brush)\n            if self.var.is_continuous:\n                valname = self.str_int(\n                    x0, x1, not left_idx, right_idx == len(self.bar_items) - 1)\n                inside = sum(np.sum(self.bar_items[i].freqs) for i in group)\n                total = len(self.valid_data)\n                item.setToolTip(\n                    \"<p style='white-space:pre;'>\"\n                    f\"<b>{escape(valname)}</b>: \"\n                    f\"{inside} ({100 * inside / total:.2f} %)\")\n            self.plot_mark.addItem(item)\n\n    def _determine_padding(self, left_idx, right_idx):\n        def _padding(i):\n            return (self.bar_items[i + 1].x0 - self.bar_items[i].x1) / 2\n\n        if len(self.bar_items) == 1:\n            return 6, 6\n        if left_idx == 0 and right_idx == len(self.bar_items) - 1:\n            return (_padding(0), ) * 2\n\n        if left_idx > 0:\n            left_pad = _padding(left_idx - 1)\n        if right_idx < len(self.bar_items) - 1:\n            right_pad = _padding(right_idx)\n        else:\n            right_pad = left_pad\n        if left_idx == 0:\n            left_pad = right_pad\n        return left_pad, right_pad\n\n    def grouped_selection(self):\n        return [[g[1] for g in group]\n                for _, group in groupby(enumerate(sorted(self.selection)),\n                                        key=lambda x: x[1] - x[0])]\n\n    def keyPressEvent(self, e):\n        def on_nothing_selected():\n            if e.key() == Qt.Key_Left:\n                self.last_click_idx = len(self.bar_items) - 1\n            else:\n                self.last_click_idx = 0\n            self.selection.add(self.last_click_idx)\n\n        def on_key_left():\n            if e.modifiers() & Qt.ShiftModifier:\n                if self.key_operation == Qt.Key_Right and first != last:\n                    self.selection.remove(last)\n                    self.last_click_idx = last - 1\n                elif first:\n                    self.key_operation = Qt.Key_Left\n                    self.selection.add(first - 1)\n                    self.last_click_idx = first - 1\n            else:\n                self.selection.clear()\n                self.last_click_idx = max(first - 1, 0)\n                self.selection.add(self.last_click_idx)\n\n        def on_key_right():\n            if e.modifiers() & Qt.ShiftModifier:\n                if self.key_operation == Qt.Key_Left and first != last:\n                    self.selection.remove(first)\n                    self.last_click_idx = first + 1\n                elif not self._is_last_bar(last):\n                    self.key_operation = Qt.Key_Right\n                    self.selection.add(last + 1)\n                    self.last_click_idx = last + 1\n            else:\n                self.selection.clear()\n                self.last_click_idx = min(last + 1, len(self.bar_items) - 1)\n                self.selection.add(self.last_click_idx)\n\n        if not self.is_valid or not self.bar_items \\\n                or e.key() not in (Qt.Key_Left, Qt.Key_Right):\n            super().keyPressEvent(e)\n            return\n\n        prev_selection = self.selection.copy()\n        if not self.selection:\n            on_nothing_selected()\n        else:\n            first, last = min(self.selection), max(self.selection)\n            if e.key() == Qt.Key_Left:\n                on_key_left()\n            else:\n                on_key_right()\n\n        if self.selection != prev_selection:\n            self.drag_operation = self.DragAdd\n            self.show_selection()\n            self.apply()\n\n    def keyReleaseEvent(self, ev):\n        if ev.key() == Qt.Key_Shift:\n            self.key_operation = None\n        super().keyReleaseEvent(ev)\n\n\n    # -----------------------------\n    # Output\n\n    def apply(self):\n        data = self.data\n        selected_data = annotated_data = histogram_data = None\n        if self.is_valid:\n            if self.var.is_discrete:\n                group_indices, values = self._get_output_indices_disc()\n            else:\n                group_indices, values = self._get_output_indices_cont()\n                hist_indices, hist_values = self._get_histogram_indices()\n                histogram_data = create_groups_table(\n                    data, hist_indices, values=hist_values)\n            selected = np.nonzero(group_indices)[0]\n            if selected.size:\n                selected_data = create_groups_table(\n                    data, group_indices,\n                    include_unselected=False, values=values)\n                annotated_data = create_annotated_table(data, selected)\n\n        self.Outputs.selected_data.send(selected_data)\n        self.Outputs.annotated_data.send(annotated_data)\n        self.Outputs.histogram_data.send(histogram_data)\n\n    def _get_output_indices_disc(self):\n        group_indices = np.zeros(len(self.data), dtype=np.int32)\n        col = self.data.get_column_view(self.var)[0].astype(float)\n        for group_idx, val_idx in enumerate(self.selection, start=1):\n            group_indices[col == val_idx] = group_idx\n        values = [self.var.values[i] for i in self.selection]\n        return group_indices, values\n\n    def _get_output_indices_cont(self):\n        group_indices = np.zeros(len(self.data), dtype=np.int32)\n        col = self.data.get_column_view(self.var)[0].astype(float)\n        values = []\n        for group_idx, group in enumerate(self.grouped_selection(), start=1):\n            x0 = x1 = None\n            for bar_idx in group:\n                minx, maxx, mask = self._get_cont_baritem_indices(col, bar_idx)\n                if x0 is None:\n                    x0 = minx\n                x1 = maxx\n                group_indices[mask] = group_idx\n            # pylint: disable=undefined-loop-variable\n            values.append(\n                self.str_int(x0, x1, not bar_idx, self._is_last_bar(bar_idx)))\n        return group_indices, values\n\n    def _get_histogram_indices(self):\n        group_indices = np.zeros(len(self.data), dtype=np.int32)\n        col = self.data.get_column_view(self.var)[0].astype(float)\n        values = []\n        for bar_idx in range(len(self.bar_items)):\n            x0, x1, mask = self._get_cont_baritem_indices(col, bar_idx)\n            group_indices[mask] = bar_idx + 1\n            values.append(\n                self.str_int(x0, x1, not bar_idx, self._is_last_bar(bar_idx)))\n        return group_indices, values\n\n    def _get_cont_baritem_indices(self, col, bar_idx):\n        bar_item = self.bar_items[bar_idx]\n        minx = bar_item.x0\n        maxx = bar_item.x1 + (bar_idx == len(self.bar_items) - 1)\n        with np.errstate(invalid=\"ignore\"):\n            return minx, maxx, (col >= minx) * (col < maxx)\n\n    def _is_last_bar(self, idx):\n        return idx == len(self.bar_items) - 1\n\n    # -----------------------------\n    # Report\n\n    def get_widget_name_extension(self):\n        return self.var\n\n    def send_report(self):\n        self.plotview.scene().setSceneRect(self.plotview.sceneRect())\n        if not self.is_valid:\n            return\n        self.report_plot()\n        if self.cumulative_distr:\n            text = f\"Cummulative distribution of '{self.var.name}'\"\n        else:\n            text = f\"Distribution of '{self.var.name}'\"\n        if self.cvar:\n            text += f\" with columns split by '{self.cvar.name}'\"\n        self.report_caption(text)",
                                "ast_type_str": "ClassDef",
                                "start_lineno": 200,
                                "end_lineno": 1015,
                                "parent": null
                            }
                        }
                    ],
                    "added_entities": [],
                    "deleted_entities": []
                }
            ]
        },
        {
            "old_file_content": "# Test methods with long descriptive names can omit docstrings\n# pylint: disable=missing-docstring,protected-access\nimport os\nimport unittest\nfrom unittest.mock import Mock\n\nimport numpy as np\nfrom AnyQt.QtCore import QItemSelection\n\nfrom Orange.data import Table, Domain, DiscreteVariable\nfrom Orange.widgets.tests.base import WidgetTest\nfrom Orange.widgets.utils.annotated_data import ANNOTATED_DATA_FEATURE_NAME\nfrom Orange.widgets.utils.itemmodels import DomainModel\nfrom Orange.widgets.visualize.owdistributions import OWDistributions\n\n\nclass TestOWDistributions(WidgetTest):\n    def setUp(self):\n        self.widget = self.create_widget(OWDistributions)  #: OWDistributions\n        self.iris = Table(\"iris\")\n\n    def _set_cvar(self, cvar):\n        combo = self.widget.controls.cvar\n        self.widget.cvar = cvar\n        combo.activated[int].emit(combo.currentIndex())\n        combo.activated[str].emit(combo.currentText())\n\n    def _set_fitter(self, i):\n        combo = self.widget.controls.fitted_distribution\n        combo.setCurrentIndex(i)\n        combo.activated[int].emit(combo.currentIndex())\n        combo.activated[str].emit(combo.currentText())\n\n    def _set_var(self, var):\n        listview = self.widget.controls.var\n        model = listview.model()\n        index = var if isinstance(var, int) else model.indexOf(var)\n        selectionmodel = listview.selectionModel()\n        oldselection = selectionmodel.selection()\n        newselection = QItemSelection()\n        newselection.select(model.index(index, 0), model.index(index, 0))\n        selectionmodel.select(newselection, selectionmodel.ClearAndSelect)\n        selectionmodel.selectionChanged.emit(newselection, oldselection)\n\n    @staticmethod\n    def _set_check(checkbox, value):\n        checkbox.setCheckState(value)\n        checkbox.toggled[bool].emit(value)\n\n    def _set_slider(self, i):\n        slider = self.widget.controls.number_of_bins\n        slider.setValue(i)\n        slider.valueChanged[int].emit(i)\n        slider.sliderReleased.emit()\n\n    def test_set_data(self):\n        \"\"\"Basic test of set_data and removal of data\"\"\"\n        widget = self.widget\n        var_model = widget.controls.var.model()\n        cvar_model = widget.controls.cvar.model()\n\n        domain = self.iris.domain\n        self.send_signal(widget.Inputs.data, self.iris)\n        self.assertEqual({var.name for var in var_model},\n                         {var.name for var in domain.variables})\n        self.assertEqual(list(cvar_model),\n                         [None, DomainModel.Separator, domain.class_var])\n        self.assertIs(widget.var, domain[0])\n        self.assertIs(widget.cvar, domain.class_var)\n        np.testing.assert_equal(widget.valid_data, self.iris.X[:, 0])\n        np.testing.assert_equal(widget.valid_group_data, self.iris.Y)\n        self.assertEqual(\n            len(self.get_output(widget.Outputs.histogram_data)), 150)\n        self.assertIsNone(self.get_output(widget.Outputs.annotated_data))\n        self.assertIsNone(self.get_output(widget.Outputs.selected_data))\n\n        # Data gone: clean up\n        widget.selection.add(0)\n        widget._clear_plot = Mock()\n        self.send_signal(widget.Inputs.data, None)\n        self.assertEqual(len(var_model), 0)\n        self.assertEqual(list(cvar_model), [None])\n        self.assertIsNone(widget.var)\n        self.assertIsNone(widget.cvar)\n\n        self.assertEqual(widget.selection, set())\n        self.assertIsNone(widget.valid_data)\n        self.assertIsNone(widget.valid_group_data)\n        self.assertIsNone(self.get_output(widget.Outputs.histogram_data))\n        self.assertIsNone(self.get_output(widget.Outputs.annotated_data))\n        self.assertIsNone(self.get_output(widget.Outputs.selected_data))\n        widget._clear_plot.assert_called()\n\n    def test_set_data_no_class_no_discrete(self):\n        \"\"\"Widget is properly set up when there is no class and discrete vars\"\"\"\n        widget = self.widget\n        var_model = widget.controls.var.model()\n        cvar_model = widget.controls.cvar.model()\n\n        domain = Domain(self.iris.domain.attributes, [])\n        data = self.iris.transform(domain)\n        self.send_signal(widget.Inputs.data, data)\n        self.assertEqual({var.name for var in var_model},\n                         {var.name for var in domain.attributes})\n        self.assertEqual(list(cvar_model), [None])\n        self.assertIs(widget.var, domain[0])\n        self.assertIs(widget.cvar, None)\n        np.testing.assert_equal(widget.valid_data, self.iris.X[:, 0])\n        self.assertIsNone(widget.valid_group_data)\n        self.assertEqual(\n            len(self.get_output(widget.Outputs.histogram_data)), 150)\n        self.assertIsNone(self.get_output(widget.Outputs.annotated_data))\n        self.assertIsNone(self.get_output(widget.Outputs.selected_data))\n\n    def test_set_data_no_class(self):\n        \"\"\"Widget is properly set up when there is no class\"\"\"\n        widget = self.widget\n        var_model = widget.controls.var.model()\n        cvar_model = widget.controls.cvar.model()\n        iris = self.iris\n\n        domain = Domain(iris.domain.attributes + iris.domain.class_vars)\n        data = iris.transform(domain)\n        self.send_signal(widget.Inputs.data, data)\n        self.assertEqual({var.name for var in var_model},\n                         {var.name for var in domain.attributes})\n        self.assertEqual(list(cvar_model),\n                         [None, DomainModel.Separator, iris.domain.class_var])\n        self.assertIs(widget.var, domain[0])\n        self.assertIs(widget.cvar, None)\n        np.testing.assert_equal(widget.valid_data, self.iris.X[:, 0])\n        self.assertIsNone(widget.valid_group_data)\n        self.assertEqual(\n            len(self.get_output(widget.Outputs.histogram_data)), 150)\n        self.assertIsNone(self.get_output(widget.Outputs.annotated_data))\n        self.assertIsNone(self.get_output(widget.Outputs.selected_data))\n\n    def test_set_data_reg_class(self):\n        \"\"\"Widget is properly set up when the target is numeric\"\"\"\n        widget = self.widget\n        var_model = widget.controls.var.model()\n        cvar_model = widget.controls.cvar.model()\n        iris = self.iris\n\n        domain = Domain(iris.domain.attributes[:3] + iris.domain.class_vars,\n                        iris.domain.attributes[3])\n        data = iris.transform(domain)\n        self.send_signal(widget.Inputs.data, data)\n        self.assertEqual({var.name for var in var_model},\n                         {var.name for var in domain.variables})\n        self.assertEqual(list(cvar_model),\n                         [None, DomainModel.Separator, iris.domain.class_var])\n        self.assertIs(widget.var, domain[0])\n        self.assertIs(widget.cvar, None)\n        np.testing.assert_equal(widget.valid_data, self.iris.X[:, 0])\n        self.assertIsNone(widget.valid_group_data)\n        self.assertEqual(\n            len(self.get_output(widget.Outputs.histogram_data)), 150)\n        self.assertIsNone(self.get_output(widget.Outputs.annotated_data))\n        self.assertIsNone(self.get_output(widget.Outputs.selected_data))\n\n    def test_set_data_reg_class_no_discrete(self):\n        \"\"\"Widget is properly set up with regression and no discrete vars\"\"\"\n        widget = self.widget\n        var_model = widget.controls.var.model()\n        cvar_model = widget.controls.cvar.model()\n        iris = self.iris\n\n        domain = Domain(iris.domain.attributes[:3], iris.domain.attributes[3])\n        data = iris.transform(domain)\n        self.send_signal(widget.Inputs.data, data)\n        self.assertEqual({var.name for var in var_model},\n                         {var.name for var in domain.variables})\n        self.assertEqual(list(cvar_model), [None])\n        self.assertIs(widget.var, domain[0])\n        self.assertIs(widget.cvar, None)\n        np.testing.assert_equal(widget.valid_data, self.iris.X[:, 0])\n        self.assertIsNone(widget.valid_group_data)\n        self.assertEqual(\n            len(self.get_output(widget.Outputs.histogram_data)), 150)\n        self.assertIsNone(self.get_output(widget.Outputs.annotated_data))\n        self.assertIsNone(self.get_output(widget.Outputs.selected_data))\n\n    def test_switch_var(self):\n        \"\"\"Widget reset and recomputes when changing var\"\"\"\n        widget = self.widget\n\n        self.send_signal(widget.Inputs.data, self.iris)\n        binnings = widget.binnings.copy()\n        valid_data = widget.valid_data.copy()\n        widget.selection.add(1)\n        widget._clear_plot = Mock()\n        widget.apply = Mock()\n\n        self._set_var(2)\n        self.assertFalse(binnings[0].shape == widget.binnings[0].shape\n                         and np.allclose(binnings[0], widget.binnings[0]))\n        self.assertFalse(valid_data.shape == widget.valid_data.shape\n                         and np.allclose(valid_data, widget.valid_data))\n        self.assertEqual(widget.selection, set())\n        widget._clear_plot.assert_called()\n        widget.apply.assert_called()\n\n    def test_switch_cvar(self):\n        \"\"\"Widget reset and recomputes when changing splitting variable\"\"\"\n        widget = self.widget\n\n        y = self.iris.domain.class_var\n        extra = DiscreteVariable(\"foo\", values=[\"a\", \"b\"])\n        domain = Domain(self.iris.domain.attributes + (extra, ), y)\n        data = self.iris.transform(domain)\n        data.X[:75, -1] = 0\n        data.X[75:120, -1] = 1\n        self.send_signal(widget.Inputs.data, data)\n        self._set_var(2)\n        self._set_cvar(y)\n\n        binnings = widget.binnings\n        valid_data = widget.valid_data.copy()\n        widget.selection.add(1)\n        widget._clear_plot = Mock()\n        widget.apply = Mock()\n\n        self.assertEqual(len(widget.valid_group_data), 150)\n\n        self._set_cvar(extra)\n        self.assertIs(binnings, widget.binnings)\n        np.testing.assert_equal(valid_data[:120], widget.valid_data)\n        self.assertEqual(len(widget.valid_group_data), 120)\n        self.assertEqual(widget.selection, {1})\n        widget._clear_plot.assert_called()\n        widget.apply.assert_called()\n        widget._clear_plot.reset_mock()\n        widget.apply.reset_mock()\n\n        self._set_cvar(None)\n        self.assertIs(binnings, widget.binnings)\n        np.testing.assert_equal(valid_data, widget.valid_data)\n        self.assertIsNone(widget.valid_group_data)\n        self.assertEqual(widget.selection, {1})\n        widget._clear_plot.assert_called()\n        widget.apply.assert_called()\n\n    def test_on_bins_changed(self):\n        \"\"\"Widget replots and outputs data when the number of bins is changed\"\"\"\n        widget = self.widget\n        self.send_signal(widget.Inputs.data, self.iris)\n\n        widget.number_of_bins = 0\n        widget.selection.add(1)\n        n_bars = len(widget.bar_items)\n        widget.apply = Mock()\n\n        self._set_slider(1)\n        self.assertEqual(widget.selection, set())\n        self.assertGreater(n_bars, len(widget.bar_items))\n        widget.apply.assert_called_once()\n\n    def test_set_valid_data(self):\n        \"\"\"Widget handles nans in data\"\"\"\n        widget = self.widget\n        err_def_var = widget.Error.no_defined_values_var\n        err_def_pair = widget.Error.no_defined_values_pair\n        warn_nans = widget.Warning.ignored_nans\n\n        domain = self.iris.domain\n\n        self.assertIsNone(widget.var)\n        self.assertIsNone(widget.cvar)\n        self.assertIsNone(widget.valid_data)\n        self.assertIsNone(widget.valid_group_data)\n        self.assertFalse(widget.is_valid)\n\n        widget.valid_data = Mock()\n        widget.group_valid_data = Mock()\n        widget.set_valid_data()\n        self.assertIsNone(widget.valid_data)\n        self.assertIsNone(widget.valid_group_data)\n        self.assertFalse(widget.is_valid)\n\n        self.send_signal(widget.Inputs.data, self.iris)\n        self.assertIsNotNone(widget.valid_data)\n        self.assertIsNotNone(widget.valid_group_data)\n        self.assertTrue(widget.is_valid)\n\n        X, Y = self.iris.X, self.iris.Y\n        X[:, 0] = np.nan\n        X[:50, 1] = np.nan\n        X[:100, 2] = np.nan\n        Y[75:] = np.nan\n        self.send_signal(widget.Inputs.data, self.iris)\n\n        self._set_var(domain[0])\n        self._set_cvar(domain.class_var)\n        self.assertIs(widget.var, domain[0])\n        self.assertIs(widget.cvar, domain.class_var)\n        self.assertIsNone(widget.valid_data)\n        self.assertIsNone(widget.valid_group_data)\n        self.assertFalse(widget.is_valid)\n        self.assertTrue(err_def_var.is_shown())\n        self.assertFalse(err_def_pair.is_shown())\n        self.assertFalse(warn_nans.is_shown())\n\n        self._set_var(domain[1])\n        self.assertIs(widget.var, domain[1])\n        self.assertIs(widget.cvar, domain.class_var)\n        np.testing.assert_equal(widget.valid_data, X[50:75, 1])\n        np.testing.assert_equal(widget.valid_group_data, Y[50:75])\n        self.assertTrue(widget.is_valid)\n        self.assertFalse(err_def_var.is_shown())\n        self.assertFalse(err_def_pair.is_shown())\n        self.assertTrue(warn_nans.is_shown())\n\n        self._set_var(domain[2])\n        self.assertIs(widget.var, domain[2])\n        self.assertIs(widget.cvar, domain.class_var)\n        self.assertIsNone(widget.valid_data)\n        self.assertIsNone(widget.valid_group_data)\n        self.assertFalse(widget.is_valid)\n        self.assertFalse(err_def_var.is_shown())\n        self.assertTrue(err_def_pair.is_shown())\n        self.assertFalse(warn_nans.is_shown())\n\n        self._set_var(domain[3])\n        self.assertIs(widget.var, domain[3])\n        self.assertIs(widget.cvar, domain.class_var)\n        np.testing.assert_equal(widget.valid_data, X[:75, 3])\n        np.testing.assert_equal(widget.valid_group_data, Y[:75])\n        self.assertTrue(widget.is_valid)\n        self.assertFalse(err_def_var.is_shown())\n        self.assertFalse(err_def_pair.is_shown())\n        self.assertTrue(warn_nans.is_shown())\n\n        self._set_var(domain[0])\n        self._set_cvar(None)\n        self.assertIs(widget.var, domain[0])\n        self.assertIsNone(widget.cvar)\n        self.assertIsNone(widget.valid_data)\n        self.assertIsNone(widget.valid_group_data)\n        self.assertFalse(widget.is_valid)\n        self.assertTrue(err_def_var.is_shown())\n        self.assertFalse(err_def_pair.is_shown())\n        self.assertFalse(warn_nans.is_shown())\n\n        self._set_var(domain[1])\n        self.assertIs(widget.var, domain[1])\n        self.assertIsNone(widget.cvar)\n        np.testing.assert_equal(widget.valid_data, X[50:, 1])\n        self.assertIsNone(widget.valid_group_data)\n        self.assertTrue(widget.is_valid)\n        self.assertFalse(err_def_var.is_shown())\n        self.assertFalse(err_def_pair.is_shown())\n        self.assertTrue(warn_nans.is_shown())\n\n        self._set_var(domain[3])\n        self.assertIs(widget.var, domain[3])\n        self.assertIsNone(widget.cvar)\n        np.testing.assert_equal(widget.valid_data, X[:, 3])\n        self.assertIsNone(widget.valid_group_data)\n        self.assertTrue(widget.is_valid)\n        self.assertFalse(err_def_var.is_shown())\n        self.assertFalse(err_def_pair.is_shown())\n        self.assertFalse(warn_nans.is_shown())\n\n    def test_controls_disabling(self):\n        \"\"\"Widget changes gui for continuous/discrete variables and grouping\"\"\"\n        widget = self.widget\n        self.send_signal(widget.Inputs.data, self.iris)\n\n        cont = self.iris.domain[0]\n        disc = self.iris.domain.class_var\n        cont_box = widget.continuous_box\n        show_probs = widget.controls.show_probs\n        stacked = widget.controls.stacked_columns\n\n        self._set_var(cont)\n        self._set_cvar(disc)\n        self.assertTrue(cont_box.isEnabled())\n        self.assertTrue(show_probs.isEnabled())\n        self.assertTrue(stacked.isEnabled())\n\n        self._set_var(cont)\n        self._set_cvar(None)\n        self.assertTrue(cont_box.isEnabled())\n        self.assertFalse(show_probs.isEnabled())\n        self.assertFalse(stacked.isEnabled())\n\n        self._set_var(disc)\n        self._set_cvar(None)\n        self.assertFalse(cont_box.isEnabled())\n        self.assertFalse(show_probs.isEnabled())\n        self.assertFalse(stacked.isEnabled())\n\n        self._set_var(disc)\n        self._set_cvar(disc)\n        self.assertFalse(cont_box.isEnabled())\n        self.assertTrue(show_probs.isEnabled())\n        self.assertTrue(stacked.isEnabled())\n\n    if os.getenv(\"CI\"):\n        # Testing all combinations takes 10-15 seconds; this should take < 2s\n        # Code for fitter, stacked_columns and show_probs is independent, so\n        # changing them simultaneously doesn't significantly degrade the tests\n        def test_plot_types_combinations(self):\n            \"\"\"Check that the widget doesn't crash at any plot combination\"\"\"\n            from AnyQt.QtWidgets import qApp\n\n            widget = self.widget\n            c = widget.controls\n            self.send_signal(widget.Inputs.data, self.iris)\n            cont = self.iris.domain[0]\n            disc = self.iris.domain.class_var\n            for var in (cont, disc):\n                for cvar in (disc, None):\n                    for b in [0, 1]:\n                        self._set_var(var)\n                        self._set_cvar(cvar)\n                        self._set_fitter(2 * b)\n                        self._set_check(c.stacked_columns, b)\n                        self._set_check(c.show_probs, b)\n                        qApp.processEvents()\n    else:\n        def test_plot_types_combinations(self):\n            \"\"\"Check that the widget doesn't crash at any plot combination\"\"\"\n            # pylint: disable=too-many-nested-blocks\n            from AnyQt.QtWidgets import qApp\n\n            widget = self.widget\n            c = widget.controls\n            self.send_signal(widget.Inputs.data, self.iris)\n            cont = self.iris.domain[0]\n            disc = self.iris.domain.class_var\n            for var in (cont, disc):\n                for cvar in (disc, None):\n                    for fitter in [0, 2]:\n                        for cumulative in [False, True]:\n                            for stack in [False, True]:\n                                for show_probs in [False, True]:\n                                    self._set_var(var)\n                                    self._set_cvar(cvar)\n                                    self._set_fitter(fitter)\n                                    self._set_check(c.cumulative_distr,\n                                                    cumulative)\n                                    self._set_check(c.stacked_columns, stack)\n                                    self._set_check(c.show_probs, show_probs)\n                                    qApp.processEvents()\n\n    def test_selection_grouping(self):\n        \"\"\"Widget groups consecutive selected bars\"\"\"\n        widget = self.widget\n        self.send_signal(widget.Inputs.data, self.iris)\n        self._set_slider(len(widget.binnings) - 1)\n        widget.selection = {1, 2, 3, 5, 6, 9}\n        widget.plot_mark.addItem = Mock()\n        widget.show_selection()\n        widget._on_end_selecting()\n        self.assertEqual(widget.plot_mark.addItem.call_count, 3)\n        out_selected = self.get_output(widget.Outputs.selected_data)\n        self.assertEqual(\n            len(out_selected.domain[ANNOTATED_DATA_FEATURE_NAME].values), 3)\n\n    def test_report(self):\n        \"\"\"Report doesn't crash\"\"\"\n        widget = self.widget\n        self.send_signal(widget.Inputs.data, self.iris)\n        widget.send_report()\n\n\nif __name__ == \"__main__\":\n    unittest.main()\n",
            "new_file_content": "# Test methods with long descriptive names can omit docstrings\n# pylint: disable=missing-docstring,protected-access\nimport os\nimport unittest\nfrom unittest.mock import Mock\n\nimport numpy as np\nfrom AnyQt.QtCore import QItemSelection\n\nfrom Orange.data import Table, Domain, DiscreteVariable\nfrom Orange.widgets.tests.base import WidgetTest\nfrom Orange.widgets.utils.annotated_data import ANNOTATED_DATA_FEATURE_NAME\nfrom Orange.widgets.utils.itemmodels import DomainModel\nfrom Orange.widgets.visualize.owdistributions import OWDistributions\n\n\nclass TestOWDistributions(WidgetTest):\n    def setUp(self):\n        self.widget = self.create_widget(OWDistributions)  #: OWDistributions\n        self.iris = Table(\"iris\")\n\n    def _set_cvar(self, cvar):\n        combo = self.widget.controls.cvar\n        self.widget.cvar = cvar\n        combo.activated[int].emit(combo.currentIndex())\n        combo.activated[str].emit(combo.currentText())\n\n    def _set_fitter(self, i):\n        combo = self.widget.controls.fitted_distribution\n        combo.setCurrentIndex(i)\n        combo.activated[int].emit(combo.currentIndex())\n        combo.activated[str].emit(combo.currentText())\n\n    def _set_var(self, var):\n        listview = self.widget.controls.var\n        model = listview.model()\n        index = var if isinstance(var, int) else model.indexOf(var)\n        selectionmodel = listview.selectionModel()\n        oldselection = selectionmodel.selection()\n        newselection = QItemSelection()\n        newselection.select(model.index(index, 0), model.index(index, 0))\n        selectionmodel.select(newselection, selectionmodel.ClearAndSelect)\n        selectionmodel.selectionChanged.emit(newselection, oldselection)\n\n    @staticmethod\n    def _set_check(checkbox, value):\n        checkbox.setCheckState(value)\n        checkbox.toggled[bool].emit(value)\n\n    def _set_slider(self, i):\n        slider = self.widget.controls.number_of_bins\n        slider.setValue(i)\n        slider.valueChanged[int].emit(i)\n        slider.sliderReleased.emit()\n\n    def test_set_data(self):\n        \"\"\"Basic test of set_data and removal of data\"\"\"\n        widget = self.widget\n        var_model = widget.controls.var.model()\n        cvar_model = widget.controls.cvar.model()\n\n        domain = self.iris.domain\n        self.send_signal(widget.Inputs.data, self.iris)\n        self.assertEqual({var.name for var in var_model},\n                         {var.name for var in domain.variables})\n        self.assertEqual(list(cvar_model),\n                         [None, DomainModel.Separator, domain.class_var])\n        self.assertIs(widget.var, domain[0])\n        self.assertIs(widget.cvar, domain.class_var)\n        np.testing.assert_equal(widget.valid_data, self.iris.X[:, 0])\n        np.testing.assert_equal(widget.valid_group_data, self.iris.Y)\n        self.assertEqual(\n            len(self.get_output(widget.Outputs.histogram_data)), 150)\n        self.assertIsNone(self.get_output(widget.Outputs.annotated_data))\n        self.assertIsNone(self.get_output(widget.Outputs.selected_data))\n\n        # Data gone: clean up\n        widget.selection.add(0)\n        widget._clear_plot = Mock()\n        self.send_signal(widget.Inputs.data, None)\n        self.assertEqual(len(var_model), 0)\n        self.assertEqual(list(cvar_model), [None])\n        self.assertIsNone(widget.var)\n        self.assertIsNone(widget.cvar)\n\n        self.assertEqual(widget.selection, set())\n        self.assertIsNone(widget.valid_data)\n        self.assertIsNone(widget.valid_group_data)\n        self.assertIsNone(self.get_output(widget.Outputs.histogram_data))\n        self.assertIsNone(self.get_output(widget.Outputs.annotated_data))\n        self.assertIsNone(self.get_output(widget.Outputs.selected_data))\n        widget._clear_plot.assert_called()\n\n    def test_set_data_no_class_no_discrete(self):\n        \"\"\"Widget is properly set up when there is no class and discrete vars\"\"\"\n        widget = self.widget\n        var_model = widget.controls.var.model()\n        cvar_model = widget.controls.cvar.model()\n\n        domain = Domain(self.iris.domain.attributes, [])\n        data = self.iris.transform(domain)\n        self.send_signal(widget.Inputs.data, data)\n        self.assertEqual({var.name for var in var_model},\n                         {var.name for var in domain.attributes})\n        self.assertEqual(list(cvar_model), [None])\n        self.assertIs(widget.var, domain[0])\n        self.assertIs(widget.cvar, None)\n        np.testing.assert_equal(widget.valid_data, self.iris.X[:, 0])\n        self.assertIsNone(widget.valid_group_data)\n        self.assertEqual(\n            len(self.get_output(widget.Outputs.histogram_data)), 150)\n        self.assertIsNone(self.get_output(widget.Outputs.annotated_data))\n        self.assertIsNone(self.get_output(widget.Outputs.selected_data))\n\n    def test_set_data_no_class(self):\n        \"\"\"Widget is properly set up when there is no class\"\"\"\n        widget = self.widget\n        var_model = widget.controls.var.model()\n        cvar_model = widget.controls.cvar.model()\n        iris = self.iris\n\n        domain = Domain(iris.domain.attributes + iris.domain.class_vars)\n        data = iris.transform(domain)\n        self.send_signal(widget.Inputs.data, data)\n        self.assertEqual({var.name for var in var_model},\n                         {var.name for var in domain.attributes})\n        self.assertEqual(list(cvar_model),\n                         [None, DomainModel.Separator, iris.domain.class_var])\n        self.assertIs(widget.var, domain[0])\n        self.assertIs(widget.cvar, None)\n        np.testing.assert_equal(widget.valid_data, self.iris.X[:, 0])\n        self.assertIsNone(widget.valid_group_data)\n        self.assertEqual(\n            len(self.get_output(widget.Outputs.histogram_data)), 150)\n        self.assertIsNone(self.get_output(widget.Outputs.annotated_data))\n        self.assertIsNone(self.get_output(widget.Outputs.selected_data))\n\n    def test_set_data_reg_class(self):\n        \"\"\"Widget is properly set up when the target is numeric\"\"\"\n        widget = self.widget\n        var_model = widget.controls.var.model()\n        cvar_model = widget.controls.cvar.model()\n        iris = self.iris\n\n        domain = Domain(iris.domain.attributes[:3] + iris.domain.class_vars,\n                        iris.domain.attributes[3])\n        data = iris.transform(domain)\n        self.send_signal(widget.Inputs.data, data)\n        self.assertEqual({var.name for var in var_model},\n                         {var.name for var in domain.variables})\n        self.assertEqual(list(cvar_model),\n                         [None, DomainModel.Separator, iris.domain.class_var])\n        self.assertIs(widget.var, domain[0])\n        self.assertIs(widget.cvar, None)\n        np.testing.assert_equal(widget.valid_data, self.iris.X[:, 0])\n        self.assertIsNone(widget.valid_group_data)\n        self.assertEqual(\n            len(self.get_output(widget.Outputs.histogram_data)), 150)\n        self.assertIsNone(self.get_output(widget.Outputs.annotated_data))\n        self.assertIsNone(self.get_output(widget.Outputs.selected_data))\n\n    def test_set_data_reg_class_no_discrete(self):\n        \"\"\"Widget is properly set up with regression and no discrete vars\"\"\"\n        widget = self.widget\n        var_model = widget.controls.var.model()\n        cvar_model = widget.controls.cvar.model()\n        iris = self.iris\n\n        domain = Domain(iris.domain.attributes[:3], iris.domain.attributes[3])\n        data = iris.transform(domain)\n        self.send_signal(widget.Inputs.data, data)\n        self.assertEqual({var.name for var in var_model},\n                         {var.name for var in domain.variables})\n        self.assertEqual(list(cvar_model), [None])\n        self.assertIs(widget.var, domain[0])\n        self.assertIs(widget.cvar, None)\n        np.testing.assert_equal(widget.valid_data, self.iris.X[:, 0])\n        self.assertIsNone(widget.valid_group_data)\n        self.assertEqual(\n            len(self.get_output(widget.Outputs.histogram_data)), 150)\n        self.assertIsNone(self.get_output(widget.Outputs.annotated_data))\n        self.assertIsNone(self.get_output(widget.Outputs.selected_data))\n\n    def test_switch_var(self):\n        \"\"\"Widget reset and recomputes when changing var\"\"\"\n        widget = self.widget\n\n        self.send_signal(widget.Inputs.data, self.iris)\n        binnings = widget.binnings.copy()\n        valid_data = widget.valid_data.copy()\n        widget.selection.add(1)\n        widget._clear_plot = Mock()\n        widget.apply = Mock()\n\n        self._set_var(2)\n        self.assertFalse(binnings[0].shape == widget.binnings[0].shape\n                         and np.allclose(binnings[0], widget.binnings[0]))\n        self.assertFalse(valid_data.shape == widget.valid_data.shape\n                         and np.allclose(valid_data, widget.valid_data))\n        self.assertEqual(widget.selection, set())\n        widget._clear_plot.assert_called()\n        widget.apply.assert_called()\n\n    def test_switch_cvar(self):\n        \"\"\"Widget reset and recomputes when changing splitting variable\"\"\"\n        widget = self.widget\n\n        y = self.iris.domain.class_var\n        extra = DiscreteVariable(\"foo\", values=[\"a\", \"b\"])\n        domain = Domain(self.iris.domain.attributes + (extra, ), y)\n        data = self.iris.transform(domain)\n        data.X[:75, -1] = 0\n        data.X[75:120, -1] = 1\n        self.send_signal(widget.Inputs.data, data)\n        self._set_var(2)\n        self._set_cvar(y)\n\n        binnings = widget.binnings\n        valid_data = widget.valid_data.copy()\n        widget.selection.add(1)\n        widget._clear_plot = Mock()\n        widget.apply = Mock()\n\n        self.assertEqual(len(widget.valid_group_data), 150)\n\n        self._set_cvar(extra)\n        self.assertIs(binnings, widget.binnings)\n        np.testing.assert_equal(valid_data[:120], widget.valid_data)\n        self.assertEqual(len(widget.valid_group_data), 120)\n        self.assertEqual(widget.selection, {1})\n        widget._clear_plot.assert_called()\n        widget.apply.assert_called()\n        widget._clear_plot.reset_mock()\n        widget.apply.reset_mock()\n\n        self._set_cvar(None)\n        self.assertIs(binnings, widget.binnings)\n        np.testing.assert_equal(valid_data, widget.valid_data)\n        self.assertIsNone(widget.valid_group_data)\n        self.assertEqual(widget.selection, {1})\n        widget._clear_plot.assert_called()\n        widget.apply.assert_called()\n\n    def test_on_bins_changed(self):\n        \"\"\"Widget replots and outputs data when the number of bins is changed\"\"\"\n        widget = self.widget\n        self.send_signal(widget.Inputs.data, self.iris)\n\n        self._set_slider(0)\n        widget.selection.add(1)\n        n_bars = len(widget.bar_items)\n        widget.apply = Mock()\n\n        self._set_slider(1)\n        self.assertEqual(widget.selection, set())\n        self.assertGreater(n_bars, len(widget.bar_items))\n        widget.apply.assert_called_once()\n\n    def test_set_valid_data(self):\n        \"\"\"Widget handles nans in data\"\"\"\n        widget = self.widget\n        err_def_var = widget.Error.no_defined_values_var\n        err_def_pair = widget.Error.no_defined_values_pair\n        warn_nans = widget.Warning.ignored_nans\n\n        domain = self.iris.domain\n\n        self.assertIsNone(widget.var)\n        self.assertIsNone(widget.cvar)\n        self.assertIsNone(widget.valid_data)\n        self.assertIsNone(widget.valid_group_data)\n        self.assertFalse(widget.is_valid)\n\n        widget.valid_data = Mock()\n        widget.group_valid_data = Mock()\n        widget.set_valid_data()\n        self.assertIsNone(widget.valid_data)\n        self.assertIsNone(widget.valid_group_data)\n        self.assertFalse(widget.is_valid)\n\n        self.send_signal(widget.Inputs.data, self.iris)\n        self.assertIsNotNone(widget.valid_data)\n        self.assertIsNotNone(widget.valid_group_data)\n        self.assertTrue(widget.is_valid)\n\n        X, Y = self.iris.X, self.iris.Y\n        X[:, 0] = np.nan\n        X[:50, 1] = np.nan\n        X[:100, 2] = np.nan\n        Y[75:] = np.nan\n        self.send_signal(widget.Inputs.data, self.iris)\n\n        self._set_var(domain[0])\n        self._set_cvar(domain.class_var)\n        self.assertIs(widget.var, domain[0])\n        self.assertIs(widget.cvar, domain.class_var)\n        self.assertIsNone(widget.valid_data)\n        self.assertIsNone(widget.valid_group_data)\n        self.assertFalse(widget.is_valid)\n        self.assertTrue(err_def_var.is_shown())\n        self.assertFalse(err_def_pair.is_shown())\n        self.assertFalse(warn_nans.is_shown())\n\n        self._set_var(domain[1])\n        self.assertIs(widget.var, domain[1])\n        self.assertIs(widget.cvar, domain.class_var)\n        np.testing.assert_equal(widget.valid_data, X[50:75, 1])\n        np.testing.assert_equal(widget.valid_group_data, Y[50:75])\n        self.assertTrue(widget.is_valid)\n        self.assertFalse(err_def_var.is_shown())\n        self.assertFalse(err_def_pair.is_shown())\n        self.assertTrue(warn_nans.is_shown())\n\n        self._set_var(domain[2])\n        self.assertIs(widget.var, domain[2])\n        self.assertIs(widget.cvar, domain.class_var)\n        self.assertIsNone(widget.valid_data)\n        self.assertIsNone(widget.valid_group_data)\n        self.assertFalse(widget.is_valid)\n        self.assertFalse(err_def_var.is_shown())\n        self.assertTrue(err_def_pair.is_shown())\n        self.assertFalse(warn_nans.is_shown())\n\n        self._set_var(domain[3])\n        self.assertIs(widget.var, domain[3])\n        self.assertIs(widget.cvar, domain.class_var)\n        np.testing.assert_equal(widget.valid_data, X[:75, 3])\n        np.testing.assert_equal(widget.valid_group_data, Y[:75])\n        self.assertTrue(widget.is_valid)\n        self.assertFalse(err_def_var.is_shown())\n        self.assertFalse(err_def_pair.is_shown())\n        self.assertTrue(warn_nans.is_shown())\n\n        self._set_var(domain[0])\n        self._set_cvar(None)\n        self.assertIs(widget.var, domain[0])\n        self.assertIsNone(widget.cvar)\n        self.assertIsNone(widget.valid_data)\n        self.assertIsNone(widget.valid_group_data)\n        self.assertFalse(widget.is_valid)\n        self.assertTrue(err_def_var.is_shown())\n        self.assertFalse(err_def_pair.is_shown())\n        self.assertFalse(warn_nans.is_shown())\n\n        self._set_var(domain[1])\n        self.assertIs(widget.var, domain[1])\n        self.assertIsNone(widget.cvar)\n        np.testing.assert_equal(widget.valid_data, X[50:, 1])\n        self.assertIsNone(widget.valid_group_data)\n        self.assertTrue(widget.is_valid)\n        self.assertFalse(err_def_var.is_shown())\n        self.assertFalse(err_def_pair.is_shown())\n        self.assertTrue(warn_nans.is_shown())\n\n        self._set_var(domain[3])\n        self.assertIs(widget.var, domain[3])\n        self.assertIsNone(widget.cvar)\n        np.testing.assert_equal(widget.valid_data, X[:, 3])\n        self.assertIsNone(widget.valid_group_data)\n        self.assertTrue(widget.is_valid)\n        self.assertFalse(err_def_var.is_shown())\n        self.assertFalse(err_def_pair.is_shown())\n        self.assertFalse(warn_nans.is_shown())\n\n    def test_controls_disabling(self):\n        \"\"\"Widget changes gui for continuous/discrete variables and grouping\"\"\"\n        widget = self.widget\n        self.send_signal(widget.Inputs.data, self.iris)\n\n        cont = self.iris.domain[0]\n        disc = self.iris.domain.class_var\n        cont_box = widget.continuous_box\n        show_probs = widget.controls.show_probs\n        stacked = widget.controls.stacked_columns\n\n        self._set_var(cont)\n        self._set_cvar(disc)\n        self.assertTrue(cont_box.isEnabled())\n        self.assertTrue(show_probs.isEnabled())\n        self.assertTrue(stacked.isEnabled())\n\n        self._set_var(cont)\n        self._set_cvar(None)\n        self.assertTrue(cont_box.isEnabled())\n        self.assertFalse(show_probs.isEnabled())\n        self.assertFalse(stacked.isEnabled())\n\n        self._set_var(disc)\n        self._set_cvar(None)\n        self.assertFalse(cont_box.isEnabled())\n        self.assertFalse(show_probs.isEnabled())\n        self.assertFalse(stacked.isEnabled())\n\n        self._set_var(disc)\n        self._set_cvar(disc)\n        self.assertFalse(cont_box.isEnabled())\n        self.assertTrue(show_probs.isEnabled())\n        self.assertTrue(stacked.isEnabled())\n\n    if os.getenv(\"CI\"):\n        # Testing all combinations takes 10-15 seconds; this should take < 2s\n        # Code for fitter, stacked_columns and show_probs is independent, so\n        # changing them simultaneously doesn't significantly degrade the tests\n        def test_plot_types_combinations(self):\n            \"\"\"Check that the widget doesn't crash at any plot combination\"\"\"\n            from AnyQt.QtWidgets import qApp\n\n            widget = self.widget\n            c = widget.controls\n            self.send_signal(widget.Inputs.data, self.iris)\n            cont = self.iris.domain[0]\n            disc = self.iris.domain.class_var\n            for var in (cont, disc):\n                for cvar in (disc, None):\n                    for b in [0, 1]:\n                        self._set_var(var)\n                        self._set_cvar(cvar)\n                        self._set_fitter(2 * b)\n                        self._set_check(c.stacked_columns, b)\n                        self._set_check(c.show_probs, b)\n                        qApp.processEvents()\n    else:\n        def test_plot_types_combinations(self):\n            \"\"\"Check that the widget doesn't crash at any plot combination\"\"\"\n            # pylint: disable=too-many-nested-blocks\n            from AnyQt.QtWidgets import qApp\n\n            widget = self.widget\n            c = widget.controls\n            self.send_signal(widget.Inputs.data, self.iris)\n            cont = self.iris.domain[0]\n            disc = self.iris.domain.class_var\n            for var in (cont, disc):\n                for cvar in (disc, None):\n                    for fitter in [0, 2]:\n                        for cumulative in [False, True]:\n                            for stack in [False, True]:\n                                for show_probs in [False, True]:\n                                    self._set_var(var)\n                                    self._set_cvar(cvar)\n                                    self._set_fitter(fitter)\n                                    self._set_check(c.cumulative_distr,\n                                                    cumulative)\n                                    self._set_check(c.stacked_columns, stack)\n                                    self._set_check(c.show_probs, show_probs)\n                                    qApp.processEvents()\n\n    def test_selection_grouping(self):\n        \"\"\"Widget groups consecutive selected bars\"\"\"\n        widget = self.widget\n        self.send_signal(widget.Inputs.data, self.iris)\n        self._set_slider(0)\n        widget.selection = {1, 2, 3, 5, 6, 9}\n        widget.plot_mark.addItem = Mock()\n        widget.show_selection()\n        widget._on_end_selecting()\n        self.assertEqual(widget.plot_mark.addItem.call_count, 3)\n        out_selected = self.get_output(widget.Outputs.selected_data)\n        self.assertEqual(\n            len(out_selected.domain[ANNOTATED_DATA_FEATURE_NAME].values), 3)\n\n    def test_report(self):\n        \"\"\"Report doesn't crash\"\"\"\n        widget = self.widget\n        self.send_signal(widget.Inputs.data, self.iris)\n        widget.send_report()\n\n\nif __name__ == \"__main__\":\n    unittest.main()\n",
            "header": {
                "file": {
                    "path": "Orange/widgets/visualize/tests/test_owdistributions.py"
                },
                "misc_line": null
            },
            "index_line": {
                "old_commit_hash": "5408deef0",
                "new_commit_hash": "265a78a42",
                "mode": "100644"
            },
            "is_binary_file": false,
            "binary_line": null,
            "minus_file": {
                "path": "a/Orange/widgets/visualize/tests/test_owdistributions.py"
            },
            "plus_file": {
                "path": "b/Orange/widgets/visualize/tests/test_owdistributions.py"
            },
            "hunks": [
                {
                    "descriptor": {
                        "old_range": {
                            "start": 246,
                            "length": 7
                        },
                        "new_range": {
                            "start": 246,
                            "length": 7
                        },
                        "section": "class TestOWDistributions(WidgetTest):"
                    },
                    "line_group": {
                        "all_lines": [
                            {
                                "content": "        widget = self.widget",
                                "type": "context"
                            },
                            {
                                "content": "        self.send_signal(widget.Inputs.data, self.iris)",
                                "type": "context"
                            },
                            {
                                "content": "",
                                "type": "context"
                            },
                            {
                                "content": "        widget.number_of_bins = 0",
                                "type": "deleted"
                            },
                            {
                                "content": "        self._set_slider(0)",
                                "type": "added"
                            },
                            {
                                "content": "        widget.selection.add(1)",
                                "type": "context"
                            },
                            {
                                "content": "        n_bars = len(widget.bar_items)",
                                "type": "context"
                            },
                            {
                                "content": "        widget.apply = Mock()",
                                "type": "context"
                            }
                        ]
                    },
                    "modified_entities": [
                        {
                            "file_name": "Orange/widgets/visualize/tests/test_owdistributions.py",
                            "type": "class",
                            "name": "TestOWDistributions",
                            "content": "class TestOWDistributions(WidgetTest):\n    def setUp(self):\n        self.widget = self.create_widget(OWDistributions)  #: OWDistributions\n        self.iris = Table(\"iris\")\n\n    def _set_cvar(self, cvar):\n        combo = self.widget.controls.cvar\n        self.widget.cvar = cvar\n        combo.activated[int].emit(combo.currentIndex())\n        combo.activated[str].emit(combo.currentText())\n\n    def _set_fitter(self, i):\n        combo = self.widget.controls.fitted_distribution\n        combo.setCurrentIndex(i)\n        combo.activated[int].emit(combo.currentIndex())\n        combo.activated[str].emit(combo.currentText())\n\n    def _set_var(self, var):\n        listview = self.widget.controls.var\n        model = listview.model()\n        index = var if isinstance(var, int) else model.indexOf(var)\n        selectionmodel = listview.selectionModel()\n        oldselection = selectionmodel.selection()\n        newselection = QItemSelection()\n        newselection.select(model.index(index, 0), model.index(index, 0))\n        selectionmodel.select(newselection, selectionmodel.ClearAndSelect)\n        selectionmodel.selectionChanged.emit(newselection, oldselection)\n\n    @staticmethod\n    def _set_check(checkbox, value):\n        checkbox.setCheckState(value)\n        checkbox.toggled[bool].emit(value)\n\n    def _set_slider(self, i):\n        slider = self.widget.controls.number_of_bins\n        slider.setValue(i)\n        slider.valueChanged[int].emit(i)\n        slider.sliderReleased.emit()\n\n    def test_set_data(self):\n        \"\"\"Basic test of set_data and removal of data\"\"\"\n        widget = self.widget\n        var_model = widget.controls.var.model()\n        cvar_model = widget.controls.cvar.model()\n\n        domain = self.iris.domain\n        self.send_signal(widget.Inputs.data, self.iris)\n        self.assertEqual({var.name for var in var_model},\n                         {var.name for var in domain.variables})\n        self.assertEqual(list(cvar_model),\n                         [None, DomainModel.Separator, domain.class_var])\n        self.assertIs(widget.var, domain[0])\n        self.assertIs(widget.cvar, domain.class_var)\n        np.testing.assert_equal(widget.valid_data, self.iris.X[:, 0])\n        np.testing.assert_equal(widget.valid_group_data, self.iris.Y)\n        self.assertEqual(\n            len(self.get_output(widget.Outputs.histogram_data)), 150)\n        self.assertIsNone(self.get_output(widget.Outputs.annotated_data))\n        self.assertIsNone(self.get_output(widget.Outputs.selected_data))\n\n        # Data gone: clean up\n        widget.selection.add(0)\n        widget._clear_plot = Mock()\n        self.send_signal(widget.Inputs.data, None)\n        self.assertEqual(len(var_model), 0)\n        self.assertEqual(list(cvar_model), [None])\n        self.assertIsNone(widget.var)\n        self.assertIsNone(widget.cvar)\n\n        self.assertEqual(widget.selection, set())\n        self.assertIsNone(widget.valid_data)\n        self.assertIsNone(widget.valid_group_data)\n        self.assertIsNone(self.get_output(widget.Outputs.histogram_data))\n        self.assertIsNone(self.get_output(widget.Outputs.annotated_data))\n        self.assertIsNone(self.get_output(widget.Outputs.selected_data))\n        widget._clear_plot.assert_called()\n\n    def test_set_data_no_class_no_discrete(self):\n        \"\"\"Widget is properly set up when there is no class and discrete vars\"\"\"\n        widget = self.widget\n        var_model = widget.controls.var.model()\n        cvar_model = widget.controls.cvar.model()\n\n        domain = Domain(self.iris.domain.attributes, [])\n        data = self.iris.transform(domain)\n        self.send_signal(widget.Inputs.data, data)\n        self.assertEqual({var.name for var in var_model},\n                         {var.name for var in domain.attributes})\n        self.assertEqual(list(cvar_model), [None])\n        self.assertIs(widget.var, domain[0])\n        self.assertIs(widget.cvar, None)\n        np.testing.assert_equal(widget.valid_data, self.iris.X[:, 0])\n        self.assertIsNone(widget.valid_group_data)\n        self.assertEqual(\n            len(self.get_output(widget.Outputs.histogram_data)), 150)\n        self.assertIsNone(self.get_output(widget.Outputs.annotated_data))\n        self.assertIsNone(self.get_output(widget.Outputs.selected_data))\n\n    def test_set_data_no_class(self):\n        \"\"\"Widget is properly set up when there is no class\"\"\"\n        widget = self.widget\n        var_model = widget.controls.var.model()\n        cvar_model = widget.controls.cvar.model()\n        iris = self.iris\n\n        domain = Domain(iris.domain.attributes + iris.domain.class_vars)\n        data = iris.transform(domain)\n        self.send_signal(widget.Inputs.data, data)\n        self.assertEqual({var.name for var in var_model},\n                         {var.name for var in domain.attributes})\n        self.assertEqual(list(cvar_model),\n                         [None, DomainModel.Separator, iris.domain.class_var])\n        self.assertIs(widget.var, domain[0])\n        self.assertIs(widget.cvar, None)\n        np.testing.assert_equal(widget.valid_data, self.iris.X[:, 0])\n        self.assertIsNone(widget.valid_group_data)\n        self.assertEqual(\n            len(self.get_output(widget.Outputs.histogram_data)), 150)\n        self.assertIsNone(self.get_output(widget.Outputs.annotated_data))\n        self.assertIsNone(self.get_output(widget.Outputs.selected_data))\n\n    def test_set_data_reg_class(self):\n        \"\"\"Widget is properly set up when the target is numeric\"\"\"\n        widget = self.widget\n        var_model = widget.controls.var.model()\n        cvar_model = widget.controls.cvar.model()\n        iris = self.iris\n\n        domain = Domain(iris.domain.attributes[:3] + iris.domain.class_vars,\n                        iris.domain.attributes[3])\n        data = iris.transform(domain)\n        self.send_signal(widget.Inputs.data, data)\n        self.assertEqual({var.name for var in var_model},\n                         {var.name for var in domain.variables})\n        self.assertEqual(list(cvar_model),\n                         [None, DomainModel.Separator, iris.domain.class_var])\n        self.assertIs(widget.var, domain[0])\n        self.assertIs(widget.cvar, None)\n        np.testing.assert_equal(widget.valid_data, self.iris.X[:, 0])\n        self.assertIsNone(widget.valid_group_data)\n        self.assertEqual(\n            len(self.get_output(widget.Outputs.histogram_data)), 150)\n        self.assertIsNone(self.get_output(widget.Outputs.annotated_data))\n        self.assertIsNone(self.get_output(widget.Outputs.selected_data))\n\n    def test_set_data_reg_class_no_discrete(self):\n        \"\"\"Widget is properly set up with regression and no discrete vars\"\"\"\n        widget = self.widget\n        var_model = widget.controls.var.model()\n        cvar_model = widget.controls.cvar.model()\n        iris = self.iris\n\n        domain = Domain(iris.domain.attributes[:3], iris.domain.attributes[3])\n        data = iris.transform(domain)\n        self.send_signal(widget.Inputs.data, data)\n        self.assertEqual({var.name for var in var_model},\n                         {var.name for var in domain.variables})\n        self.assertEqual(list(cvar_model), [None])\n        self.assertIs(widget.var, domain[0])\n        self.assertIs(widget.cvar, None)\n        np.testing.assert_equal(widget.valid_data, self.iris.X[:, 0])\n        self.assertIsNone(widget.valid_group_data)\n        self.assertEqual(\n            len(self.get_output(widget.Outputs.histogram_data)), 150)\n        self.assertIsNone(self.get_output(widget.Outputs.annotated_data))\n        self.assertIsNone(self.get_output(widget.Outputs.selected_data))\n\n    def test_switch_var(self):\n        \"\"\"Widget reset and recomputes when changing var\"\"\"\n        widget = self.widget\n\n        self.send_signal(widget.Inputs.data, self.iris)\n        binnings = widget.binnings.copy()\n        valid_data = widget.valid_data.copy()\n        widget.selection.add(1)\n        widget._clear_plot = Mock()\n        widget.apply = Mock()\n\n        self._set_var(2)\n        self.assertFalse(binnings[0].shape == widget.binnings[0].shape\n                         and np.allclose(binnings[0], widget.binnings[0]))\n        self.assertFalse(valid_data.shape == widget.valid_data.shape\n                         and np.allclose(valid_data, widget.valid_data))\n        self.assertEqual(widget.selection, set())\n        widget._clear_plot.assert_called()\n        widget.apply.assert_called()\n\n    def test_switch_cvar(self):\n        \"\"\"Widget reset and recomputes when changing splitting variable\"\"\"\n        widget = self.widget\n\n        y = self.iris.domain.class_var\n        extra = DiscreteVariable(\"foo\", values=[\"a\", \"b\"])\n        domain = Domain(self.iris.domain.attributes + (extra, ), y)\n        data = self.iris.transform(domain)\n        data.X[:75, -1] = 0\n        data.X[75:120, -1] = 1\n        self.send_signal(widget.Inputs.data, data)\n        self._set_var(2)\n        self._set_cvar(y)\n\n        binnings = widget.binnings\n        valid_data = widget.valid_data.copy()\n        widget.selection.add(1)\n        widget._clear_plot = Mock()\n        widget.apply = Mock()\n\n        self.assertEqual(len(widget.valid_group_data), 150)\n\n        self._set_cvar(extra)\n        self.assertIs(binnings, widget.binnings)\n        np.testing.assert_equal(valid_data[:120], widget.valid_data)\n        self.assertEqual(len(widget.valid_group_data), 120)\n        self.assertEqual(widget.selection, {1})\n        widget._clear_plot.assert_called()\n        widget.apply.assert_called()\n        widget._clear_plot.reset_mock()\n        widget.apply.reset_mock()\n\n        self._set_cvar(None)\n        self.assertIs(binnings, widget.binnings)\n        np.testing.assert_equal(valid_data, widget.valid_data)\n        self.assertIsNone(widget.valid_group_data)\n        self.assertEqual(widget.selection, {1})\n        widget._clear_plot.assert_called()\n        widget.apply.assert_called()\n\n    def test_on_bins_changed(self):\n        \"\"\"Widget replots and outputs data when the number of bins is changed\"\"\"\n        widget = self.widget\n        self.send_signal(widget.Inputs.data, self.iris)\n\n        widget.number_of_bins = 0\n        widget.selection.add(1)\n        n_bars = len(widget.bar_items)\n        widget.apply = Mock()\n\n        self._set_slider(1)\n        self.assertEqual(widget.selection, set())\n        self.assertGreater(n_bars, len(widget.bar_items))\n        widget.apply.assert_called_once()\n\n    def test_set_valid_data(self):\n        \"\"\"Widget handles nans in data\"\"\"\n        widget = self.widget\n        err_def_var = widget.Error.no_defined_values_var\n        err_def_pair = widget.Error.no_defined_values_pair\n        warn_nans = widget.Warning.ignored_nans\n\n        domain = self.iris.domain\n\n        self.assertIsNone(widget.var)\n        self.assertIsNone(widget.cvar)\n        self.assertIsNone(widget.valid_data)\n        self.assertIsNone(widget.valid_group_data)\n        self.assertFalse(widget.is_valid)\n\n        widget.valid_data = Mock()\n        widget.group_valid_data = Mock()\n        widget.set_valid_data()\n        self.assertIsNone(widget.valid_data)\n        self.assertIsNone(widget.valid_group_data)\n        self.assertFalse(widget.is_valid)\n\n        self.send_signal(widget.Inputs.data, self.iris)\n        self.assertIsNotNone(widget.valid_data)\n        self.assertIsNotNone(widget.valid_group_data)\n        self.assertTrue(widget.is_valid)\n\n        X, Y = self.iris.X, self.iris.Y\n        X[:, 0] = np.nan\n        X[:50, 1] = np.nan\n        X[:100, 2] = np.nan\n        Y[75:] = np.nan\n        self.send_signal(widget.Inputs.data, self.iris)\n\n        self._set_var(domain[0])\n        self._set_cvar(domain.class_var)\n        self.assertIs(widget.var, domain[0])\n        self.assertIs(widget.cvar, domain.class_var)\n        self.assertIsNone(widget.valid_data)\n        self.assertIsNone(widget.valid_group_data)\n        self.assertFalse(widget.is_valid)\n        self.assertTrue(err_def_var.is_shown())\n        self.assertFalse(err_def_pair.is_shown())\n        self.assertFalse(warn_nans.is_shown())\n\n        self._set_var(domain[1])\n        self.assertIs(widget.var, domain[1])\n        self.assertIs(widget.cvar, domain.class_var)\n        np.testing.assert_equal(widget.valid_data, X[50:75, 1])\n        np.testing.assert_equal(widget.valid_group_data, Y[50:75])\n        self.assertTrue(widget.is_valid)\n        self.assertFalse(err_def_var.is_shown())\n        self.assertFalse(err_def_pair.is_shown())\n        self.assertTrue(warn_nans.is_shown())\n\n        self._set_var(domain[2])\n        self.assertIs(widget.var, domain[2])\n        self.assertIs(widget.cvar, domain.class_var)\n        self.assertIsNone(widget.valid_data)\n        self.assertIsNone(widget.valid_group_data)\n        self.assertFalse(widget.is_valid)\n        self.assertFalse(err_def_var.is_shown())\n        self.assertTrue(err_def_pair.is_shown())\n        self.assertFalse(warn_nans.is_shown())\n\n        self._set_var(domain[3])\n        self.assertIs(widget.var, domain[3])\n        self.assertIs(widget.cvar, domain.class_var)\n        np.testing.assert_equal(widget.valid_data, X[:75, 3])\n        np.testing.assert_equal(widget.valid_group_data, Y[:75])\n        self.assertTrue(widget.is_valid)\n        self.assertFalse(err_def_var.is_shown())\n        self.assertFalse(err_def_pair.is_shown())\n        self.assertTrue(warn_nans.is_shown())\n\n        self._set_var(domain[0])\n        self._set_cvar(None)\n        self.assertIs(widget.var, domain[0])\n        self.assertIsNone(widget.cvar)\n        self.assertIsNone(widget.valid_data)\n        self.assertIsNone(widget.valid_group_data)\n        self.assertFalse(widget.is_valid)\n        self.assertTrue(err_def_var.is_shown())\n        self.assertFalse(err_def_pair.is_shown())\n        self.assertFalse(warn_nans.is_shown())\n\n        self._set_var(domain[1])\n        self.assertIs(widget.var, domain[1])\n        self.assertIsNone(widget.cvar)\n        np.testing.assert_equal(widget.valid_data, X[50:, 1])\n        self.assertIsNone(widget.valid_group_data)\n        self.assertTrue(widget.is_valid)\n        self.assertFalse(err_def_var.is_shown())\n        self.assertFalse(err_def_pair.is_shown())\n        self.assertTrue(warn_nans.is_shown())\n\n        self._set_var(domain[3])\n        self.assertIs(widget.var, domain[3])\n        self.assertIsNone(widget.cvar)\n        np.testing.assert_equal(widget.valid_data, X[:, 3])\n        self.assertIsNone(widget.valid_group_data)\n        self.assertTrue(widget.is_valid)\n        self.assertFalse(err_def_var.is_shown())\n        self.assertFalse(err_def_pair.is_shown())\n        self.assertFalse(warn_nans.is_shown())\n\n    def test_controls_disabling(self):\n        \"\"\"Widget changes gui for continuous/discrete variables and grouping\"\"\"\n        widget = self.widget\n        self.send_signal(widget.Inputs.data, self.iris)\n\n        cont = self.iris.domain[0]\n        disc = self.iris.domain.class_var\n        cont_box = widget.continuous_box\n        show_probs = widget.controls.show_probs\n        stacked = widget.controls.stacked_columns\n\n        self._set_var(cont)\n        self._set_cvar(disc)\n        self.assertTrue(cont_box.isEnabled())\n        self.assertTrue(show_probs.isEnabled())\n        self.assertTrue(stacked.isEnabled())\n\n        self._set_var(cont)\n        self._set_cvar(None)\n        self.assertTrue(cont_box.isEnabled())\n        self.assertFalse(show_probs.isEnabled())\n        self.assertFalse(stacked.isEnabled())\n\n        self._set_var(disc)\n        self._set_cvar(None)\n        self.assertFalse(cont_box.isEnabled())\n        self.assertFalse(show_probs.isEnabled())\n        self.assertFalse(stacked.isEnabled())\n\n        self._set_var(disc)\n        self._set_cvar(disc)\n        self.assertFalse(cont_box.isEnabled())\n        self.assertTrue(show_probs.isEnabled())\n        self.assertTrue(stacked.isEnabled())\n\n    if os.getenv(\"CI\"):\n        # Testing all combinations takes 10-15 seconds; this should take < 2s\n        # Code for fitter, stacked_columns and show_probs is independent, so\n        # changing them simultaneously doesn't significantly degrade the tests\n        def test_plot_types_combinations(self):\n            \"\"\"Check that the widget doesn't crash at any plot combination\"\"\"\n            from AnyQt.QtWidgets import qApp\n\n            widget = self.widget\n            c = widget.controls\n            self.send_signal(widget.Inputs.data, self.iris)\n            cont = self.iris.domain[0]\n            disc = self.iris.domain.class_var\n            for var in (cont, disc):\n                for cvar in (disc, None):\n                    for b in [0, 1]:\n                        self._set_var(var)\n                        self._set_cvar(cvar)\n                        self._set_fitter(2 * b)\n                        self._set_check(c.stacked_columns, b)\n                        self._set_check(c.show_probs, b)\n                        qApp.processEvents()\n    else:\n        def test_plot_types_combinations(self):\n            \"\"\"Check that the widget doesn't crash at any plot combination\"\"\"\n            # pylint: disable=too-many-nested-blocks\n            from AnyQt.QtWidgets import qApp\n\n            widget = self.widget\n            c = widget.controls\n            self.send_signal(widget.Inputs.data, self.iris)\n            cont = self.iris.domain[0]\n            disc = self.iris.domain.class_var\n            for var in (cont, disc):\n                for cvar in (disc, None):\n                    for fitter in [0, 2]:\n                        for cumulative in [False, True]:\n                            for stack in [False, True]:\n                                for show_probs in [False, True]:\n                                    self._set_var(var)\n                                    self._set_cvar(cvar)\n                                    self._set_fitter(fitter)\n                                    self._set_check(c.cumulative_distr,\n                                                    cumulative)\n                                    self._set_check(c.stacked_columns, stack)\n                                    self._set_check(c.show_probs, show_probs)\n                                    qApp.processEvents()\n\n    def test_selection_grouping(self):\n        \"\"\"Widget groups consecutive selected bars\"\"\"\n        widget = self.widget\n        self.send_signal(widget.Inputs.data, self.iris)\n        self._set_slider(len(widget.binnings) - 1)\n        widget.selection = {1, 2, 3, 5, 6, 9}\n        widget.plot_mark.addItem = Mock()\n        widget.show_selection()\n        widget._on_end_selecting()\n        self.assertEqual(widget.plot_mark.addItem.call_count, 3)\n        out_selected = self.get_output(widget.Outputs.selected_data)\n        self.assertEqual(\n            len(out_selected.domain[ANNOTATED_DATA_FEATURE_NAME].values), 3)\n\n    def test_report(self):\n        \"\"\"Report doesn't crash\"\"\"\n        widget = self.widget\n        self.send_signal(widget.Inputs.data, self.iris)\n        widget.send_report()",
                            "ast_type_str": "ClassDef",
                            "start_lineno": 17,
                            "end_lineno": 466,
                            "parent": null
                        },
                        {
                            "file_name": "Orange/widgets/visualize/tests/test_owdistributions.py",
                            "type": "method",
                            "name": "TestOWDistributions.test_on_bins_changed",
                            "content": "class TestOWDistributions(WidgetTest):\n    def setUp(self):\n        self.widget = self.create_widget(OWDistributions)  #: OWDistributions\n        self.iris = Table(\"iris\")\n\n    def _set_cvar(self, cvar):\n        combo = self.widget.controls.cvar\n        self.widget.cvar = cvar\n        combo.activated[int].emit(combo.currentIndex())\n        combo.activated[str].emit(combo.currentText())\n\n    def _set_fitter(self, i):\n        combo = self.widget.controls.fitted_distribution\n        combo.setCurrentIndex(i)\n        combo.activated[int].emit(combo.currentIndex())\n        combo.activated[str].emit(combo.currentText())\n\n    def _set_var(self, var):\n        listview = self.widget.controls.var\n        model = listview.model()\n        index = var if isinstance(var, int) else model.indexOf(var)\n        selectionmodel = listview.selectionModel()\n        oldselection = selectionmodel.selection()\n        newselection = QItemSelection()\n        newselection.select(model.index(index, 0), model.index(index, 0))\n        selectionmodel.select(newselection, selectionmodel.ClearAndSelect)\n        selectionmodel.selectionChanged.emit(newselection, oldselection)\n\n    @staticmethod\n    def _set_check(checkbox, value):\n        checkbox.setCheckState(value)\n        checkbox.toggled[bool].emit(value)\n\n    def _set_slider(self, i):\n        slider = self.widget.controls.number_of_bins\n        slider.setValue(i)\n        slider.valueChanged[int].emit(i)\n        slider.sliderReleased.emit()\n\n    def test_set_data(self):\n        \"\"\"Basic test of set_data and removal of data\"\"\"\n        widget = self.widget\n        var_model = widget.controls.var.model()\n        cvar_model = widget.controls.cvar.model()\n\n        domain = self.iris.domain\n        self.send_signal(widget.Inputs.data, self.iris)\n        self.assertEqual({var.name for var in var_model},\n                         {var.name for var in domain.variables})\n        self.assertEqual(list(cvar_model),\n                         [None, DomainModel.Separator, domain.class_var])\n        self.assertIs(widget.var, domain[0])\n        self.assertIs(widget.cvar, domain.class_var)\n        np.testing.assert_equal(widget.valid_data, self.iris.X[:, 0])\n        np.testing.assert_equal(widget.valid_group_data, self.iris.Y)\n        self.assertEqual(\n            len(self.get_output(widget.Outputs.histogram_data)), 150)\n        self.assertIsNone(self.get_output(widget.Outputs.annotated_data))\n        self.assertIsNone(self.get_output(widget.Outputs.selected_data))\n\n        # Data gone: clean up\n        widget.selection.add(0)\n        widget._clear_plot = Mock()\n        self.send_signal(widget.Inputs.data, None)\n        self.assertEqual(len(var_model), 0)\n        self.assertEqual(list(cvar_model), [None])\n        self.assertIsNone(widget.var)\n        self.assertIsNone(widget.cvar)\n\n        self.assertEqual(widget.selection, set())\n        self.assertIsNone(widget.valid_data)\n        self.assertIsNone(widget.valid_group_data)\n        self.assertIsNone(self.get_output(widget.Outputs.histogram_data))\n        self.assertIsNone(self.get_output(widget.Outputs.annotated_data))\n        self.assertIsNone(self.get_output(widget.Outputs.selected_data))\n        widget._clear_plot.assert_called()\n\n    def test_set_data_no_class_no_discrete(self):\n        \"\"\"Widget is properly set up when there is no class and discrete vars\"\"\"\n        widget = self.widget\n        var_model = widget.controls.var.model()\n        cvar_model = widget.controls.cvar.model()\n\n        domain = Domain(self.iris.domain.attributes, [])\n        data = self.iris.transform(domain)\n        self.send_signal(widget.Inputs.data, data)\n        self.assertEqual({var.name for var in var_model},\n                         {var.name for var in domain.attributes})\n        self.assertEqual(list(cvar_model), [None])\n        self.assertIs(widget.var, domain[0])\n        self.assertIs(widget.cvar, None)\n        np.testing.assert_equal(widget.valid_data, self.iris.X[:, 0])\n        self.assertIsNone(widget.valid_group_data)\n        self.assertEqual(\n            len(self.get_output(widget.Outputs.histogram_data)), 150)\n        self.assertIsNone(self.get_output(widget.Outputs.annotated_data))\n        self.assertIsNone(self.get_output(widget.Outputs.selected_data))\n\n    def test_set_data_no_class(self):\n        \"\"\"Widget is properly set up when there is no class\"\"\"\n        widget = self.widget\n        var_model = widget.controls.var.model()\n        cvar_model = widget.controls.cvar.model()\n        iris = self.iris\n\n        domain = Domain(iris.domain.attributes + iris.domain.class_vars)\n        data = iris.transform(domain)\n        self.send_signal(widget.Inputs.data, data)\n        self.assertEqual({var.name for var in var_model},\n                         {var.name for var in domain.attributes})\n        self.assertEqual(list(cvar_model),\n                         [None, DomainModel.Separator, iris.domain.class_var])\n        self.assertIs(widget.var, domain[0])\n        self.assertIs(widget.cvar, None)\n        np.testing.assert_equal(widget.valid_data, self.iris.X[:, 0])\n        self.assertIsNone(widget.valid_group_data)\n        self.assertEqual(\n            len(self.get_output(widget.Outputs.histogram_data)), 150)\n        self.assertIsNone(self.get_output(widget.Outputs.annotated_data))\n        self.assertIsNone(self.get_output(widget.Outputs.selected_data))\n\n    def test_set_data_reg_class(self):\n        \"\"\"Widget is properly set up when the target is numeric\"\"\"\n        widget = self.widget\n        var_model = widget.controls.var.model()\n        cvar_model = widget.controls.cvar.model()\n        iris = self.iris\n\n        domain = Domain(iris.domain.attributes[:3] + iris.domain.class_vars,\n                        iris.domain.attributes[3])\n        data = iris.transform(domain)\n        self.send_signal(widget.Inputs.data, data)\n        self.assertEqual({var.name for var in var_model},\n                         {var.name for var in domain.variables})\n        self.assertEqual(list(cvar_model),\n                         [None, DomainModel.Separator, iris.domain.class_var])\n        self.assertIs(widget.var, domain[0])\n        self.assertIs(widget.cvar, None)\n        np.testing.assert_equal(widget.valid_data, self.iris.X[:, 0])\n        self.assertIsNone(widget.valid_group_data)\n        self.assertEqual(\n            len(self.get_output(widget.Outputs.histogram_data)), 150)\n        self.assertIsNone(self.get_output(widget.Outputs.annotated_data))\n        self.assertIsNone(self.get_output(widget.Outputs.selected_data))\n\n    def test_set_data_reg_class_no_discrete(self):\n        \"\"\"Widget is properly set up with regression and no discrete vars\"\"\"\n        widget = self.widget\n        var_model = widget.controls.var.model()\n        cvar_model = widget.controls.cvar.model()\n        iris = self.iris\n\n        domain = Domain(iris.domain.attributes[:3], iris.domain.attributes[3])\n        data = iris.transform(domain)\n        self.send_signal(widget.Inputs.data, data)\n        self.assertEqual({var.name for var in var_model},\n                         {var.name for var in domain.variables})\n        self.assertEqual(list(cvar_model), [None])\n        self.assertIs(widget.var, domain[0])\n        self.assertIs(widget.cvar, None)\n        np.testing.assert_equal(widget.valid_data, self.iris.X[:, 0])\n        self.assertIsNone(widget.valid_group_data)\n        self.assertEqual(\n            len(self.get_output(widget.Outputs.histogram_data)), 150)\n        self.assertIsNone(self.get_output(widget.Outputs.annotated_data))\n        self.assertIsNone(self.get_output(widget.Outputs.selected_data))\n\n    def test_switch_var(self):\n        \"\"\"Widget reset and recomputes when changing var\"\"\"\n        widget = self.widget\n\n        self.send_signal(widget.Inputs.data, self.iris)\n        binnings = widget.binnings.copy()\n        valid_data = widget.valid_data.copy()\n        widget.selection.add(1)\n        widget._clear_plot = Mock()\n        widget.apply = Mock()\n\n        self._set_var(2)\n        self.assertFalse(binnings[0].shape == widget.binnings[0].shape\n                         and np.allclose(binnings[0], widget.binnings[0]))\n        self.assertFalse(valid_data.shape == widget.valid_data.shape\n                         and np.allclose(valid_data, widget.valid_data))\n        self.assertEqual(widget.selection, set())\n        widget._clear_plot.assert_called()\n        widget.apply.assert_called()\n\n    def test_switch_cvar(self):\n        \"\"\"Widget reset and recomputes when changing splitting variable\"\"\"\n        widget = self.widget\n\n        y = self.iris.domain.class_var\n        extra = DiscreteVariable(\"foo\", values=[\"a\", \"b\"])\n        domain = Domain(self.iris.domain.attributes + (extra, ), y)\n        data = self.iris.transform(domain)\n        data.X[:75, -1] = 0\n        data.X[75:120, -1] = 1\n        self.send_signal(widget.Inputs.data, data)\n        self._set_var(2)\n        self._set_cvar(y)\n\n        binnings = widget.binnings\n        valid_data = widget.valid_data.copy()\n        widget.selection.add(1)\n        widget._clear_plot = Mock()\n        widget.apply = Mock()\n\n        self.assertEqual(len(widget.valid_group_data), 150)\n\n        self._set_cvar(extra)\n        self.assertIs(binnings, widget.binnings)\n        np.testing.assert_equal(valid_data[:120], widget.valid_data)\n        self.assertEqual(len(widget.valid_group_data), 120)\n        self.assertEqual(widget.selection, {1})\n        widget._clear_plot.assert_called()\n        widget.apply.assert_called()\n        widget._clear_plot.reset_mock()\n        widget.apply.reset_mock()\n\n        self._set_cvar(None)\n        self.assertIs(binnings, widget.binnings)\n        np.testing.assert_equal(valid_data, widget.valid_data)\n        self.assertIsNone(widget.valid_group_data)\n        self.assertEqual(widget.selection, {1})\n        widget._clear_plot.assert_called()\n        widget.apply.assert_called()\n\n    def test_on_bins_changed(self):\n        \"\"\"Widget replots and outputs data when the number of bins is changed\"\"\"\n        widget = self.widget\n        self.send_signal(widget.Inputs.data, self.iris)\n\n        widget.number_of_bins = 0\n        widget.selection.add(1)\n        n_bars = len(widget.bar_items)\n        widget.apply = Mock()\n\n        self._set_slider(1)\n        self.assertEqual(widget.selection, set())\n        self.assertGreater(n_bars, len(widget.bar_items))\n        widget.apply.assert_called_once()\n\n    def test_set_valid_data(self):\n        \"\"\"Widget handles nans in data\"\"\"\n        widget = self.widget\n        err_def_var = widget.Error.no_defined_values_var\n        err_def_pair = widget.Error.no_defined_values_pair\n        warn_nans = widget.Warning.ignored_nans\n\n        domain = self.iris.domain\n\n        self.assertIsNone(widget.var)\n        self.assertIsNone(widget.cvar)\n        self.assertIsNone(widget.valid_data)\n        self.assertIsNone(widget.valid_group_data)\n        self.assertFalse(widget.is_valid)\n\n        widget.valid_data = Mock()\n        widget.group_valid_data = Mock()\n        widget.set_valid_data()\n        self.assertIsNone(widget.valid_data)\n        self.assertIsNone(widget.valid_group_data)\n        self.assertFalse(widget.is_valid)\n\n        self.send_signal(widget.Inputs.data, self.iris)\n        self.assertIsNotNone(widget.valid_data)\n        self.assertIsNotNone(widget.valid_group_data)\n        self.assertTrue(widget.is_valid)\n\n        X, Y = self.iris.X, self.iris.Y\n        X[:, 0] = np.nan\n        X[:50, 1] = np.nan\n        X[:100, 2] = np.nan\n        Y[75:] = np.nan\n        self.send_signal(widget.Inputs.data, self.iris)\n\n        self._set_var(domain[0])\n        self._set_cvar(domain.class_var)\n        self.assertIs(widget.var, domain[0])\n        self.assertIs(widget.cvar, domain.class_var)\n        self.assertIsNone(widget.valid_data)\n        self.assertIsNone(widget.valid_group_data)\n        self.assertFalse(widget.is_valid)\n        self.assertTrue(err_def_var.is_shown())\n        self.assertFalse(err_def_pair.is_shown())\n        self.assertFalse(warn_nans.is_shown())\n\n        self._set_var(domain[1])\n        self.assertIs(widget.var, domain[1])\n        self.assertIs(widget.cvar, domain.class_var)\n        np.testing.assert_equal(widget.valid_data, X[50:75, 1])\n        np.testing.assert_equal(widget.valid_group_data, Y[50:75])\n        self.assertTrue(widget.is_valid)\n        self.assertFalse(err_def_var.is_shown())\n        self.assertFalse(err_def_pair.is_shown())\n        self.assertTrue(warn_nans.is_shown())\n\n        self._set_var(domain[2])\n        self.assertIs(widget.var, domain[2])\n        self.assertIs(widget.cvar, domain.class_var)\n        self.assertIsNone(widget.valid_data)\n        self.assertIsNone(widget.valid_group_data)\n        self.assertFalse(widget.is_valid)\n        self.assertFalse(err_def_var.is_shown())\n        self.assertTrue(err_def_pair.is_shown())\n        self.assertFalse(warn_nans.is_shown())\n\n        self._set_var(domain[3])\n        self.assertIs(widget.var, domain[3])\n        self.assertIs(widget.cvar, domain.class_var)\n        np.testing.assert_equal(widget.valid_data, X[:75, 3])\n        np.testing.assert_equal(widget.valid_group_data, Y[:75])\n        self.assertTrue(widget.is_valid)\n        self.assertFalse(err_def_var.is_shown())\n        self.assertFalse(err_def_pair.is_shown())\n        self.assertTrue(warn_nans.is_shown())\n\n        self._set_var(domain[0])\n        self._set_cvar(None)\n        self.assertIs(widget.var, domain[0])\n        self.assertIsNone(widget.cvar)\n        self.assertIsNone(widget.valid_data)\n        self.assertIsNone(widget.valid_group_data)\n        self.assertFalse(widget.is_valid)\n        self.assertTrue(err_def_var.is_shown())\n        self.assertFalse(err_def_pair.is_shown())\n        self.assertFalse(warn_nans.is_shown())\n\n        self._set_var(domain[1])\n        self.assertIs(widget.var, domain[1])\n        self.assertIsNone(widget.cvar)\n        np.testing.assert_equal(widget.valid_data, X[50:, 1])\n        self.assertIsNone(widget.valid_group_data)\n        self.assertTrue(widget.is_valid)\n        self.assertFalse(err_def_var.is_shown())\n        self.assertFalse(err_def_pair.is_shown())\n        self.assertTrue(warn_nans.is_shown())\n\n        self._set_var(domain[3])\n        self.assertIs(widget.var, domain[3])\n        self.assertIsNone(widget.cvar)\n        np.testing.assert_equal(widget.valid_data, X[:, 3])\n        self.assertIsNone(widget.valid_group_data)\n        self.assertTrue(widget.is_valid)\n        self.assertFalse(err_def_var.is_shown())\n        self.assertFalse(err_def_pair.is_shown())\n        self.assertFalse(warn_nans.is_shown())\n\n    def test_controls_disabling(self):\n        \"\"\"Widget changes gui for continuous/discrete variables and grouping\"\"\"\n        widget = self.widget\n        self.send_signal(widget.Inputs.data, self.iris)\n\n        cont = self.iris.domain[0]\n        disc = self.iris.domain.class_var\n        cont_box = widget.continuous_box\n        show_probs = widget.controls.show_probs\n        stacked = widget.controls.stacked_columns\n\n        self._set_var(cont)\n        self._set_cvar(disc)\n        self.assertTrue(cont_box.isEnabled())\n        self.assertTrue(show_probs.isEnabled())\n        self.assertTrue(stacked.isEnabled())\n\n        self._set_var(cont)\n        self._set_cvar(None)\n        self.assertTrue(cont_box.isEnabled())\n        self.assertFalse(show_probs.isEnabled())\n        self.assertFalse(stacked.isEnabled())\n\n        self._set_var(disc)\n        self._set_cvar(None)\n        self.assertFalse(cont_box.isEnabled())\n        self.assertFalse(show_probs.isEnabled())\n        self.assertFalse(stacked.isEnabled())\n\n        self._set_var(disc)\n        self._set_cvar(disc)\n        self.assertFalse(cont_box.isEnabled())\n        self.assertTrue(show_probs.isEnabled())\n        self.assertTrue(stacked.isEnabled())\n\n    if os.getenv(\"CI\"):\n        # Testing all combinations takes 10-15 seconds; this should take < 2s\n        # Code for fitter, stacked_columns and show_probs is independent, so\n        # changing them simultaneously doesn't significantly degrade the tests\n        def test_plot_types_combinations(self):\n            \"\"\"Check that the widget doesn't crash at any plot combination\"\"\"\n            from AnyQt.QtWidgets import qApp\n\n            widget = self.widget\n            c = widget.controls\n            self.send_signal(widget.Inputs.data, self.iris)\n            cont = self.iris.domain[0]\n            disc = self.iris.domain.class_var\n            for var in (cont, disc):\n                for cvar in (disc, None):\n                    for b in [0, 1]:\n                        self._set_var(var)\n                        self._set_cvar(cvar)\n                        self._set_fitter(2 * b)\n                        self._set_check(c.stacked_columns, b)\n                        self._set_check(c.show_probs, b)\n                        qApp.processEvents()\n    else:\n        def test_plot_types_combinations(self):\n            \"\"\"Check that the widget doesn't crash at any plot combination\"\"\"\n            # pylint: disable=too-many-nested-blocks\n            from AnyQt.QtWidgets import qApp\n\n            widget = self.widget\n            c = widget.controls\n            self.send_signal(widget.Inputs.data, self.iris)\n            cont = self.iris.domain[0]\n            disc = self.iris.domain.class_var\n            for var in (cont, disc):\n                for cvar in (disc, None):\n                    for fitter in [0, 2]:\n                        for cumulative in [False, True]:\n                            for stack in [False, True]:\n                                for show_probs in [False, True]:\n                                    self._set_var(var)\n                                    self._set_cvar(cvar)\n                                    self._set_fitter(fitter)\n                                    self._set_check(c.cumulative_distr,\n                                                    cumulative)\n                                    self._set_check(c.stacked_columns, stack)\n                                    self._set_check(c.show_probs, show_probs)\n                                    qApp.processEvents()\n\n    def test_selection_grouping(self):\n        \"\"\"Widget groups consecutive selected bars\"\"\"\n        widget = self.widget\n        self.send_signal(widget.Inputs.data, self.iris)\n        self._set_slider(len(widget.binnings) - 1)\n        widget.selection = {1, 2, 3, 5, 6, 9}\n        widget.plot_mark.addItem = Mock()\n        widget.show_selection()\n        widget._on_end_selecting()\n        self.assertEqual(widget.plot_mark.addItem.call_count, 3)\n        out_selected = self.get_output(widget.Outputs.selected_data)\n        self.assertEqual(\n            len(out_selected.domain[ANNOTATED_DATA_FEATURE_NAME].values), 3)\n\n    def test_report(self):\n        \"\"\"Report doesn't crash\"\"\"\n        widget = self.widget\n        self.send_signal(widget.Inputs.data, self.iris)\n        widget.send_report()",
                            "ast_type_str": "ClassDef",
                            "start_lineno": 244,
                            "end_lineno": 257,
                            "parent": {
                                "file_name": "Orange/widgets/visualize/tests/test_owdistributions.py",
                                "type": "class",
                                "name": "TestOWDistributions",
                                "content": "class TestOWDistributions(WidgetTest):\n    def setUp(self):\n        self.widget = self.create_widget(OWDistributions)  #: OWDistributions\n        self.iris = Table(\"iris\")\n\n    def _set_cvar(self, cvar):\n        combo = self.widget.controls.cvar\n        self.widget.cvar = cvar\n        combo.activated[int].emit(combo.currentIndex())\n        combo.activated[str].emit(combo.currentText())\n\n    def _set_fitter(self, i):\n        combo = self.widget.controls.fitted_distribution\n        combo.setCurrentIndex(i)\n        combo.activated[int].emit(combo.currentIndex())\n        combo.activated[str].emit(combo.currentText())\n\n    def _set_var(self, var):\n        listview = self.widget.controls.var\n        model = listview.model()\n        index = var if isinstance(var, int) else model.indexOf(var)\n        selectionmodel = listview.selectionModel()\n        oldselection = selectionmodel.selection()\n        newselection = QItemSelection()\n        newselection.select(model.index(index, 0), model.index(index, 0))\n        selectionmodel.select(newselection, selectionmodel.ClearAndSelect)\n        selectionmodel.selectionChanged.emit(newselection, oldselection)\n\n    @staticmethod\n    def _set_check(checkbox, value):\n        checkbox.setCheckState(value)\n        checkbox.toggled[bool].emit(value)\n\n    def _set_slider(self, i):\n        slider = self.widget.controls.number_of_bins\n        slider.setValue(i)\n        slider.valueChanged[int].emit(i)\n        slider.sliderReleased.emit()\n\n    def test_set_data(self):\n        \"\"\"Basic test of set_data and removal of data\"\"\"\n        widget = self.widget\n        var_model = widget.controls.var.model()\n        cvar_model = widget.controls.cvar.model()\n\n        domain = self.iris.domain\n        self.send_signal(widget.Inputs.data, self.iris)\n        self.assertEqual({var.name for var in var_model},\n                         {var.name for var in domain.variables})\n        self.assertEqual(list(cvar_model),\n                         [None, DomainModel.Separator, domain.class_var])\n        self.assertIs(widget.var, domain[0])\n        self.assertIs(widget.cvar, domain.class_var)\n        np.testing.assert_equal(widget.valid_data, self.iris.X[:, 0])\n        np.testing.assert_equal(widget.valid_group_data, self.iris.Y)\n        self.assertEqual(\n            len(self.get_output(widget.Outputs.histogram_data)), 150)\n        self.assertIsNone(self.get_output(widget.Outputs.annotated_data))\n        self.assertIsNone(self.get_output(widget.Outputs.selected_data))\n\n        # Data gone: clean up\n        widget.selection.add(0)\n        widget._clear_plot = Mock()\n        self.send_signal(widget.Inputs.data, None)\n        self.assertEqual(len(var_model), 0)\n        self.assertEqual(list(cvar_model), [None])\n        self.assertIsNone(widget.var)\n        self.assertIsNone(widget.cvar)\n\n        self.assertEqual(widget.selection, set())\n        self.assertIsNone(widget.valid_data)\n        self.assertIsNone(widget.valid_group_data)\n        self.assertIsNone(self.get_output(widget.Outputs.histogram_data))\n        self.assertIsNone(self.get_output(widget.Outputs.annotated_data))\n        self.assertIsNone(self.get_output(widget.Outputs.selected_data))\n        widget._clear_plot.assert_called()\n\n    def test_set_data_no_class_no_discrete(self):\n        \"\"\"Widget is properly set up when there is no class and discrete vars\"\"\"\n        widget = self.widget\n        var_model = widget.controls.var.model()\n        cvar_model = widget.controls.cvar.model()\n\n        domain = Domain(self.iris.domain.attributes, [])\n        data = self.iris.transform(domain)\n        self.send_signal(widget.Inputs.data, data)\n        self.assertEqual({var.name for var in var_model},\n                         {var.name for var in domain.attributes})\n        self.assertEqual(list(cvar_model), [None])\n        self.assertIs(widget.var, domain[0])\n        self.assertIs(widget.cvar, None)\n        np.testing.assert_equal(widget.valid_data, self.iris.X[:, 0])\n        self.assertIsNone(widget.valid_group_data)\n        self.assertEqual(\n            len(self.get_output(widget.Outputs.histogram_data)), 150)\n        self.assertIsNone(self.get_output(widget.Outputs.annotated_data))\n        self.assertIsNone(self.get_output(widget.Outputs.selected_data))\n\n    def test_set_data_no_class(self):\n        \"\"\"Widget is properly set up when there is no class\"\"\"\n        widget = self.widget\n        var_model = widget.controls.var.model()\n        cvar_model = widget.controls.cvar.model()\n        iris = self.iris\n\n        domain = Domain(iris.domain.attributes + iris.domain.class_vars)\n        data = iris.transform(domain)\n        self.send_signal(widget.Inputs.data, data)\n        self.assertEqual({var.name for var in var_model},\n                         {var.name for var in domain.attributes})\n        self.assertEqual(list(cvar_model),\n                         [None, DomainModel.Separator, iris.domain.class_var])\n        self.assertIs(widget.var, domain[0])\n        self.assertIs(widget.cvar, None)\n        np.testing.assert_equal(widget.valid_data, self.iris.X[:, 0])\n        self.assertIsNone(widget.valid_group_data)\n        self.assertEqual(\n            len(self.get_output(widget.Outputs.histogram_data)), 150)\n        self.assertIsNone(self.get_output(widget.Outputs.annotated_data))\n        self.assertIsNone(self.get_output(widget.Outputs.selected_data))\n\n    def test_set_data_reg_class(self):\n        \"\"\"Widget is properly set up when the target is numeric\"\"\"\n        widget = self.widget\n        var_model = widget.controls.var.model()\n        cvar_model = widget.controls.cvar.model()\n        iris = self.iris\n\n        domain = Domain(iris.domain.attributes[:3] + iris.domain.class_vars,\n                        iris.domain.attributes[3])\n        data = iris.transform(domain)\n        self.send_signal(widget.Inputs.data, data)\n        self.assertEqual({var.name for var in var_model},\n                         {var.name for var in domain.variables})\n        self.assertEqual(list(cvar_model),\n                         [None, DomainModel.Separator, iris.domain.class_var])\n        self.assertIs(widget.var, domain[0])\n        self.assertIs(widget.cvar, None)\n        np.testing.assert_equal(widget.valid_data, self.iris.X[:, 0])\n        self.assertIsNone(widget.valid_group_data)\n        self.assertEqual(\n            len(self.get_output(widget.Outputs.histogram_data)), 150)\n        self.assertIsNone(self.get_output(widget.Outputs.annotated_data))\n        self.assertIsNone(self.get_output(widget.Outputs.selected_data))\n\n    def test_set_data_reg_class_no_discrete(self):\n        \"\"\"Widget is properly set up with regression and no discrete vars\"\"\"\n        widget = self.widget\n        var_model = widget.controls.var.model()\n        cvar_model = widget.controls.cvar.model()\n        iris = self.iris\n\n        domain = Domain(iris.domain.attributes[:3], iris.domain.attributes[3])\n        data = iris.transform(domain)\n        self.send_signal(widget.Inputs.data, data)\n        self.assertEqual({var.name for var in var_model},\n                         {var.name for var in domain.variables})\n        self.assertEqual(list(cvar_model), [None])\n        self.assertIs(widget.var, domain[0])\n        self.assertIs(widget.cvar, None)\n        np.testing.assert_equal(widget.valid_data, self.iris.X[:, 0])\n        self.assertIsNone(widget.valid_group_data)\n        self.assertEqual(\n            len(self.get_output(widget.Outputs.histogram_data)), 150)\n        self.assertIsNone(self.get_output(widget.Outputs.annotated_data))\n        self.assertIsNone(self.get_output(widget.Outputs.selected_data))\n\n    def test_switch_var(self):\n        \"\"\"Widget reset and recomputes when changing var\"\"\"\n        widget = self.widget\n\n        self.send_signal(widget.Inputs.data, self.iris)\n        binnings = widget.binnings.copy()\n        valid_data = widget.valid_data.copy()\n        widget.selection.add(1)\n        widget._clear_plot = Mock()\n        widget.apply = Mock()\n\n        self._set_var(2)\n        self.assertFalse(binnings[0].shape == widget.binnings[0].shape\n                         and np.allclose(binnings[0], widget.binnings[0]))\n        self.assertFalse(valid_data.shape == widget.valid_data.shape\n                         and np.allclose(valid_data, widget.valid_data))\n        self.assertEqual(widget.selection, set())\n        widget._clear_plot.assert_called()\n        widget.apply.assert_called()\n\n    def test_switch_cvar(self):\n        \"\"\"Widget reset and recomputes when changing splitting variable\"\"\"\n        widget = self.widget\n\n        y = self.iris.domain.class_var\n        extra = DiscreteVariable(\"foo\", values=[\"a\", \"b\"])\n        domain = Domain(self.iris.domain.attributes + (extra, ), y)\n        data = self.iris.transform(domain)\n        data.X[:75, -1] = 0\n        data.X[75:120, -1] = 1\n        self.send_signal(widget.Inputs.data, data)\n        self._set_var(2)\n        self._set_cvar(y)\n\n        binnings = widget.binnings\n        valid_data = widget.valid_data.copy()\n        widget.selection.add(1)\n        widget._clear_plot = Mock()\n        widget.apply = Mock()\n\n        self.assertEqual(len(widget.valid_group_data), 150)\n\n        self._set_cvar(extra)\n        self.assertIs(binnings, widget.binnings)\n        np.testing.assert_equal(valid_data[:120], widget.valid_data)\n        self.assertEqual(len(widget.valid_group_data), 120)\n        self.assertEqual(widget.selection, {1})\n        widget._clear_plot.assert_called()\n        widget.apply.assert_called()\n        widget._clear_plot.reset_mock()\n        widget.apply.reset_mock()\n\n        self._set_cvar(None)\n        self.assertIs(binnings, widget.binnings)\n        np.testing.assert_equal(valid_data, widget.valid_data)\n        self.assertIsNone(widget.valid_group_data)\n        self.assertEqual(widget.selection, {1})\n        widget._clear_plot.assert_called()\n        widget.apply.assert_called()\n\n    def test_on_bins_changed(self):\n        \"\"\"Widget replots and outputs data when the number of bins is changed\"\"\"\n        widget = self.widget\n        self.send_signal(widget.Inputs.data, self.iris)\n\n        widget.number_of_bins = 0\n        widget.selection.add(1)\n        n_bars = len(widget.bar_items)\n        widget.apply = Mock()\n\n        self._set_slider(1)\n        self.assertEqual(widget.selection, set())\n        self.assertGreater(n_bars, len(widget.bar_items))\n        widget.apply.assert_called_once()\n\n    def test_set_valid_data(self):\n        \"\"\"Widget handles nans in data\"\"\"\n        widget = self.widget\n        err_def_var = widget.Error.no_defined_values_var\n        err_def_pair = widget.Error.no_defined_values_pair\n        warn_nans = widget.Warning.ignored_nans\n\n        domain = self.iris.domain\n\n        self.assertIsNone(widget.var)\n        self.assertIsNone(widget.cvar)\n        self.assertIsNone(widget.valid_data)\n        self.assertIsNone(widget.valid_group_data)\n        self.assertFalse(widget.is_valid)\n\n        widget.valid_data = Mock()\n        widget.group_valid_data = Mock()\n        widget.set_valid_data()\n        self.assertIsNone(widget.valid_data)\n        self.assertIsNone(widget.valid_group_data)\n        self.assertFalse(widget.is_valid)\n\n        self.send_signal(widget.Inputs.data, self.iris)\n        self.assertIsNotNone(widget.valid_data)\n        self.assertIsNotNone(widget.valid_group_data)\n        self.assertTrue(widget.is_valid)\n\n        X, Y = self.iris.X, self.iris.Y\n        X[:, 0] = np.nan\n        X[:50, 1] = np.nan\n        X[:100, 2] = np.nan\n        Y[75:] = np.nan\n        self.send_signal(widget.Inputs.data, self.iris)\n\n        self._set_var(domain[0])\n        self._set_cvar(domain.class_var)\n        self.assertIs(widget.var, domain[0])\n        self.assertIs(widget.cvar, domain.class_var)\n        self.assertIsNone(widget.valid_data)\n        self.assertIsNone(widget.valid_group_data)\n        self.assertFalse(widget.is_valid)\n        self.assertTrue(err_def_var.is_shown())\n        self.assertFalse(err_def_pair.is_shown())\n        self.assertFalse(warn_nans.is_shown())\n\n        self._set_var(domain[1])\n        self.assertIs(widget.var, domain[1])\n        self.assertIs(widget.cvar, domain.class_var)\n        np.testing.assert_equal(widget.valid_data, X[50:75, 1])\n        np.testing.assert_equal(widget.valid_group_data, Y[50:75])\n        self.assertTrue(widget.is_valid)\n        self.assertFalse(err_def_var.is_shown())\n        self.assertFalse(err_def_pair.is_shown())\n        self.assertTrue(warn_nans.is_shown())\n\n        self._set_var(domain[2])\n        self.assertIs(widget.var, domain[2])\n        self.assertIs(widget.cvar, domain.class_var)\n        self.assertIsNone(widget.valid_data)\n        self.assertIsNone(widget.valid_group_data)\n        self.assertFalse(widget.is_valid)\n        self.assertFalse(err_def_var.is_shown())\n        self.assertTrue(err_def_pair.is_shown())\n        self.assertFalse(warn_nans.is_shown())\n\n        self._set_var(domain[3])\n        self.assertIs(widget.var, domain[3])\n        self.assertIs(widget.cvar, domain.class_var)\n        np.testing.assert_equal(widget.valid_data, X[:75, 3])\n        np.testing.assert_equal(widget.valid_group_data, Y[:75])\n        self.assertTrue(widget.is_valid)\n        self.assertFalse(err_def_var.is_shown())\n        self.assertFalse(err_def_pair.is_shown())\n        self.assertTrue(warn_nans.is_shown())\n\n        self._set_var(domain[0])\n        self._set_cvar(None)\n        self.assertIs(widget.var, domain[0])\n        self.assertIsNone(widget.cvar)\n        self.assertIsNone(widget.valid_data)\n        self.assertIsNone(widget.valid_group_data)\n        self.assertFalse(widget.is_valid)\n        self.assertTrue(err_def_var.is_shown())\n        self.assertFalse(err_def_pair.is_shown())\n        self.assertFalse(warn_nans.is_shown())\n\n        self._set_var(domain[1])\n        self.assertIs(widget.var, domain[1])\n        self.assertIsNone(widget.cvar)\n        np.testing.assert_equal(widget.valid_data, X[50:, 1])\n        self.assertIsNone(widget.valid_group_data)\n        self.assertTrue(widget.is_valid)\n        self.assertFalse(err_def_var.is_shown())\n        self.assertFalse(err_def_pair.is_shown())\n        self.assertTrue(warn_nans.is_shown())\n\n        self._set_var(domain[3])\n        self.assertIs(widget.var, domain[3])\n        self.assertIsNone(widget.cvar)\n        np.testing.assert_equal(widget.valid_data, X[:, 3])\n        self.assertIsNone(widget.valid_group_data)\n        self.assertTrue(widget.is_valid)\n        self.assertFalse(err_def_var.is_shown())\n        self.assertFalse(err_def_pair.is_shown())\n        self.assertFalse(warn_nans.is_shown())\n\n    def test_controls_disabling(self):\n        \"\"\"Widget changes gui for continuous/discrete variables and grouping\"\"\"\n        widget = self.widget\n        self.send_signal(widget.Inputs.data, self.iris)\n\n        cont = self.iris.domain[0]\n        disc = self.iris.domain.class_var\n        cont_box = widget.continuous_box\n        show_probs = widget.controls.show_probs\n        stacked = widget.controls.stacked_columns\n\n        self._set_var(cont)\n        self._set_cvar(disc)\n        self.assertTrue(cont_box.isEnabled())\n        self.assertTrue(show_probs.isEnabled())\n        self.assertTrue(stacked.isEnabled())\n\n        self._set_var(cont)\n        self._set_cvar(None)\n        self.assertTrue(cont_box.isEnabled())\n        self.assertFalse(show_probs.isEnabled())\n        self.assertFalse(stacked.isEnabled())\n\n        self._set_var(disc)\n        self._set_cvar(None)\n        self.assertFalse(cont_box.isEnabled())\n        self.assertFalse(show_probs.isEnabled())\n        self.assertFalse(stacked.isEnabled())\n\n        self._set_var(disc)\n        self._set_cvar(disc)\n        self.assertFalse(cont_box.isEnabled())\n        self.assertTrue(show_probs.isEnabled())\n        self.assertTrue(stacked.isEnabled())\n\n    if os.getenv(\"CI\"):\n        # Testing all combinations takes 10-15 seconds; this should take < 2s\n        # Code for fitter, stacked_columns and show_probs is independent, so\n        # changing them simultaneously doesn't significantly degrade the tests\n        def test_plot_types_combinations(self):\n            \"\"\"Check that the widget doesn't crash at any plot combination\"\"\"\n            from AnyQt.QtWidgets import qApp\n\n            widget = self.widget\n            c = widget.controls\n            self.send_signal(widget.Inputs.data, self.iris)\n            cont = self.iris.domain[0]\n            disc = self.iris.domain.class_var\n            for var in (cont, disc):\n                for cvar in (disc, None):\n                    for b in [0, 1]:\n                        self._set_var(var)\n                        self._set_cvar(cvar)\n                        self._set_fitter(2 * b)\n                        self._set_check(c.stacked_columns, b)\n                        self._set_check(c.show_probs, b)\n                        qApp.processEvents()\n    else:\n        def test_plot_types_combinations(self):\n            \"\"\"Check that the widget doesn't crash at any plot combination\"\"\"\n            # pylint: disable=too-many-nested-blocks\n            from AnyQt.QtWidgets import qApp\n\n            widget = self.widget\n            c = widget.controls\n            self.send_signal(widget.Inputs.data, self.iris)\n            cont = self.iris.domain[0]\n            disc = self.iris.domain.class_var\n            for var in (cont, disc):\n                for cvar in (disc, None):\n                    for fitter in [0, 2]:\n                        for cumulative in [False, True]:\n                            for stack in [False, True]:\n                                for show_probs in [False, True]:\n                                    self._set_var(var)\n                                    self._set_cvar(cvar)\n                                    self._set_fitter(fitter)\n                                    self._set_check(c.cumulative_distr,\n                                                    cumulative)\n                                    self._set_check(c.stacked_columns, stack)\n                                    self._set_check(c.show_probs, show_probs)\n                                    qApp.processEvents()\n\n    def test_selection_grouping(self):\n        \"\"\"Widget groups consecutive selected bars\"\"\"\n        widget = self.widget\n        self.send_signal(widget.Inputs.data, self.iris)\n        self._set_slider(len(widget.binnings) - 1)\n        widget.selection = {1, 2, 3, 5, 6, 9}\n        widget.plot_mark.addItem = Mock()\n        widget.show_selection()\n        widget._on_end_selecting()\n        self.assertEqual(widget.plot_mark.addItem.call_count, 3)\n        out_selected = self.get_output(widget.Outputs.selected_data)\n        self.assertEqual(\n            len(out_selected.domain[ANNOTATED_DATA_FEATURE_NAME].values), 3)\n\n    def test_report(self):\n        \"\"\"Report doesn't crash\"\"\"\n        widget = self.widget\n        self.send_signal(widget.Inputs.data, self.iris)\n        widget.send_report()",
                                "ast_type_str": "ClassDef",
                                "start_lineno": 17,
                                "end_lineno": 466,
                                "parent": null
                            }
                        }
                    ],
                    "added_entities": [],
                    "deleted_entities": []
                },
                {
                    "descriptor": {
                        "old_range": {
                            "start": 449,
                            "length": 7
                        },
                        "new_range": {
                            "start": 449,
                            "length": 7
                        },
                        "section": "class TestOWDistributions(WidgetTest):"
                    },
                    "line_group": {
                        "all_lines": [
                            {
                                "content": "        \"\"\"Widget groups consecutive selected bars\"\"\"",
                                "type": "context"
                            },
                            {
                                "content": "        widget = self.widget",
                                "type": "context"
                            },
                            {
                                "content": "        self.send_signal(widget.Inputs.data, self.iris)",
                                "type": "context"
                            },
                            {
                                "content": "        self._set_slider(len(widget.binnings) - 1)",
                                "type": "deleted"
                            },
                            {
                                "content": "        self._set_slider(0)",
                                "type": "added"
                            },
                            {
                                "content": "        widget.selection = {1, 2, 3, 5, 6, 9}",
                                "type": "context"
                            },
                            {
                                "content": "        widget.plot_mark.addItem = Mock()",
                                "type": "context"
                            },
                            {
                                "content": "        widget.show_selection()",
                                "type": "context"
                            },
                            {
                                "content": "",
                                "type": "context"
                            }
                        ]
                    },
                    "modified_entities": [
                        {
                            "file_name": "Orange/widgets/visualize/tests/test_owdistributions.py",
                            "type": "class",
                            "name": "TestOWDistributions",
                            "content": "class TestOWDistributions(WidgetTest):\n    def setUp(self):\n        self.widget = self.create_widget(OWDistributions)  #: OWDistributions\n        self.iris = Table(\"iris\")\n\n    def _set_cvar(self, cvar):\n        combo = self.widget.controls.cvar\n        self.widget.cvar = cvar\n        combo.activated[int].emit(combo.currentIndex())\n        combo.activated[str].emit(combo.currentText())\n\n    def _set_fitter(self, i):\n        combo = self.widget.controls.fitted_distribution\n        combo.setCurrentIndex(i)\n        combo.activated[int].emit(combo.currentIndex())\n        combo.activated[str].emit(combo.currentText())\n\n    def _set_var(self, var):\n        listview = self.widget.controls.var\n        model = listview.model()\n        index = var if isinstance(var, int) else model.indexOf(var)\n        selectionmodel = listview.selectionModel()\n        oldselection = selectionmodel.selection()\n        newselection = QItemSelection()\n        newselection.select(model.index(index, 0), model.index(index, 0))\n        selectionmodel.select(newselection, selectionmodel.ClearAndSelect)\n        selectionmodel.selectionChanged.emit(newselection, oldselection)\n\n    @staticmethod\n    def _set_check(checkbox, value):\n        checkbox.setCheckState(value)\n        checkbox.toggled[bool].emit(value)\n\n    def _set_slider(self, i):\n        slider = self.widget.controls.number_of_bins\n        slider.setValue(i)\n        slider.valueChanged[int].emit(i)\n        slider.sliderReleased.emit()\n\n    def test_set_data(self):\n        \"\"\"Basic test of set_data and removal of data\"\"\"\n        widget = self.widget\n        var_model = widget.controls.var.model()\n        cvar_model = widget.controls.cvar.model()\n\n        domain = self.iris.domain\n        self.send_signal(widget.Inputs.data, self.iris)\n        self.assertEqual({var.name for var in var_model},\n                         {var.name for var in domain.variables})\n        self.assertEqual(list(cvar_model),\n                         [None, DomainModel.Separator, domain.class_var])\n        self.assertIs(widget.var, domain[0])\n        self.assertIs(widget.cvar, domain.class_var)\n        np.testing.assert_equal(widget.valid_data, self.iris.X[:, 0])\n        np.testing.assert_equal(widget.valid_group_data, self.iris.Y)\n        self.assertEqual(\n            len(self.get_output(widget.Outputs.histogram_data)), 150)\n        self.assertIsNone(self.get_output(widget.Outputs.annotated_data))\n        self.assertIsNone(self.get_output(widget.Outputs.selected_data))\n\n        # Data gone: clean up\n        widget.selection.add(0)\n        widget._clear_plot = Mock()\n        self.send_signal(widget.Inputs.data, None)\n        self.assertEqual(len(var_model), 0)\n        self.assertEqual(list(cvar_model), [None])\n        self.assertIsNone(widget.var)\n        self.assertIsNone(widget.cvar)\n\n        self.assertEqual(widget.selection, set())\n        self.assertIsNone(widget.valid_data)\n        self.assertIsNone(widget.valid_group_data)\n        self.assertIsNone(self.get_output(widget.Outputs.histogram_data))\n        self.assertIsNone(self.get_output(widget.Outputs.annotated_data))\n        self.assertIsNone(self.get_output(widget.Outputs.selected_data))\n        widget._clear_plot.assert_called()\n\n    def test_set_data_no_class_no_discrete(self):\n        \"\"\"Widget is properly set up when there is no class and discrete vars\"\"\"\n        widget = self.widget\n        var_model = widget.controls.var.model()\n        cvar_model = widget.controls.cvar.model()\n\n        domain = Domain(self.iris.domain.attributes, [])\n        data = self.iris.transform(domain)\n        self.send_signal(widget.Inputs.data, data)\n        self.assertEqual({var.name for var in var_model},\n                         {var.name for var in domain.attributes})\n        self.assertEqual(list(cvar_model), [None])\n        self.assertIs(widget.var, domain[0])\n        self.assertIs(widget.cvar, None)\n        np.testing.assert_equal(widget.valid_data, self.iris.X[:, 0])\n        self.assertIsNone(widget.valid_group_data)\n        self.assertEqual(\n            len(self.get_output(widget.Outputs.histogram_data)), 150)\n        self.assertIsNone(self.get_output(widget.Outputs.annotated_data))\n        self.assertIsNone(self.get_output(widget.Outputs.selected_data))\n\n    def test_set_data_no_class(self):\n        \"\"\"Widget is properly set up when there is no class\"\"\"\n        widget = self.widget\n        var_model = widget.controls.var.model()\n        cvar_model = widget.controls.cvar.model()\n        iris = self.iris\n\n        domain = Domain(iris.domain.attributes + iris.domain.class_vars)\n        data = iris.transform(domain)\n        self.send_signal(widget.Inputs.data, data)\n        self.assertEqual({var.name for var in var_model},\n                         {var.name for var in domain.attributes})\n        self.assertEqual(list(cvar_model),\n                         [None, DomainModel.Separator, iris.domain.class_var])\n        self.assertIs(widget.var, domain[0])\n        self.assertIs(widget.cvar, None)\n        np.testing.assert_equal(widget.valid_data, self.iris.X[:, 0])\n        self.assertIsNone(widget.valid_group_data)\n        self.assertEqual(\n            len(self.get_output(widget.Outputs.histogram_data)), 150)\n        self.assertIsNone(self.get_output(widget.Outputs.annotated_data))\n        self.assertIsNone(self.get_output(widget.Outputs.selected_data))\n\n    def test_set_data_reg_class(self):\n        \"\"\"Widget is properly set up when the target is numeric\"\"\"\n        widget = self.widget\n        var_model = widget.controls.var.model()\n        cvar_model = widget.controls.cvar.model()\n        iris = self.iris\n\n        domain = Domain(iris.domain.attributes[:3] + iris.domain.class_vars,\n                        iris.domain.attributes[3])\n        data = iris.transform(domain)\n        self.send_signal(widget.Inputs.data, data)\n        self.assertEqual({var.name for var in var_model},\n                         {var.name for var in domain.variables})\n        self.assertEqual(list(cvar_model),\n                         [None, DomainModel.Separator, iris.domain.class_var])\n        self.assertIs(widget.var, domain[0])\n        self.assertIs(widget.cvar, None)\n        np.testing.assert_equal(widget.valid_data, self.iris.X[:, 0])\n        self.assertIsNone(widget.valid_group_data)\n        self.assertEqual(\n            len(self.get_output(widget.Outputs.histogram_data)), 150)\n        self.assertIsNone(self.get_output(widget.Outputs.annotated_data))\n        self.assertIsNone(self.get_output(widget.Outputs.selected_data))\n\n    def test_set_data_reg_class_no_discrete(self):\n        \"\"\"Widget is properly set up with regression and no discrete vars\"\"\"\n        widget = self.widget\n        var_model = widget.controls.var.model()\n        cvar_model = widget.controls.cvar.model()\n        iris = self.iris\n\n        domain = Domain(iris.domain.attributes[:3], iris.domain.attributes[3])\n        data = iris.transform(domain)\n        self.send_signal(widget.Inputs.data, data)\n        self.assertEqual({var.name for var in var_model},\n                         {var.name for var in domain.variables})\n        self.assertEqual(list(cvar_model), [None])\n        self.assertIs(widget.var, domain[0])\n        self.assertIs(widget.cvar, None)\n        np.testing.assert_equal(widget.valid_data, self.iris.X[:, 0])\n        self.assertIsNone(widget.valid_group_data)\n        self.assertEqual(\n            len(self.get_output(widget.Outputs.histogram_data)), 150)\n        self.assertIsNone(self.get_output(widget.Outputs.annotated_data))\n        self.assertIsNone(self.get_output(widget.Outputs.selected_data))\n\n    def test_switch_var(self):\n        \"\"\"Widget reset and recomputes when changing var\"\"\"\n        widget = self.widget\n\n        self.send_signal(widget.Inputs.data, self.iris)\n        binnings = widget.binnings.copy()\n        valid_data = widget.valid_data.copy()\n        widget.selection.add(1)\n        widget._clear_plot = Mock()\n        widget.apply = Mock()\n\n        self._set_var(2)\n        self.assertFalse(binnings[0].shape == widget.binnings[0].shape\n                         and np.allclose(binnings[0], widget.binnings[0]))\n        self.assertFalse(valid_data.shape == widget.valid_data.shape\n                         and np.allclose(valid_data, widget.valid_data))\n        self.assertEqual(widget.selection, set())\n        widget._clear_plot.assert_called()\n        widget.apply.assert_called()\n\n    def test_switch_cvar(self):\n        \"\"\"Widget reset and recomputes when changing splitting variable\"\"\"\n        widget = self.widget\n\n        y = self.iris.domain.class_var\n        extra = DiscreteVariable(\"foo\", values=[\"a\", \"b\"])\n        domain = Domain(self.iris.domain.attributes + (extra, ), y)\n        data = self.iris.transform(domain)\n        data.X[:75, -1] = 0\n        data.X[75:120, -1] = 1\n        self.send_signal(widget.Inputs.data, data)\n        self._set_var(2)\n        self._set_cvar(y)\n\n        binnings = widget.binnings\n        valid_data = widget.valid_data.copy()\n        widget.selection.add(1)\n        widget._clear_plot = Mock()\n        widget.apply = Mock()\n\n        self.assertEqual(len(widget.valid_group_data), 150)\n\n        self._set_cvar(extra)\n        self.assertIs(binnings, widget.binnings)\n        np.testing.assert_equal(valid_data[:120], widget.valid_data)\n        self.assertEqual(len(widget.valid_group_data), 120)\n        self.assertEqual(widget.selection, {1})\n        widget._clear_plot.assert_called()\n        widget.apply.assert_called()\n        widget._clear_plot.reset_mock()\n        widget.apply.reset_mock()\n\n        self._set_cvar(None)\n        self.assertIs(binnings, widget.binnings)\n        np.testing.assert_equal(valid_data, widget.valid_data)\n        self.assertIsNone(widget.valid_group_data)\n        self.assertEqual(widget.selection, {1})\n        widget._clear_plot.assert_called()\n        widget.apply.assert_called()\n\n    def test_on_bins_changed(self):\n        \"\"\"Widget replots and outputs data when the number of bins is changed\"\"\"\n        widget = self.widget\n        self.send_signal(widget.Inputs.data, self.iris)\n\n        widget.number_of_bins = 0\n        widget.selection.add(1)\n        n_bars = len(widget.bar_items)\n        widget.apply = Mock()\n\n        self._set_slider(1)\n        self.assertEqual(widget.selection, set())\n        self.assertGreater(n_bars, len(widget.bar_items))\n        widget.apply.assert_called_once()\n\n    def test_set_valid_data(self):\n        \"\"\"Widget handles nans in data\"\"\"\n        widget = self.widget\n        err_def_var = widget.Error.no_defined_values_var\n        err_def_pair = widget.Error.no_defined_values_pair\n        warn_nans = widget.Warning.ignored_nans\n\n        domain = self.iris.domain\n\n        self.assertIsNone(widget.var)\n        self.assertIsNone(widget.cvar)\n        self.assertIsNone(widget.valid_data)\n        self.assertIsNone(widget.valid_group_data)\n        self.assertFalse(widget.is_valid)\n\n        widget.valid_data = Mock()\n        widget.group_valid_data = Mock()\n        widget.set_valid_data()\n        self.assertIsNone(widget.valid_data)\n        self.assertIsNone(widget.valid_group_data)\n        self.assertFalse(widget.is_valid)\n\n        self.send_signal(widget.Inputs.data, self.iris)\n        self.assertIsNotNone(widget.valid_data)\n        self.assertIsNotNone(widget.valid_group_data)\n        self.assertTrue(widget.is_valid)\n\n        X, Y = self.iris.X, self.iris.Y\n        X[:, 0] = np.nan\n        X[:50, 1] = np.nan\n        X[:100, 2] = np.nan\n        Y[75:] = np.nan\n        self.send_signal(widget.Inputs.data, self.iris)\n\n        self._set_var(domain[0])\n        self._set_cvar(domain.class_var)\n        self.assertIs(widget.var, domain[0])\n        self.assertIs(widget.cvar, domain.class_var)\n        self.assertIsNone(widget.valid_data)\n        self.assertIsNone(widget.valid_group_data)\n        self.assertFalse(widget.is_valid)\n        self.assertTrue(err_def_var.is_shown())\n        self.assertFalse(err_def_pair.is_shown())\n        self.assertFalse(warn_nans.is_shown())\n\n        self._set_var(domain[1])\n        self.assertIs(widget.var, domain[1])\n        self.assertIs(widget.cvar, domain.class_var)\n        np.testing.assert_equal(widget.valid_data, X[50:75, 1])\n        np.testing.assert_equal(widget.valid_group_data, Y[50:75])\n        self.assertTrue(widget.is_valid)\n        self.assertFalse(err_def_var.is_shown())\n        self.assertFalse(err_def_pair.is_shown())\n        self.assertTrue(warn_nans.is_shown())\n\n        self._set_var(domain[2])\n        self.assertIs(widget.var, domain[2])\n        self.assertIs(widget.cvar, domain.class_var)\n        self.assertIsNone(widget.valid_data)\n        self.assertIsNone(widget.valid_group_data)\n        self.assertFalse(widget.is_valid)\n        self.assertFalse(err_def_var.is_shown())\n        self.assertTrue(err_def_pair.is_shown())\n        self.assertFalse(warn_nans.is_shown())\n\n        self._set_var(domain[3])\n        self.assertIs(widget.var, domain[3])\n        self.assertIs(widget.cvar, domain.class_var)\n        np.testing.assert_equal(widget.valid_data, X[:75, 3])\n        np.testing.assert_equal(widget.valid_group_data, Y[:75])\n        self.assertTrue(widget.is_valid)\n        self.assertFalse(err_def_var.is_shown())\n        self.assertFalse(err_def_pair.is_shown())\n        self.assertTrue(warn_nans.is_shown())\n\n        self._set_var(domain[0])\n        self._set_cvar(None)\n        self.assertIs(widget.var, domain[0])\n        self.assertIsNone(widget.cvar)\n        self.assertIsNone(widget.valid_data)\n        self.assertIsNone(widget.valid_group_data)\n        self.assertFalse(widget.is_valid)\n        self.assertTrue(err_def_var.is_shown())\n        self.assertFalse(err_def_pair.is_shown())\n        self.assertFalse(warn_nans.is_shown())\n\n        self._set_var(domain[1])\n        self.assertIs(widget.var, domain[1])\n        self.assertIsNone(widget.cvar)\n        np.testing.assert_equal(widget.valid_data, X[50:, 1])\n        self.assertIsNone(widget.valid_group_data)\n        self.assertTrue(widget.is_valid)\n        self.assertFalse(err_def_var.is_shown())\n        self.assertFalse(err_def_pair.is_shown())\n        self.assertTrue(warn_nans.is_shown())\n\n        self._set_var(domain[3])\n        self.assertIs(widget.var, domain[3])\n        self.assertIsNone(widget.cvar)\n        np.testing.assert_equal(widget.valid_data, X[:, 3])\n        self.assertIsNone(widget.valid_group_data)\n        self.assertTrue(widget.is_valid)\n        self.assertFalse(err_def_var.is_shown())\n        self.assertFalse(err_def_pair.is_shown())\n        self.assertFalse(warn_nans.is_shown())\n\n    def test_controls_disabling(self):\n        \"\"\"Widget changes gui for continuous/discrete variables and grouping\"\"\"\n        widget = self.widget\n        self.send_signal(widget.Inputs.data, self.iris)\n\n        cont = self.iris.domain[0]\n        disc = self.iris.domain.class_var\n        cont_box = widget.continuous_box\n        show_probs = widget.controls.show_probs\n        stacked = widget.controls.stacked_columns\n\n        self._set_var(cont)\n        self._set_cvar(disc)\n        self.assertTrue(cont_box.isEnabled())\n        self.assertTrue(show_probs.isEnabled())\n        self.assertTrue(stacked.isEnabled())\n\n        self._set_var(cont)\n        self._set_cvar(None)\n        self.assertTrue(cont_box.isEnabled())\n        self.assertFalse(show_probs.isEnabled())\n        self.assertFalse(stacked.isEnabled())\n\n        self._set_var(disc)\n        self._set_cvar(None)\n        self.assertFalse(cont_box.isEnabled())\n        self.assertFalse(show_probs.isEnabled())\n        self.assertFalse(stacked.isEnabled())\n\n        self._set_var(disc)\n        self._set_cvar(disc)\n        self.assertFalse(cont_box.isEnabled())\n        self.assertTrue(show_probs.isEnabled())\n        self.assertTrue(stacked.isEnabled())\n\n    if os.getenv(\"CI\"):\n        # Testing all combinations takes 10-15 seconds; this should take < 2s\n        # Code for fitter, stacked_columns and show_probs is independent, so\n        # changing them simultaneously doesn't significantly degrade the tests\n        def test_plot_types_combinations(self):\n            \"\"\"Check that the widget doesn't crash at any plot combination\"\"\"\n            from AnyQt.QtWidgets import qApp\n\n            widget = self.widget\n            c = widget.controls\n            self.send_signal(widget.Inputs.data, self.iris)\n            cont = self.iris.domain[0]\n            disc = self.iris.domain.class_var\n            for var in (cont, disc):\n                for cvar in (disc, None):\n                    for b in [0, 1]:\n                        self._set_var(var)\n                        self._set_cvar(cvar)\n                        self._set_fitter(2 * b)\n                        self._set_check(c.stacked_columns, b)\n                        self._set_check(c.show_probs, b)\n                        qApp.processEvents()\n    else:\n        def test_plot_types_combinations(self):\n            \"\"\"Check that the widget doesn't crash at any plot combination\"\"\"\n            # pylint: disable=too-many-nested-blocks\n            from AnyQt.QtWidgets import qApp\n\n            widget = self.widget\n            c = widget.controls\n            self.send_signal(widget.Inputs.data, self.iris)\n            cont = self.iris.domain[0]\n            disc = self.iris.domain.class_var\n            for var in (cont, disc):\n                for cvar in (disc, None):\n                    for fitter in [0, 2]:\n                        for cumulative in [False, True]:\n                            for stack in [False, True]:\n                                for show_probs in [False, True]:\n                                    self._set_var(var)\n                                    self._set_cvar(cvar)\n                                    self._set_fitter(fitter)\n                                    self._set_check(c.cumulative_distr,\n                                                    cumulative)\n                                    self._set_check(c.stacked_columns, stack)\n                                    self._set_check(c.show_probs, show_probs)\n                                    qApp.processEvents()\n\n    def test_selection_grouping(self):\n        \"\"\"Widget groups consecutive selected bars\"\"\"\n        widget = self.widget\n        self.send_signal(widget.Inputs.data, self.iris)\n        self._set_slider(len(widget.binnings) - 1)\n        widget.selection = {1, 2, 3, 5, 6, 9}\n        widget.plot_mark.addItem = Mock()\n        widget.show_selection()\n        widget._on_end_selecting()\n        self.assertEqual(widget.plot_mark.addItem.call_count, 3)\n        out_selected = self.get_output(widget.Outputs.selected_data)\n        self.assertEqual(\n            len(out_selected.domain[ANNOTATED_DATA_FEATURE_NAME].values), 3)\n\n    def test_report(self):\n        \"\"\"Report doesn't crash\"\"\"\n        widget = self.widget\n        self.send_signal(widget.Inputs.data, self.iris)\n        widget.send_report()",
                            "ast_type_str": "ClassDef",
                            "start_lineno": 17,
                            "end_lineno": 466,
                            "parent": null
                        },
                        {
                            "file_name": "Orange/widgets/visualize/tests/test_owdistributions.py",
                            "type": "method",
                            "name": "TestOWDistributions.test_selection_grouping",
                            "content": "class TestOWDistributions(WidgetTest):\n    def setUp(self):\n        self.widget = self.create_widget(OWDistributions)  #: OWDistributions\n        self.iris = Table(\"iris\")\n\n    def _set_cvar(self, cvar):\n        combo = self.widget.controls.cvar\n        self.widget.cvar = cvar\n        combo.activated[int].emit(combo.currentIndex())\n        combo.activated[str].emit(combo.currentText())\n\n    def _set_fitter(self, i):\n        combo = self.widget.controls.fitted_distribution\n        combo.setCurrentIndex(i)\n        combo.activated[int].emit(combo.currentIndex())\n        combo.activated[str].emit(combo.currentText())\n\n    def _set_var(self, var):\n        listview = self.widget.controls.var\n        model = listview.model()\n        index = var if isinstance(var, int) else model.indexOf(var)\n        selectionmodel = listview.selectionModel()\n        oldselection = selectionmodel.selection()\n        newselection = QItemSelection()\n        newselection.select(model.index(index, 0), model.index(index, 0))\n        selectionmodel.select(newselection, selectionmodel.ClearAndSelect)\n        selectionmodel.selectionChanged.emit(newselection, oldselection)\n\n    @staticmethod\n    def _set_check(checkbox, value):\n        checkbox.setCheckState(value)\n        checkbox.toggled[bool].emit(value)\n\n    def _set_slider(self, i):\n        slider = self.widget.controls.number_of_bins\n        slider.setValue(i)\n        slider.valueChanged[int].emit(i)\n        slider.sliderReleased.emit()\n\n    def test_set_data(self):\n        \"\"\"Basic test of set_data and removal of data\"\"\"\n        widget = self.widget\n        var_model = widget.controls.var.model()\n        cvar_model = widget.controls.cvar.model()\n\n        domain = self.iris.domain\n        self.send_signal(widget.Inputs.data, self.iris)\n        self.assertEqual({var.name for var in var_model},\n                         {var.name for var in domain.variables})\n        self.assertEqual(list(cvar_model),\n                         [None, DomainModel.Separator, domain.class_var])\n        self.assertIs(widget.var, domain[0])\n        self.assertIs(widget.cvar, domain.class_var)\n        np.testing.assert_equal(widget.valid_data, self.iris.X[:, 0])\n        np.testing.assert_equal(widget.valid_group_data, self.iris.Y)\n        self.assertEqual(\n            len(self.get_output(widget.Outputs.histogram_data)), 150)\n        self.assertIsNone(self.get_output(widget.Outputs.annotated_data))\n        self.assertIsNone(self.get_output(widget.Outputs.selected_data))\n\n        # Data gone: clean up\n        widget.selection.add(0)\n        widget._clear_plot = Mock()\n        self.send_signal(widget.Inputs.data, None)\n        self.assertEqual(len(var_model), 0)\n        self.assertEqual(list(cvar_model), [None])\n        self.assertIsNone(widget.var)\n        self.assertIsNone(widget.cvar)\n\n        self.assertEqual(widget.selection, set())\n        self.assertIsNone(widget.valid_data)\n        self.assertIsNone(widget.valid_group_data)\n        self.assertIsNone(self.get_output(widget.Outputs.histogram_data))\n        self.assertIsNone(self.get_output(widget.Outputs.annotated_data))\n        self.assertIsNone(self.get_output(widget.Outputs.selected_data))\n        widget._clear_plot.assert_called()\n\n    def test_set_data_no_class_no_discrete(self):\n        \"\"\"Widget is properly set up when there is no class and discrete vars\"\"\"\n        widget = self.widget\n        var_model = widget.controls.var.model()\n        cvar_model = widget.controls.cvar.model()\n\n        domain = Domain(self.iris.domain.attributes, [])\n        data = self.iris.transform(domain)\n        self.send_signal(widget.Inputs.data, data)\n        self.assertEqual({var.name for var in var_model},\n                         {var.name for var in domain.attributes})\n        self.assertEqual(list(cvar_model), [None])\n        self.assertIs(widget.var, domain[0])\n        self.assertIs(widget.cvar, None)\n        np.testing.assert_equal(widget.valid_data, self.iris.X[:, 0])\n        self.assertIsNone(widget.valid_group_data)\n        self.assertEqual(\n            len(self.get_output(widget.Outputs.histogram_data)), 150)\n        self.assertIsNone(self.get_output(widget.Outputs.annotated_data))\n        self.assertIsNone(self.get_output(widget.Outputs.selected_data))\n\n    def test_set_data_no_class(self):\n        \"\"\"Widget is properly set up when there is no class\"\"\"\n        widget = self.widget\n        var_model = widget.controls.var.model()\n        cvar_model = widget.controls.cvar.model()\n        iris = self.iris\n\n        domain = Domain(iris.domain.attributes + iris.domain.class_vars)\n        data = iris.transform(domain)\n        self.send_signal(widget.Inputs.data, data)\n        self.assertEqual({var.name for var in var_model},\n                         {var.name for var in domain.attributes})\n        self.assertEqual(list(cvar_model),\n                         [None, DomainModel.Separator, iris.domain.class_var])\n        self.assertIs(widget.var, domain[0])\n        self.assertIs(widget.cvar, None)\n        np.testing.assert_equal(widget.valid_data, self.iris.X[:, 0])\n        self.assertIsNone(widget.valid_group_data)\n        self.assertEqual(\n            len(self.get_output(widget.Outputs.histogram_data)), 150)\n        self.assertIsNone(self.get_output(widget.Outputs.annotated_data))\n        self.assertIsNone(self.get_output(widget.Outputs.selected_data))\n\n    def test_set_data_reg_class(self):\n        \"\"\"Widget is properly set up when the target is numeric\"\"\"\n        widget = self.widget\n        var_model = widget.controls.var.model()\n        cvar_model = widget.controls.cvar.model()\n        iris = self.iris\n\n        domain = Domain(iris.domain.attributes[:3] + iris.domain.class_vars,\n                        iris.domain.attributes[3])\n        data = iris.transform(domain)\n        self.send_signal(widget.Inputs.data, data)\n        self.assertEqual({var.name for var in var_model},\n                         {var.name for var in domain.variables})\n        self.assertEqual(list(cvar_model),\n                         [None, DomainModel.Separator, iris.domain.class_var])\n        self.assertIs(widget.var, domain[0])\n        self.assertIs(widget.cvar, None)\n        np.testing.assert_equal(widget.valid_data, self.iris.X[:, 0])\n        self.assertIsNone(widget.valid_group_data)\n        self.assertEqual(\n            len(self.get_output(widget.Outputs.histogram_data)), 150)\n        self.assertIsNone(self.get_output(widget.Outputs.annotated_data))\n        self.assertIsNone(self.get_output(widget.Outputs.selected_data))\n\n    def test_set_data_reg_class_no_discrete(self):\n        \"\"\"Widget is properly set up with regression and no discrete vars\"\"\"\n        widget = self.widget\n        var_model = widget.controls.var.model()\n        cvar_model = widget.controls.cvar.model()\n        iris = self.iris\n\n        domain = Domain(iris.domain.attributes[:3], iris.domain.attributes[3])\n        data = iris.transform(domain)\n        self.send_signal(widget.Inputs.data, data)\n        self.assertEqual({var.name for var in var_model},\n                         {var.name for var in domain.variables})\n        self.assertEqual(list(cvar_model), [None])\n        self.assertIs(widget.var, domain[0])\n        self.assertIs(widget.cvar, None)\n        np.testing.assert_equal(widget.valid_data, self.iris.X[:, 0])\n        self.assertIsNone(widget.valid_group_data)\n        self.assertEqual(\n            len(self.get_output(widget.Outputs.histogram_data)), 150)\n        self.assertIsNone(self.get_output(widget.Outputs.annotated_data))\n        self.assertIsNone(self.get_output(widget.Outputs.selected_data))\n\n    def test_switch_var(self):\n        \"\"\"Widget reset and recomputes when changing var\"\"\"\n        widget = self.widget\n\n        self.send_signal(widget.Inputs.data, self.iris)\n        binnings = widget.binnings.copy()\n        valid_data = widget.valid_data.copy()\n        widget.selection.add(1)\n        widget._clear_plot = Mock()\n        widget.apply = Mock()\n\n        self._set_var(2)\n        self.assertFalse(binnings[0].shape == widget.binnings[0].shape\n                         and np.allclose(binnings[0], widget.binnings[0]))\n        self.assertFalse(valid_data.shape == widget.valid_data.shape\n                         and np.allclose(valid_data, widget.valid_data))\n        self.assertEqual(widget.selection, set())\n        widget._clear_plot.assert_called()\n        widget.apply.assert_called()\n\n    def test_switch_cvar(self):\n        \"\"\"Widget reset and recomputes when changing splitting variable\"\"\"\n        widget = self.widget\n\n        y = self.iris.domain.class_var\n        extra = DiscreteVariable(\"foo\", values=[\"a\", \"b\"])\n        domain = Domain(self.iris.domain.attributes + (extra, ), y)\n        data = self.iris.transform(domain)\n        data.X[:75, -1] = 0\n        data.X[75:120, -1] = 1\n        self.send_signal(widget.Inputs.data, data)\n        self._set_var(2)\n        self._set_cvar(y)\n\n        binnings = widget.binnings\n        valid_data = widget.valid_data.copy()\n        widget.selection.add(1)\n        widget._clear_plot = Mock()\n        widget.apply = Mock()\n\n        self.assertEqual(len(widget.valid_group_data), 150)\n\n        self._set_cvar(extra)\n        self.assertIs(binnings, widget.binnings)\n        np.testing.assert_equal(valid_data[:120], widget.valid_data)\n        self.assertEqual(len(widget.valid_group_data), 120)\n        self.assertEqual(widget.selection, {1})\n        widget._clear_plot.assert_called()\n        widget.apply.assert_called()\n        widget._clear_plot.reset_mock()\n        widget.apply.reset_mock()\n\n        self._set_cvar(None)\n        self.assertIs(binnings, widget.binnings)\n        np.testing.assert_equal(valid_data, widget.valid_data)\n        self.assertIsNone(widget.valid_group_data)\n        self.assertEqual(widget.selection, {1})\n        widget._clear_plot.assert_called()\n        widget.apply.assert_called()\n\n    def test_on_bins_changed(self):\n        \"\"\"Widget replots and outputs data when the number of bins is changed\"\"\"\n        widget = self.widget\n        self.send_signal(widget.Inputs.data, self.iris)\n\n        widget.number_of_bins = 0\n        widget.selection.add(1)\n        n_bars = len(widget.bar_items)\n        widget.apply = Mock()\n\n        self._set_slider(1)\n        self.assertEqual(widget.selection, set())\n        self.assertGreater(n_bars, len(widget.bar_items))\n        widget.apply.assert_called_once()\n\n    def test_set_valid_data(self):\n        \"\"\"Widget handles nans in data\"\"\"\n        widget = self.widget\n        err_def_var = widget.Error.no_defined_values_var\n        err_def_pair = widget.Error.no_defined_values_pair\n        warn_nans = widget.Warning.ignored_nans\n\n        domain = self.iris.domain\n\n        self.assertIsNone(widget.var)\n        self.assertIsNone(widget.cvar)\n        self.assertIsNone(widget.valid_data)\n        self.assertIsNone(widget.valid_group_data)\n        self.assertFalse(widget.is_valid)\n\n        widget.valid_data = Mock()\n        widget.group_valid_data = Mock()\n        widget.set_valid_data()\n        self.assertIsNone(widget.valid_data)\n        self.assertIsNone(widget.valid_group_data)\n        self.assertFalse(widget.is_valid)\n\n        self.send_signal(widget.Inputs.data, self.iris)\n        self.assertIsNotNone(widget.valid_data)\n        self.assertIsNotNone(widget.valid_group_data)\n        self.assertTrue(widget.is_valid)\n\n        X, Y = self.iris.X, self.iris.Y\n        X[:, 0] = np.nan\n        X[:50, 1] = np.nan\n        X[:100, 2] = np.nan\n        Y[75:] = np.nan\n        self.send_signal(widget.Inputs.data, self.iris)\n\n        self._set_var(domain[0])\n        self._set_cvar(domain.class_var)\n        self.assertIs(widget.var, domain[0])\n        self.assertIs(widget.cvar, domain.class_var)\n        self.assertIsNone(widget.valid_data)\n        self.assertIsNone(widget.valid_group_data)\n        self.assertFalse(widget.is_valid)\n        self.assertTrue(err_def_var.is_shown())\n        self.assertFalse(err_def_pair.is_shown())\n        self.assertFalse(warn_nans.is_shown())\n\n        self._set_var(domain[1])\n        self.assertIs(widget.var, domain[1])\n        self.assertIs(widget.cvar, domain.class_var)\n        np.testing.assert_equal(widget.valid_data, X[50:75, 1])\n        np.testing.assert_equal(widget.valid_group_data, Y[50:75])\n        self.assertTrue(widget.is_valid)\n        self.assertFalse(err_def_var.is_shown())\n        self.assertFalse(err_def_pair.is_shown())\n        self.assertTrue(warn_nans.is_shown())\n\n        self._set_var(domain[2])\n        self.assertIs(widget.var, domain[2])\n        self.assertIs(widget.cvar, domain.class_var)\n        self.assertIsNone(widget.valid_data)\n        self.assertIsNone(widget.valid_group_data)\n        self.assertFalse(widget.is_valid)\n        self.assertFalse(err_def_var.is_shown())\n        self.assertTrue(err_def_pair.is_shown())\n        self.assertFalse(warn_nans.is_shown())\n\n        self._set_var(domain[3])\n        self.assertIs(widget.var, domain[3])\n        self.assertIs(widget.cvar, domain.class_var)\n        np.testing.assert_equal(widget.valid_data, X[:75, 3])\n        np.testing.assert_equal(widget.valid_group_data, Y[:75])\n        self.assertTrue(widget.is_valid)\n        self.assertFalse(err_def_var.is_shown())\n        self.assertFalse(err_def_pair.is_shown())\n        self.assertTrue(warn_nans.is_shown())\n\n        self._set_var(domain[0])\n        self._set_cvar(None)\n        self.assertIs(widget.var, domain[0])\n        self.assertIsNone(widget.cvar)\n        self.assertIsNone(widget.valid_data)\n        self.assertIsNone(widget.valid_group_data)\n        self.assertFalse(widget.is_valid)\n        self.assertTrue(err_def_var.is_shown())\n        self.assertFalse(err_def_pair.is_shown())\n        self.assertFalse(warn_nans.is_shown())\n\n        self._set_var(domain[1])\n        self.assertIs(widget.var, domain[1])\n        self.assertIsNone(widget.cvar)\n        np.testing.assert_equal(widget.valid_data, X[50:, 1])\n        self.assertIsNone(widget.valid_group_data)\n        self.assertTrue(widget.is_valid)\n        self.assertFalse(err_def_var.is_shown())\n        self.assertFalse(err_def_pair.is_shown())\n        self.assertTrue(warn_nans.is_shown())\n\n        self._set_var(domain[3])\n        self.assertIs(widget.var, domain[3])\n        self.assertIsNone(widget.cvar)\n        np.testing.assert_equal(widget.valid_data, X[:, 3])\n        self.assertIsNone(widget.valid_group_data)\n        self.assertTrue(widget.is_valid)\n        self.assertFalse(err_def_var.is_shown())\n        self.assertFalse(err_def_pair.is_shown())\n        self.assertFalse(warn_nans.is_shown())\n\n    def test_controls_disabling(self):\n        \"\"\"Widget changes gui for continuous/discrete variables and grouping\"\"\"\n        widget = self.widget\n        self.send_signal(widget.Inputs.data, self.iris)\n\n        cont = self.iris.domain[0]\n        disc = self.iris.domain.class_var\n        cont_box = widget.continuous_box\n        show_probs = widget.controls.show_probs\n        stacked = widget.controls.stacked_columns\n\n        self._set_var(cont)\n        self._set_cvar(disc)\n        self.assertTrue(cont_box.isEnabled())\n        self.assertTrue(show_probs.isEnabled())\n        self.assertTrue(stacked.isEnabled())\n\n        self._set_var(cont)\n        self._set_cvar(None)\n        self.assertTrue(cont_box.isEnabled())\n        self.assertFalse(show_probs.isEnabled())\n        self.assertFalse(stacked.isEnabled())\n\n        self._set_var(disc)\n        self._set_cvar(None)\n        self.assertFalse(cont_box.isEnabled())\n        self.assertFalse(show_probs.isEnabled())\n        self.assertFalse(stacked.isEnabled())\n\n        self._set_var(disc)\n        self._set_cvar(disc)\n        self.assertFalse(cont_box.isEnabled())\n        self.assertTrue(show_probs.isEnabled())\n        self.assertTrue(stacked.isEnabled())\n\n    if os.getenv(\"CI\"):\n        # Testing all combinations takes 10-15 seconds; this should take < 2s\n        # Code for fitter, stacked_columns and show_probs is independent, so\n        # changing them simultaneously doesn't significantly degrade the tests\n        def test_plot_types_combinations(self):\n            \"\"\"Check that the widget doesn't crash at any plot combination\"\"\"\n            from AnyQt.QtWidgets import qApp\n\n            widget = self.widget\n            c = widget.controls\n            self.send_signal(widget.Inputs.data, self.iris)\n            cont = self.iris.domain[0]\n            disc = self.iris.domain.class_var\n            for var in (cont, disc):\n                for cvar in (disc, None):\n                    for b in [0, 1]:\n                        self._set_var(var)\n                        self._set_cvar(cvar)\n                        self._set_fitter(2 * b)\n                        self._set_check(c.stacked_columns, b)\n                        self._set_check(c.show_probs, b)\n                        qApp.processEvents()\n    else:\n        def test_plot_types_combinations(self):\n            \"\"\"Check that the widget doesn't crash at any plot combination\"\"\"\n            # pylint: disable=too-many-nested-blocks\n            from AnyQt.QtWidgets import qApp\n\n            widget = self.widget\n            c = widget.controls\n            self.send_signal(widget.Inputs.data, self.iris)\n            cont = self.iris.domain[0]\n            disc = self.iris.domain.class_var\n            for var in (cont, disc):\n                for cvar in (disc, None):\n                    for fitter in [0, 2]:\n                        for cumulative in [False, True]:\n                            for stack in [False, True]:\n                                for show_probs in [False, True]:\n                                    self._set_var(var)\n                                    self._set_cvar(cvar)\n                                    self._set_fitter(fitter)\n                                    self._set_check(c.cumulative_distr,\n                                                    cumulative)\n                                    self._set_check(c.stacked_columns, stack)\n                                    self._set_check(c.show_probs, show_probs)\n                                    qApp.processEvents()\n\n    def test_selection_grouping(self):\n        \"\"\"Widget groups consecutive selected bars\"\"\"\n        widget = self.widget\n        self.send_signal(widget.Inputs.data, self.iris)\n        self._set_slider(len(widget.binnings) - 1)\n        widget.selection = {1, 2, 3, 5, 6, 9}\n        widget.plot_mark.addItem = Mock()\n        widget.show_selection()\n        widget._on_end_selecting()\n        self.assertEqual(widget.plot_mark.addItem.call_count, 3)\n        out_selected = self.get_output(widget.Outputs.selected_data)\n        self.assertEqual(\n            len(out_selected.domain[ANNOTATED_DATA_FEATURE_NAME].values), 3)\n\n    def test_report(self):\n        \"\"\"Report doesn't crash\"\"\"\n        widget = self.widget\n        self.send_signal(widget.Inputs.data, self.iris)\n        widget.send_report()",
                            "ast_type_str": "ClassDef",
                            "start_lineno": 448,
                            "end_lineno": 460,
                            "parent": {
                                "file_name": "Orange/widgets/visualize/tests/test_owdistributions.py",
                                "type": "class",
                                "name": "TestOWDistributions",
                                "content": "class TestOWDistributions(WidgetTest):\n    def setUp(self):\n        self.widget = self.create_widget(OWDistributions)  #: OWDistributions\n        self.iris = Table(\"iris\")\n\n    def _set_cvar(self, cvar):\n        combo = self.widget.controls.cvar\n        self.widget.cvar = cvar\n        combo.activated[int].emit(combo.currentIndex())\n        combo.activated[str].emit(combo.currentText())\n\n    def _set_fitter(self, i):\n        combo = self.widget.controls.fitted_distribution\n        combo.setCurrentIndex(i)\n        combo.activated[int].emit(combo.currentIndex())\n        combo.activated[str].emit(combo.currentText())\n\n    def _set_var(self, var):\n        listview = self.widget.controls.var\n        model = listview.model()\n        index = var if isinstance(var, int) else model.indexOf(var)\n        selectionmodel = listview.selectionModel()\n        oldselection = selectionmodel.selection()\n        newselection = QItemSelection()\n        newselection.select(model.index(index, 0), model.index(index, 0))\n        selectionmodel.select(newselection, selectionmodel.ClearAndSelect)\n        selectionmodel.selectionChanged.emit(newselection, oldselection)\n\n    @staticmethod\n    def _set_check(checkbox, value):\n        checkbox.setCheckState(value)\n        checkbox.toggled[bool].emit(value)\n\n    def _set_slider(self, i):\n        slider = self.widget.controls.number_of_bins\n        slider.setValue(i)\n        slider.valueChanged[int].emit(i)\n        slider.sliderReleased.emit()\n\n    def test_set_data(self):\n        \"\"\"Basic test of set_data and removal of data\"\"\"\n        widget = self.widget\n        var_model = widget.controls.var.model()\n        cvar_model = widget.controls.cvar.model()\n\n        domain = self.iris.domain\n        self.send_signal(widget.Inputs.data, self.iris)\n        self.assertEqual({var.name for var in var_model},\n                         {var.name for var in domain.variables})\n        self.assertEqual(list(cvar_model),\n                         [None, DomainModel.Separator, domain.class_var])\n        self.assertIs(widget.var, domain[0])\n        self.assertIs(widget.cvar, domain.class_var)\n        np.testing.assert_equal(widget.valid_data, self.iris.X[:, 0])\n        np.testing.assert_equal(widget.valid_group_data, self.iris.Y)\n        self.assertEqual(\n            len(self.get_output(widget.Outputs.histogram_data)), 150)\n        self.assertIsNone(self.get_output(widget.Outputs.annotated_data))\n        self.assertIsNone(self.get_output(widget.Outputs.selected_data))\n\n        # Data gone: clean up\n        widget.selection.add(0)\n        widget._clear_plot = Mock()\n        self.send_signal(widget.Inputs.data, None)\n        self.assertEqual(len(var_model), 0)\n        self.assertEqual(list(cvar_model), [None])\n        self.assertIsNone(widget.var)\n        self.assertIsNone(widget.cvar)\n\n        self.assertEqual(widget.selection, set())\n        self.assertIsNone(widget.valid_data)\n        self.assertIsNone(widget.valid_group_data)\n        self.assertIsNone(self.get_output(widget.Outputs.histogram_data))\n        self.assertIsNone(self.get_output(widget.Outputs.annotated_data))\n        self.assertIsNone(self.get_output(widget.Outputs.selected_data))\n        widget._clear_plot.assert_called()\n\n    def test_set_data_no_class_no_discrete(self):\n        \"\"\"Widget is properly set up when there is no class and discrete vars\"\"\"\n        widget = self.widget\n        var_model = widget.controls.var.model()\n        cvar_model = widget.controls.cvar.model()\n\n        domain = Domain(self.iris.domain.attributes, [])\n        data = self.iris.transform(domain)\n        self.send_signal(widget.Inputs.data, data)\n        self.assertEqual({var.name for var in var_model},\n                         {var.name for var in domain.attributes})\n        self.assertEqual(list(cvar_model), [None])\n        self.assertIs(widget.var, domain[0])\n        self.assertIs(widget.cvar, None)\n        np.testing.assert_equal(widget.valid_data, self.iris.X[:, 0])\n        self.assertIsNone(widget.valid_group_data)\n        self.assertEqual(\n            len(self.get_output(widget.Outputs.histogram_data)), 150)\n        self.assertIsNone(self.get_output(widget.Outputs.annotated_data))\n        self.assertIsNone(self.get_output(widget.Outputs.selected_data))\n\n    def test_set_data_no_class(self):\n        \"\"\"Widget is properly set up when there is no class\"\"\"\n        widget = self.widget\n        var_model = widget.controls.var.model()\n        cvar_model = widget.controls.cvar.model()\n        iris = self.iris\n\n        domain = Domain(iris.domain.attributes + iris.domain.class_vars)\n        data = iris.transform(domain)\n        self.send_signal(widget.Inputs.data, data)\n        self.assertEqual({var.name for var in var_model},\n                         {var.name for var in domain.attributes})\n        self.assertEqual(list(cvar_model),\n                         [None, DomainModel.Separator, iris.domain.class_var])\n        self.assertIs(widget.var, domain[0])\n        self.assertIs(widget.cvar, None)\n        np.testing.assert_equal(widget.valid_data, self.iris.X[:, 0])\n        self.assertIsNone(widget.valid_group_data)\n        self.assertEqual(\n            len(self.get_output(widget.Outputs.histogram_data)), 150)\n        self.assertIsNone(self.get_output(widget.Outputs.annotated_data))\n        self.assertIsNone(self.get_output(widget.Outputs.selected_data))\n\n    def test_set_data_reg_class(self):\n        \"\"\"Widget is properly set up when the target is numeric\"\"\"\n        widget = self.widget\n        var_model = widget.controls.var.model()\n        cvar_model = widget.controls.cvar.model()\n        iris = self.iris\n\n        domain = Domain(iris.domain.attributes[:3] + iris.domain.class_vars,\n                        iris.domain.attributes[3])\n        data = iris.transform(domain)\n        self.send_signal(widget.Inputs.data, data)\n        self.assertEqual({var.name for var in var_model},\n                         {var.name for var in domain.variables})\n        self.assertEqual(list(cvar_model),\n                         [None, DomainModel.Separator, iris.domain.class_var])\n        self.assertIs(widget.var, domain[0])\n        self.assertIs(widget.cvar, None)\n        np.testing.assert_equal(widget.valid_data, self.iris.X[:, 0])\n        self.assertIsNone(widget.valid_group_data)\n        self.assertEqual(\n            len(self.get_output(widget.Outputs.histogram_data)), 150)\n        self.assertIsNone(self.get_output(widget.Outputs.annotated_data))\n        self.assertIsNone(self.get_output(widget.Outputs.selected_data))\n\n    def test_set_data_reg_class_no_discrete(self):\n        \"\"\"Widget is properly set up with regression and no discrete vars\"\"\"\n        widget = self.widget\n        var_model = widget.controls.var.model()\n        cvar_model = widget.controls.cvar.model()\n        iris = self.iris\n\n        domain = Domain(iris.domain.attributes[:3], iris.domain.attributes[3])\n        data = iris.transform(domain)\n        self.send_signal(widget.Inputs.data, data)\n        self.assertEqual({var.name for var in var_model},\n                         {var.name for var in domain.variables})\n        self.assertEqual(list(cvar_model), [None])\n        self.assertIs(widget.var, domain[0])\n        self.assertIs(widget.cvar, None)\n        np.testing.assert_equal(widget.valid_data, self.iris.X[:, 0])\n        self.assertIsNone(widget.valid_group_data)\n        self.assertEqual(\n            len(self.get_output(widget.Outputs.histogram_data)), 150)\n        self.assertIsNone(self.get_output(widget.Outputs.annotated_data))\n        self.assertIsNone(self.get_output(widget.Outputs.selected_data))\n\n    def test_switch_var(self):\n        \"\"\"Widget reset and recomputes when changing var\"\"\"\n        widget = self.widget\n\n        self.send_signal(widget.Inputs.data, self.iris)\n        binnings = widget.binnings.copy()\n        valid_data = widget.valid_data.copy()\n        widget.selection.add(1)\n        widget._clear_plot = Mock()\n        widget.apply = Mock()\n\n        self._set_var(2)\n        self.assertFalse(binnings[0].shape == widget.binnings[0].shape\n                         and np.allclose(binnings[0], widget.binnings[0]))\n        self.assertFalse(valid_data.shape == widget.valid_data.shape\n                         and np.allclose(valid_data, widget.valid_data))\n        self.assertEqual(widget.selection, set())\n        widget._clear_plot.assert_called()\n        widget.apply.assert_called()\n\n    def test_switch_cvar(self):\n        \"\"\"Widget reset and recomputes when changing splitting variable\"\"\"\n        widget = self.widget\n\n        y = self.iris.domain.class_var\n        extra = DiscreteVariable(\"foo\", values=[\"a\", \"b\"])\n        domain = Domain(self.iris.domain.attributes + (extra, ), y)\n        data = self.iris.transform(domain)\n        data.X[:75, -1] = 0\n        data.X[75:120, -1] = 1\n        self.send_signal(widget.Inputs.data, data)\n        self._set_var(2)\n        self._set_cvar(y)\n\n        binnings = widget.binnings\n        valid_data = widget.valid_data.copy()\n        widget.selection.add(1)\n        widget._clear_plot = Mock()\n        widget.apply = Mock()\n\n        self.assertEqual(len(widget.valid_group_data), 150)\n\n        self._set_cvar(extra)\n        self.assertIs(binnings, widget.binnings)\n        np.testing.assert_equal(valid_data[:120], widget.valid_data)\n        self.assertEqual(len(widget.valid_group_data), 120)\n        self.assertEqual(widget.selection, {1})\n        widget._clear_plot.assert_called()\n        widget.apply.assert_called()\n        widget._clear_plot.reset_mock()\n        widget.apply.reset_mock()\n\n        self._set_cvar(None)\n        self.assertIs(binnings, widget.binnings)\n        np.testing.assert_equal(valid_data, widget.valid_data)\n        self.assertIsNone(widget.valid_group_data)\n        self.assertEqual(widget.selection, {1})\n        widget._clear_plot.assert_called()\n        widget.apply.assert_called()\n\n    def test_on_bins_changed(self):\n        \"\"\"Widget replots and outputs data when the number of bins is changed\"\"\"\n        widget = self.widget\n        self.send_signal(widget.Inputs.data, self.iris)\n\n        widget.number_of_bins = 0\n        widget.selection.add(1)\n        n_bars = len(widget.bar_items)\n        widget.apply = Mock()\n\n        self._set_slider(1)\n        self.assertEqual(widget.selection, set())\n        self.assertGreater(n_bars, len(widget.bar_items))\n        widget.apply.assert_called_once()\n\n    def test_set_valid_data(self):\n        \"\"\"Widget handles nans in data\"\"\"\n        widget = self.widget\n        err_def_var = widget.Error.no_defined_values_var\n        err_def_pair = widget.Error.no_defined_values_pair\n        warn_nans = widget.Warning.ignored_nans\n\n        domain = self.iris.domain\n\n        self.assertIsNone(widget.var)\n        self.assertIsNone(widget.cvar)\n        self.assertIsNone(widget.valid_data)\n        self.assertIsNone(widget.valid_group_data)\n        self.assertFalse(widget.is_valid)\n\n        widget.valid_data = Mock()\n        widget.group_valid_data = Mock()\n        widget.set_valid_data()\n        self.assertIsNone(widget.valid_data)\n        self.assertIsNone(widget.valid_group_data)\n        self.assertFalse(widget.is_valid)\n\n        self.send_signal(widget.Inputs.data, self.iris)\n        self.assertIsNotNone(widget.valid_data)\n        self.assertIsNotNone(widget.valid_group_data)\n        self.assertTrue(widget.is_valid)\n\n        X, Y = self.iris.X, self.iris.Y\n        X[:, 0] = np.nan\n        X[:50, 1] = np.nan\n        X[:100, 2] = np.nan\n        Y[75:] = np.nan\n        self.send_signal(widget.Inputs.data, self.iris)\n\n        self._set_var(domain[0])\n        self._set_cvar(domain.class_var)\n        self.assertIs(widget.var, domain[0])\n        self.assertIs(widget.cvar, domain.class_var)\n        self.assertIsNone(widget.valid_data)\n        self.assertIsNone(widget.valid_group_data)\n        self.assertFalse(widget.is_valid)\n        self.assertTrue(err_def_var.is_shown())\n        self.assertFalse(err_def_pair.is_shown())\n        self.assertFalse(warn_nans.is_shown())\n\n        self._set_var(domain[1])\n        self.assertIs(widget.var, domain[1])\n        self.assertIs(widget.cvar, domain.class_var)\n        np.testing.assert_equal(widget.valid_data, X[50:75, 1])\n        np.testing.assert_equal(widget.valid_group_data, Y[50:75])\n        self.assertTrue(widget.is_valid)\n        self.assertFalse(err_def_var.is_shown())\n        self.assertFalse(err_def_pair.is_shown())\n        self.assertTrue(warn_nans.is_shown())\n\n        self._set_var(domain[2])\n        self.assertIs(widget.var, domain[2])\n        self.assertIs(widget.cvar, domain.class_var)\n        self.assertIsNone(widget.valid_data)\n        self.assertIsNone(widget.valid_group_data)\n        self.assertFalse(widget.is_valid)\n        self.assertFalse(err_def_var.is_shown())\n        self.assertTrue(err_def_pair.is_shown())\n        self.assertFalse(warn_nans.is_shown())\n\n        self._set_var(domain[3])\n        self.assertIs(widget.var, domain[3])\n        self.assertIs(widget.cvar, domain.class_var)\n        np.testing.assert_equal(widget.valid_data, X[:75, 3])\n        np.testing.assert_equal(widget.valid_group_data, Y[:75])\n        self.assertTrue(widget.is_valid)\n        self.assertFalse(err_def_var.is_shown())\n        self.assertFalse(err_def_pair.is_shown())\n        self.assertTrue(warn_nans.is_shown())\n\n        self._set_var(domain[0])\n        self._set_cvar(None)\n        self.assertIs(widget.var, domain[0])\n        self.assertIsNone(widget.cvar)\n        self.assertIsNone(widget.valid_data)\n        self.assertIsNone(widget.valid_group_data)\n        self.assertFalse(widget.is_valid)\n        self.assertTrue(err_def_var.is_shown())\n        self.assertFalse(err_def_pair.is_shown())\n        self.assertFalse(warn_nans.is_shown())\n\n        self._set_var(domain[1])\n        self.assertIs(widget.var, domain[1])\n        self.assertIsNone(widget.cvar)\n        np.testing.assert_equal(widget.valid_data, X[50:, 1])\n        self.assertIsNone(widget.valid_group_data)\n        self.assertTrue(widget.is_valid)\n        self.assertFalse(err_def_var.is_shown())\n        self.assertFalse(err_def_pair.is_shown())\n        self.assertTrue(warn_nans.is_shown())\n\n        self._set_var(domain[3])\n        self.assertIs(widget.var, domain[3])\n        self.assertIsNone(widget.cvar)\n        np.testing.assert_equal(widget.valid_data, X[:, 3])\n        self.assertIsNone(widget.valid_group_data)\n        self.assertTrue(widget.is_valid)\n        self.assertFalse(err_def_var.is_shown())\n        self.assertFalse(err_def_pair.is_shown())\n        self.assertFalse(warn_nans.is_shown())\n\n    def test_controls_disabling(self):\n        \"\"\"Widget changes gui for continuous/discrete variables and grouping\"\"\"\n        widget = self.widget\n        self.send_signal(widget.Inputs.data, self.iris)\n\n        cont = self.iris.domain[0]\n        disc = self.iris.domain.class_var\n        cont_box = widget.continuous_box\n        show_probs = widget.controls.show_probs\n        stacked = widget.controls.stacked_columns\n\n        self._set_var(cont)\n        self._set_cvar(disc)\n        self.assertTrue(cont_box.isEnabled())\n        self.assertTrue(show_probs.isEnabled())\n        self.assertTrue(stacked.isEnabled())\n\n        self._set_var(cont)\n        self._set_cvar(None)\n        self.assertTrue(cont_box.isEnabled())\n        self.assertFalse(show_probs.isEnabled())\n        self.assertFalse(stacked.isEnabled())\n\n        self._set_var(disc)\n        self._set_cvar(None)\n        self.assertFalse(cont_box.isEnabled())\n        self.assertFalse(show_probs.isEnabled())\n        self.assertFalse(stacked.isEnabled())\n\n        self._set_var(disc)\n        self._set_cvar(disc)\n        self.assertFalse(cont_box.isEnabled())\n        self.assertTrue(show_probs.isEnabled())\n        self.assertTrue(stacked.isEnabled())\n\n    if os.getenv(\"CI\"):\n        # Testing all combinations takes 10-15 seconds; this should take < 2s\n        # Code for fitter, stacked_columns and show_probs is independent, so\n        # changing them simultaneously doesn't significantly degrade the tests\n        def test_plot_types_combinations(self):\n            \"\"\"Check that the widget doesn't crash at any plot combination\"\"\"\n            from AnyQt.QtWidgets import qApp\n\n            widget = self.widget\n            c = widget.controls\n            self.send_signal(widget.Inputs.data, self.iris)\n            cont = self.iris.domain[0]\n            disc = self.iris.domain.class_var\n            for var in (cont, disc):\n                for cvar in (disc, None):\n                    for b in [0, 1]:\n                        self._set_var(var)\n                        self._set_cvar(cvar)\n                        self._set_fitter(2 * b)\n                        self._set_check(c.stacked_columns, b)\n                        self._set_check(c.show_probs, b)\n                        qApp.processEvents()\n    else:\n        def test_plot_types_combinations(self):\n            \"\"\"Check that the widget doesn't crash at any plot combination\"\"\"\n            # pylint: disable=too-many-nested-blocks\n            from AnyQt.QtWidgets import qApp\n\n            widget = self.widget\n            c = widget.controls\n            self.send_signal(widget.Inputs.data, self.iris)\n            cont = self.iris.domain[0]\n            disc = self.iris.domain.class_var\n            for var in (cont, disc):\n                for cvar in (disc, None):\n                    for fitter in [0, 2]:\n                        for cumulative in [False, True]:\n                            for stack in [False, True]:\n                                for show_probs in [False, True]:\n                                    self._set_var(var)\n                                    self._set_cvar(cvar)\n                                    self._set_fitter(fitter)\n                                    self._set_check(c.cumulative_distr,\n                                                    cumulative)\n                                    self._set_check(c.stacked_columns, stack)\n                                    self._set_check(c.show_probs, show_probs)\n                                    qApp.processEvents()\n\n    def test_selection_grouping(self):\n        \"\"\"Widget groups consecutive selected bars\"\"\"\n        widget = self.widget\n        self.send_signal(widget.Inputs.data, self.iris)\n        self._set_slider(len(widget.binnings) - 1)\n        widget.selection = {1, 2, 3, 5, 6, 9}\n        widget.plot_mark.addItem = Mock()\n        widget.show_selection()\n        widget._on_end_selecting()\n        self.assertEqual(widget.plot_mark.addItem.call_count, 3)\n        out_selected = self.get_output(widget.Outputs.selected_data)\n        self.assertEqual(\n            len(out_selected.domain[ANNOTATED_DATA_FEATURE_NAME].values), 3)\n\n    def test_report(self):\n        \"\"\"Report doesn't crash\"\"\"\n        widget = self.widget\n        self.send_signal(widget.Inputs.data, self.iris)\n        widget.send_report()",
                                "ast_type_str": "ClassDef",
                                "start_lineno": 17,
                                "end_lineno": 466,
                                "parent": null
                            }
                        }
                    ],
                    "added_entities": [],
                    "deleted_entities": []
                }
            ]
        }
    ],
    "old_commit_hash": "69d9a7d9922769ffc0bd1aa6f050690775f378b8^",
    "new_commit_hash": "69d9a7d9922769ffc0bd1aa6f050690775f378b8",
    "commit_message": "OWDistribution: Revert bin width slider",
    "commit_date": "2019-07-12T12:55:05+02:00",
    "metadata": {}
}
{
    "repo_name": "orange3",
    "new_commit_hash": "69d9a7d9922769ffc0bd1aa6f050690775f378b8",
    "test_file_codes": [
        "# Test methods with long descriptive names can omit docstrings\n# pylint: disable=missing-docstring,protected-access\nimport os\nimport unittest\nfrom unittest.mock import Mock\n\nimport numpy as np\nfrom AnyQt.QtCore import QItemSelection\n\nfrom Orange.data import Table, Domain, DiscreteVariable\nfrom Orange.widgets.tests.base import WidgetTest\nfrom Orange.widgets.utils.annotated_data import ANNOTATED_DATA_FEATURE_NAME\nfrom Orange.widgets.utils.itemmodels import DomainModel\nfrom Orange.widgets.visualize.owdistributions import OWDistributions\n\n\nclass TestOWDistributions(WidgetTest):\n    def setUp(self):\n        self.widget = self.create_widget(OWDistributions)  #: OWDistributions\n        self.iris = Table(\"iris\")\n\n    def _set_cvar(self, cvar):\n        combo = self.widget.controls.cvar\n        self.widget.cvar = cvar\n        combo.activated[int].emit(combo.currentIndex())\n        combo.activated[str].emit(combo.currentText())\n\n    def _set_fitter(self, i):\n        combo = self.widget.controls.fitted_distribution\n        combo.setCurrentIndex(i)\n        combo.activated[int].emit(combo.currentIndex())\n        combo.activated[str].emit(combo.currentText())\n\n    def _set_var(self, var):\n        listview = self.widget.controls.var\n        model = listview.model()\n        index = var if isinstance(var, int) else model.indexOf(var)\n        selectionmodel = listview.selectionModel()\n        oldselection = selectionmodel.selection()\n        newselection = QItemSelection()\n        newselection.select(model.index(index, 0), model.index(index, 0))\n        selectionmodel.select(newselection, selectionmodel.ClearAndSelect)\n        selectionmodel.selectionChanged.emit(newselection, oldselection)\n\n    @staticmethod\n    def _set_check(checkbox, value):\n        checkbox.setCheckState(value)\n        checkbox.toggled[bool].emit(value)\n\n    def _set_slider(self, i):\n        slider = self.widget.controls.number_of_bins\n        slider.setValue(i)\n        slider.valueChanged[int].emit(i)\n        slider.sliderReleased.emit()\n\n    def test_set_data(self):\n        \"\"\"Basic test of set_data and removal of data\"\"\"\n        widget = self.widget\n        var_model = widget.controls.var.model()\n        cvar_model = widget.controls.cvar.model()\n\n        domain = self.iris.domain\n        self.send_signal(widget.Inputs.data, self.iris)\n        self.assertEqual({var.name for var in var_model},\n                         {var.name for var in domain.variables})\n        self.assertEqual(list(cvar_model),\n                         [None, DomainModel.Separator, domain.class_var])\n        self.assertIs(widget.var, domain[0])\n        self.assertIs(widget.cvar, domain.class_var)\n        np.testing.assert_equal(widget.valid_data, self.iris.X[:, 0])\n        np.testing.assert_equal(widget.valid_group_data, self.iris.Y)\n        self.assertEqual(\n            len(self.get_output(widget.Outputs.histogram_data)), 150)\n        self.assertIsNone(self.get_output(widget.Outputs.annotated_data))\n        self.assertIsNone(self.get_output(widget.Outputs.selected_data))\n\n        # Data gone: clean up\n        widget.selection.add(0)\n        widget._clear_plot = Mock()\n        self.send_signal(widget.Inputs.data, None)\n        self.assertEqual(len(var_model), 0)\n        self.assertEqual(list(cvar_model), [None])\n        self.assertIsNone(widget.var)\n        self.assertIsNone(widget.cvar)\n\n        self.assertEqual(widget.selection, set())\n        self.assertIsNone(widget.valid_data)\n        self.assertIsNone(widget.valid_group_data)\n        self.assertIsNone(self.get_output(widget.Outputs.histogram_data))\n        self.assertIsNone(self.get_output(widget.Outputs.annotated_data))\n        self.assertIsNone(self.get_output(widget.Outputs.selected_data))\n        widget._clear_plot.assert_called()\n\n    def test_set_data_no_class_no_discrete(self):\n        \"\"\"Widget is properly set up when there is no class and discrete vars\"\"\"\n        widget = self.widget\n        var_model = widget.controls.var.model()\n        cvar_model = widget.controls.cvar.model()\n\n        domain = Domain(self.iris.domain.attributes, [])\n        data = self.iris.transform(domain)\n        self.send_signal(widget.Inputs.data, data)\n        self.assertEqual({var.name for var in var_model},\n                         {var.name for var in domain.attributes})\n        self.assertEqual(list(cvar_model), [None])\n        self.assertIs(widget.var, domain[0])\n        self.assertIs(widget.cvar, None)\n        np.testing.assert_equal(widget.valid_data, self.iris.X[:, 0])\n        self.assertIsNone(widget.valid_group_data)\n        self.assertEqual(\n            len(self.get_output(widget.Outputs.histogram_data)), 150)\n        self.assertIsNone(self.get_output(widget.Outputs.annotated_data))\n        self.assertIsNone(self.get_output(widget.Outputs.selected_data))\n\n    def test_set_data_no_class(self):\n        \"\"\"Widget is properly set up when there is no class\"\"\"\n        widget = self.widget\n        var_model = widget.controls.var.model()\n        cvar_model = widget.controls.cvar.model()\n        iris = self.iris\n\n        domain = Domain(iris.domain.attributes + iris.domain.class_vars)\n        data = iris.transform(domain)\n        self.send_signal(widget.Inputs.data, data)\n        self.assertEqual({var.name for var in var_model},\n                         {var.name for var in domain.attributes})\n        self.assertEqual(list(cvar_model),\n                         [None, DomainModel.Separator, iris.domain.class_var])\n        self.assertIs(widget.var, domain[0])\n        self.assertIs(widget.cvar, None)\n        np.testing.assert_equal(widget.valid_data, self.iris.X[:, 0])\n        self.assertIsNone(widget.valid_group_data)\n        self.assertEqual(\n            len(self.get_output(widget.Outputs.histogram_data)), 150)\n        self.assertIsNone(self.get_output(widget.Outputs.annotated_data))\n        self.assertIsNone(self.get_output(widget.Outputs.selected_data))\n\n    def test_set_data_reg_class(self):\n        \"\"\"Widget is properly set up when the target is numeric\"\"\"\n        widget = self.widget\n        var_model = widget.controls.var.model()\n        cvar_model = widget.controls.cvar.model()\n        iris = self.iris\n\n        domain = Domain(iris.domain.attributes[:3] + iris.domain.class_vars,\n                        iris.domain.attributes[3])\n        data = iris.transform(domain)\n        self.send_signal(widget.Inputs.data, data)\n        self.assertEqual({var.name for var in var_model},\n                         {var.name for var in domain.variables})\n        self.assertEqual(list(cvar_model),\n                         [None, DomainModel.Separator, iris.domain.class_var])\n        self.assertIs(widget.var, domain[0])\n        self.assertIs(widget.cvar, None)\n        np.testing.assert_equal(widget.valid_data, self.iris.X[:, 0])\n        self.assertIsNone(widget.valid_group_data)\n        self.assertEqual(\n            len(self.get_output(widget.Outputs.histogram_data)), 150)\n        self.assertIsNone(self.get_output(widget.Outputs.annotated_data))\n        self.assertIsNone(self.get_output(widget.Outputs.selected_data))\n\n    def test_set_data_reg_class_no_discrete(self):\n        \"\"\"Widget is properly set up with regression and no discrete vars\"\"\"\n        widget = self.widget\n        var_model = widget.controls.var.model()\n        cvar_model = widget.controls.cvar.model()\n        iris = self.iris\n\n        domain = Domain(iris.domain.attributes[:3], iris.domain.attributes[3])\n        data = iris.transform(domain)\n        self.send_signal(widget.Inputs.data, data)\n        self.assertEqual({var.name for var in var_model},\n                         {var.name for var in domain.variables})\n        self.assertEqual(list(cvar_model), [None])\n        self.assertIs(widget.var, domain[0])\n        self.assertIs(widget.cvar, None)\n        np.testing.assert_equal(widget.valid_data, self.iris.X[:, 0])\n        self.assertIsNone(widget.valid_group_data)\n        self.assertEqual(\n            len(self.get_output(widget.Outputs.histogram_data)), 150)\n        self.assertIsNone(self.get_output(widget.Outputs.annotated_data))\n        self.assertIsNone(self.get_output(widget.Outputs.selected_data))\n\n    def test_switch_var(self):\n        \"\"\"Widget reset and recomputes when changing var\"\"\"\n        widget = self.widget\n\n        self.send_signal(widget.Inputs.data, self.iris)\n        binnings = widget.binnings.copy()\n        valid_data = widget.valid_data.copy()\n        widget.selection.add(1)\n        widget._clear_plot = Mock()\n        widget.apply = Mock()\n\n        self._set_var(2)\n        self.assertFalse(binnings[0].shape == widget.binnings[0].shape\n                         and np.allclose(binnings[0], widget.binnings[0]))\n        self.assertFalse(valid_data.shape == widget.valid_data.shape\n                         and np.allclose(valid_data, widget.valid_data))\n        self.assertEqual(widget.selection, set())\n        widget._clear_plot.assert_called()\n        widget.apply.assert_called()\n\n    def test_switch_cvar(self):\n        \"\"\"Widget reset and recomputes when changing splitting variable\"\"\"\n        widget = self.widget\n\n        y = self.iris.domain.class_var\n        extra = DiscreteVariable(\"foo\", values=[\"a\", \"b\"])\n        domain = Domain(self.iris.domain.attributes + (extra, ), y)\n        data = self.iris.transform(domain)\n        data.X[:75, -1] = 0\n        data.X[75:120, -1] = 1\n        self.send_signal(widget.Inputs.data, data)\n        self._set_var(2)\n        self._set_cvar(y)\n\n        binnings = widget.binnings\n        valid_data = widget.valid_data.copy()\n        widget.selection.add(1)\n        widget._clear_plot = Mock()\n        widget.apply = Mock()\n\n        self.assertEqual(len(widget.valid_group_data), 150)\n\n        self._set_cvar(extra)\n        self.assertIs(binnings, widget.binnings)\n        np.testing.assert_equal(valid_data[:120], widget.valid_data)\n        self.assertEqual(len(widget.valid_group_data), 120)\n        self.assertEqual(widget.selection, {1})\n        widget._clear_plot.assert_called()\n        widget.apply.assert_called()\n        widget._clear_plot.reset_mock()\n        widget.apply.reset_mock()\n\n        self._set_cvar(None)\n        self.assertIs(binnings, widget.binnings)\n        np.testing.assert_equal(valid_data, widget.valid_data)\n        self.assertIsNone(widget.valid_group_data)\n        self.assertEqual(widget.selection, {1})\n        widget._clear_plot.assert_called()\n        widget.apply.assert_called()\n\n    def test_on_bins_changed(self):\n        \"\"\"Widget replots and outputs data when the number of bins is changed\"\"\"\n        widget = self.widget\n        self.send_signal(widget.Inputs.data, self.iris)\n\n        self._set_slider(0)\n        widget.selection.add(1)\n        n_bars = len(widget.bar_items)\n        widget.apply = Mock()\n\n        self._set_slider(1)\n        self.assertEqual(widget.selection, set())\n        self.assertGreater(n_bars, len(widget.bar_items))\n        widget.apply.assert_called_once()\n\n    def test_set_valid_data(self):\n        \"\"\"Widget handles nans in data\"\"\"\n        widget = self.widget\n        err_def_var = widget.Error.no_defined_values_var\n        err_def_pair = widget.Error.no_defined_values_pair\n        warn_nans = widget.Warning.ignored_nans\n\n        domain = self.iris.domain\n\n        self.assertIsNone(widget.var)\n        self.assertIsNone(widget.cvar)\n        self.assertIsNone(widget.valid_data)\n        self.assertIsNone(widget.valid_group_data)\n        self.assertFalse(widget.is_valid)\n\n        widget.valid_data = Mock()\n        widget.group_valid_data = Mock()\n        widget.set_valid_data()\n        self.assertIsNone(widget.valid_data)\n        self.assertIsNone(widget.valid_group_data)\n        self.assertFalse(widget.is_valid)\n\n        self.send_signal(widget.Inputs.data, self.iris)\n        self.assertIsNotNone(widget.valid_data)\n        self.assertIsNotNone(widget.valid_group_data)\n        self.assertTrue(widget.is_valid)\n\n        X, Y = self.iris.X, self.iris.Y\n        X[:, 0] = np.nan\n        X[:50, 1] = np.nan\n        X[:100, 2] = np.nan\n        Y[75:] = np.nan\n        self.send_signal(widget.Inputs.data, self.iris)\n\n        self._set_var(domain[0])\n        self._set_cvar(domain.class_var)\n        self.assertIs(widget.var, domain[0])\n        self.assertIs(widget.cvar, domain.class_var)\n        self.assertIsNone(widget.valid_data)\n        self.assertIsNone(widget.valid_group_data)\n        self.assertFalse(widget.is_valid)\n        self.assertTrue(err_def_var.is_shown())\n        self.assertFalse(err_def_pair.is_shown())\n        self.assertFalse(warn_nans.is_shown())\n\n        self._set_var(domain[1])\n        self.assertIs(widget.var, domain[1])\n        self.assertIs(widget.cvar, domain.class_var)\n        np.testing.assert_equal(widget.valid_data, X[50:75, 1])\n        np.testing.assert_equal(widget.valid_group_data, Y[50:75])\n        self.assertTrue(widget.is_valid)\n        self.assertFalse(err_def_var.is_shown())\n        self.assertFalse(err_def_pair.is_shown())\n        self.assertTrue(warn_nans.is_shown())\n\n        self._set_var(domain[2])\n        self.assertIs(widget.var, domain[2])\n        self.assertIs(widget.cvar, domain.class_var)\n        self.assertIsNone(widget.valid_data)\n        self.assertIsNone(widget.valid_group_data)\n        self.assertFalse(widget.is_valid)\n        self.assertFalse(err_def_var.is_shown())\n        self.assertTrue(err_def_pair.is_shown())\n        self.assertFalse(warn_nans.is_shown())\n\n        self._set_var(domain[3])\n        self.assertIs(widget.var, domain[3])\n        self.assertIs(widget.cvar, domain.class_var)\n        np.testing.assert_equal(widget.valid_data, X[:75, 3])\n        np.testing.assert_equal(widget.valid_group_data, Y[:75])\n        self.assertTrue(widget.is_valid)\n        self.assertFalse(err_def_var.is_shown())\n        self.assertFalse(err_def_pair.is_shown())\n        self.assertTrue(warn_nans.is_shown())\n\n        self._set_var(domain[0])\n        self._set_cvar(None)\n        self.assertIs(widget.var, domain[0])\n        self.assertIsNone(widget.cvar)\n        self.assertIsNone(widget.valid_data)\n        self.assertIsNone(widget.valid_group_data)\n        self.assertFalse(widget.is_valid)\n        self.assertTrue(err_def_var.is_shown())\n        self.assertFalse(err_def_pair.is_shown())\n        self.assertFalse(warn_nans.is_shown())\n\n        self._set_var(domain[1])\n        self.assertIs(widget.var, domain[1])\n        self.assertIsNone(widget.cvar)\n        np.testing.assert_equal(widget.valid_data, X[50:, 1])\n        self.assertIsNone(widget.valid_group_data)\n        self.assertTrue(widget.is_valid)\n        self.assertFalse(err_def_var.is_shown())\n        self.assertFalse(err_def_pair.is_shown())\n        self.assertTrue(warn_nans.is_shown())\n\n        self._set_var(domain[3])\n        self.assertIs(widget.var, domain[3])\n        self.assertIsNone(widget.cvar)\n        np.testing.assert_equal(widget.valid_data, X[:, 3])\n        self.assertIsNone(widget.valid_group_data)\n        self.assertTrue(widget.is_valid)\n        self.assertFalse(err_def_var.is_shown())\n        self.assertFalse(err_def_pair.is_shown())\n        self.assertFalse(warn_nans.is_shown())\n\n    def test_controls_disabling(self):\n        \"\"\"Widget changes gui for continuous/discrete variables and grouping\"\"\"\n        widget = self.widget\n        self.send_signal(widget.Inputs.data, self.iris)\n\n        cont = self.iris.domain[0]\n        disc = self.iris.domain.class_var\n        cont_box = widget.continuous_box\n        show_probs = widget.controls.show_probs\n        stacked = widget.controls.stacked_columns\n\n        self._set_var(cont)\n        self._set_cvar(disc)\n        self.assertTrue(cont_box.isEnabled())\n        self.assertTrue(show_probs.isEnabled())\n        self.assertTrue(stacked.isEnabled())\n\n        self._set_var(cont)\n        self._set_cvar(None)\n        self.assertTrue(cont_box.isEnabled())\n        self.assertFalse(show_probs.isEnabled())\n        self.assertFalse(stacked.isEnabled())\n\n        self._set_var(disc)\n        self._set_cvar(None)\n        self.assertFalse(cont_box.isEnabled())\n        self.assertFalse(show_probs.isEnabled())\n        self.assertFalse(stacked.isEnabled())\n\n        self._set_var(disc)\n        self._set_cvar(disc)\n        self.assertFalse(cont_box.isEnabled())\n        self.assertTrue(show_probs.isEnabled())\n        self.assertTrue(stacked.isEnabled())\n\n    if os.getenv(\"CI\"):\n        # Testing all combinations takes 10-15 seconds; this should take < 2s\n        # Code for fitter, stacked_columns and show_probs is independent, so\n        # changing them simultaneously doesn't significantly degrade the tests\n        def test_plot_types_combinations(self):\n            \"\"\"Check that the widget doesn't crash at any plot combination\"\"\"\n            from AnyQt.QtWidgets import qApp\n\n            widget = self.widget\n            c = widget.controls\n            self.send_signal(widget.Inputs.data, self.iris)\n            cont = self.iris.domain[0]\n            disc = self.iris.domain.class_var\n            for var in (cont, disc):\n                for cvar in (disc, None):\n                    for b in [0, 1]:\n                        self._set_var(var)\n                        self._set_cvar(cvar)\n                        self._set_fitter(2 * b)\n                        self._set_check(c.stacked_columns, b)\n                        self._set_check(c.show_probs, b)\n                        qApp.processEvents()\n    else:\n        def test_plot_types_combinations(self):\n            \"\"\"Check that the widget doesn't crash at any plot combination\"\"\"\n            # pylint: disable=too-many-nested-blocks\n            from AnyQt.QtWidgets import qApp\n\n            widget = self.widget\n            c = widget.controls\n            self.send_signal(widget.Inputs.data, self.iris)\n            cont = self.iris.domain[0]\n            disc = self.iris.domain.class_var\n            for var in (cont, disc):\n                for cvar in (disc, None):\n                    for fitter in [0, 2]:\n                        for cumulative in [False, True]:\n                            for stack in [False, True]:\n                                for show_probs in [False, True]:\n                                    self._set_var(var)\n                                    self._set_cvar(cvar)\n                                    self._set_fitter(fitter)\n                                    self._set_check(c.cumulative_distr,\n                                                    cumulative)\n                                    self._set_check(c.stacked_columns, stack)\n                                    self._set_check(c.show_probs, show_probs)\n                                    qApp.processEvents()\n\n    def test_selection_grouping(self):\n        \"\"\"Widget groups consecutive selected bars\"\"\"\n        widget = self.widget\n        self.send_signal(widget.Inputs.data, self.iris)\n        self._set_slider(0)\n        widget.selection = {1, 2, 3, 5, 6, 9}\n        widget.plot_mark.addItem = Mock()\n        widget.show_selection()\n        widget._on_end_selecting()\n        self.assertEqual(widget.plot_mark.addItem.call_count, 3)\n        out_selected = self.get_output(widget.Outputs.selected_data)\n        self.assertEqual(\n            len(out_selected.domain[ANNOTATED_DATA_FEATURE_NAME].values), 3)\n\n    def test_report(self):\n        \"\"\"Report doesn't crash\"\"\"\n        widget = self.widget\n        self.send_signal(widget.Inputs.data, self.iris)\n        widget.send_report()\n\n\nif __name__ == \"__main__\":\n    unittest.main()\n"
    ],
    "test_file_names": [
        "test_1.py"
    ],
    "setup_res_code": 0,
    "setup_res_stdout": "Starting Orange installation attempts...\nAttempting installation with Python 3.7...\nWarning: 'keywords' should be a list, got type 'tuple'\nWarning: 'classifiers' should be a list, got type 'tuple'\nWarning: 'keywords' should be a list, got type 'tuple'\nWarning: 'classifiers' should be a list, got type 'tuple'\nrunning build_ext\nrunning build_src\nbuild_src\nbuilding extension \"Orange.classification._simple_tree\" sources\nbuilding extension \"Orange.classification._tree_scorers\" sources\nbuilding extension \"Orange.data._valuecount\" sources\nbuilding extension \"Orange.data._contingency\" sources\nbuilding extension \"Orange.data._io\" sources\nbuilding extension \"Orange.data._variable\" sources\nbuilding extension \"Orange.distance._distance\" sources\nbuilding extension \"Orange.preprocess._discretize\" sources\nbuilding extension \"Orange.preprocess._relieff\" sources\nbuilding extension \"Orange.widgets.utils._grid_density\" sources\nbuild_src: building npy-pkg config files\ncustomize UnixCCompiler\nC compiler: cc -pthread -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -I/tools/deps/include -I/tools/deps/include/ncursesw -fPIC\n\ncreating /tmp/tmpvvv4u9b5/tmp\ncreating /tmp/tmpvvv4u9b5/tmp/tmpvvv4u9b5\ncompile options: '-MMD -MF /tmp/tmpvvv4u9b5/file.c.d -c'\ncc: /tmp/tmpvvv4u9b5/file.c\ncustomize UnixCCompiler using build_ext\ncustomize UnixCCompiler\nC compiler: cc -pthread -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -I/tools/deps/include -I/tools/deps/include/ncursesw -fPIC\n\ncreating /tmp/tmpdudw0cpz/tmp\ncreating /tmp/tmpdudw0cpz/tmp/tmpdudw0cpz\ncompile options: '-MMD -MF /tmp/tmpdudw0cpz/file.c.d -c'\ncc: /tmp/tmpdudw0cpz/file.c\ncustomize UnixCCompiler using build_ext\nbuilding 'Orange.classification._simple_tree' extension\ncompiling C sources\nC compiler: cc -pthread -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -I/tools/deps/include -I/tools/deps/include/ncursesw -fPIC\n\ncreating build/temp.linux-x86_64-3.7/Orange\ncreating build/temp.linux-x86_64-3.7/Orange/classification\ncompile options: '-I/home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages/numpy/core/include -I/home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/include -I/home/gcpuser/.local/share/uv/python/cpython-3.7.9-linux-x86_64-gnu/include/python3.7m -c'\ncc: Orange/classification/_simple_tree.c\ncc -pthread -shared -L/tools/deps/lib build/temp.linux-x86_64-3.7/Orange/classification/_simple_tree.o -L/home/gcpuser/.local/share/uv/python/cpython-3.7.9-linux-x86_64-gnu/lib -lm -lpython3.7m -o Orange/classification/_simple_tree.cpython-37m-x86_64-linux-gnu.so\nbuilding 'Orange.classification._tree_scorers' extension\ncompiling C sources\nC compiler: cc -pthread -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -I/tools/deps/include -I/tools/deps/include/ncursesw -fPIC\n\ncompile options: '-I/home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages/numpy/core/include -I/home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages/numpy/core/include -I/home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/include -I/home/gcpuser/.local/share/uv/python/cpython-3.7.9-linux-x86_64-gnu/include/python3.7m -c'\ncc: Orange/classification/_tree_scorers.c\ncc -pthread -shared -L/tools/deps/lib build/temp.linux-x86_64-3.7/Orange/classification/_tree_scorers.o -L/home/gcpuser/.local/share/uv/python/cpython-3.7.9-linux-x86_64-gnu/lib -lm -lpython3.7m -o Orange/classification/_tree_scorers.cpython-37m-x86_64-linux-gnu.so\nbuilding 'Orange.data._valuecount' extension\ncompiling C sources\nC compiler: cc -pthread -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -I/tools/deps/include -I/tools/deps/include/ncursesw -fPIC\n\ncreating build/temp.linux-x86_64-3.7/Orange/data\ncompile options: '-I/home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages/numpy/core/include -I/home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages/numpy/core/include -I/home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/include -I/home/gcpuser/.local/share/uv/python/cpython-3.7.9-linux-x86_64-gnu/include/python3.7m -c'\ncc: Orange/data/_valuecount.c\ncc -pthread -shared -L/tools/deps/lib build/temp.linux-x86_64-3.7/Orange/data/_valuecount.o -L/home/gcpuser/.local/share/uv/python/cpython-3.7.9-linux-x86_64-gnu/lib -lm -lpython3.7m -o Orange/data/_valuecount.cpython-37m-x86_64-linux-gnu.so\nbuilding 'Orange.data._contingency' extension\ncompiling C sources\nC compiler: cc -pthread -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -I/tools/deps/include -I/tools/deps/include/ncursesw -fPIC\n\ncompile options: '-I/home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages/numpy/core/include -I/home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages/numpy/core/include -I/home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/include -I/home/gcpuser/.local/share/uv/python/cpython-3.7.9-linux-x86_64-gnu/include/python3.7m -c'\ncc: Orange/data/_contingency.c\ncc -pthread -shared -L/tools/deps/lib build/temp.linux-x86_64-3.7/Orange/data/_contingency.o -L/home/gcpuser/.local/share/uv/python/cpython-3.7.9-linux-x86_64-gnu/lib -lm -lpython3.7m -o Orange/data/_contingency.cpython-37m-x86_64-linux-gnu.so\nbuilding 'Orange.data._io' extension\ncompiling C sources\nC compiler: cc -pthread -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -I/tools/deps/include -I/tools/deps/include/ncursesw -fPIC\n\ncompile options: '-I/home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages/numpy/core/include -I/home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages/numpy/core/include -I/home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/include -I/home/gcpuser/.local/share/uv/python/cpython-3.7.9-linux-x86_64-gnu/include/python3.7m -c'\ncc: Orange/data/_io.c\ncc -pthread -shared -L/tools/deps/lib build/temp.linux-x86_64-3.7/Orange/data/_io.o -L/home/gcpuser/.local/share/uv/python/cpython-3.7.9-linux-x86_64-gnu/lib -lm -lpython3.7m -o Orange/data/_io.cpython-37m-x86_64-linux-gnu.so\nbuilding 'Orange.data._variable' extension\ncompiling C sources\nC compiler: cc -pthread -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -I/tools/deps/include -I/tools/deps/include/ncursesw -fPIC\n\ncompile options: '-I/home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages/numpy/core/include -I/home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages/numpy/core/include -I/home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/include -I/home/gcpuser/.local/share/uv/python/cpython-3.7.9-linux-x86_64-gnu/include/python3.7m -c'\ncc: Orange/data/_variable.c\ncc -pthread -shared -L/tools/deps/lib build/temp.linux-x86_64-3.7/Orange/data/_variable.o -L/home/gcpuser/.local/share/uv/python/cpython-3.7.9-linux-x86_64-gnu/lib -lm -lpython3.7m -o Orange/data/_variable.cpython-37m-x86_64-linux-gnu.so\nbuilding 'Orange.distance._distance' extension\ncompiling C sources\nC compiler: cc -pthread -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -I/tools/deps/include -I/tools/deps/include/ncursesw -fPIC\n\ncreating build/temp.linux-x86_64-3.7/Orange/distance\ncompile options: '-I/home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages/numpy/core/include -I/home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages/numpy/core/include -I/home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/include -I/home/gcpuser/.local/share/uv/python/cpython-3.7.9-linux-x86_64-gnu/include/python3.7m -c'\ncc: Orange/distance/_distance.c\ncc -pthread -shared -L/tools/deps/lib build/temp.linux-x86_64-3.7/Orange/distance/_distance.o -L/home/gcpuser/.local/share/uv/python/cpython-3.7.9-linux-x86_64-gnu/lib -lm -lpython3.7m -o Orange/distance/_distance.cpython-37m-x86_64-linux-gnu.so\nbuilding 'Orange.preprocess._discretize' extension\ncompiling C sources\nC compiler: cc -pthread -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -I/tools/deps/include -I/tools/deps/include/ncursesw -fPIC\n\ncreating build/temp.linux-x86_64-3.7/Orange/preprocess\ncompile options: '-I/home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages/numpy/core/include -I/home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages/numpy/core/include -I/home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/include -I/home/gcpuser/.local/share/uv/python/cpython-3.7.9-linux-x86_64-gnu/include/python3.7m -c'\ncc: Orange/preprocess/_discretize.c\ncc -pthread -shared -L/tools/deps/lib build/temp.linux-x86_64-3.7/Orange/preprocess/_discretize.o -L/home/gcpuser/.local/share/uv/python/cpython-3.7.9-linux-x86_64-gnu/lib -lm -lpython3.7m -o Orange/preprocess/_discretize.cpython-37m-x86_64-linux-gnu.so\nbuilding 'Orange.preprocess._relieff' extension\ncompiling C++ sources\nC compiler: c++ -pthread -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -I/tools/deps/include -I/tools/deps/include/ncursesw -fPIC\n\ncompile options: '-I/home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages/numpy/core/include -I/home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages/numpy/core/include -I/home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/include -I/home/gcpuser/.local/share/uv/python/cpython-3.7.9-linux-x86_64-gnu/include/python3.7m -c'\nc++: Orange/preprocess/_relieff.cpp\nc++ -pthread -shared -L/tools/deps/lib build/temp.linux-x86_64-3.7/Orange/preprocess/_relieff.o -L/home/gcpuser/.local/share/uv/python/cpython-3.7.9-linux-x86_64-gnu/lib -lm -lpython3.7m -o Orange/preprocess/_relieff.cpython-37m-x86_64-linux-gnu.so\nbuilding 'Orange.widgets.utils._grid_density' extension\ncompiling C++ sources\nC compiler: c++ -pthread -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -I/tools/deps/include -I/tools/deps/include/ncursesw -fPIC\n\ncreating build/temp.linux-x86_64-3.7/Orange/widgets\ncreating build/temp.linux-x86_64-3.7/Orange/widgets/utils\ncompile options: '-I/home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages/numpy/core/include -I/home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/include -I/home/gcpuser/.local/share/uv/python/cpython-3.7.9-linux-x86_64-gnu/include/python3.7m -c'\nc++: Orange/widgets/utils/_grid_density.cpp\nc++ -pthread -shared -L/tools/deps/lib build/temp.linux-x86_64-3.7/Orange/widgets/utils/_grid_density.o -L/home/gcpuser/.local/share/uv/python/cpython-3.7.9-linux-x86_64-gnu/lib -lm -lpython3.7m -o Orange/widgets/utils/_grid_density.cpython-37m-x86_64-linux-gnu.so\nWarning: 'keywords' should be a list, got type 'tuple'\nWarning: 'classifiers' should be a list, got type 'tuple'\nWarning: 'keywords' should be a list, got type 'tuple'\nWarning: 'classifiers' should be a list, got type 'tuple'\nrunning develop\nrunning build_scripts\nrunning egg_info\nrunning build_src\nbuild_src\nbuilding extension \"Orange.classification._simple_tree\" sources\nbuilding extension \"Orange.classification._tree_scorers\" sources\nbuilding extension \"Orange.data._valuecount\" sources\nbuilding extension \"Orange.data._contingency\" sources\nbuilding extension \"Orange.data._io\" sources\nbuilding extension \"Orange.data._variable\" sources\nbuilding extension \"Orange.distance._distance\" sources\nbuilding extension \"Orange.preprocess._discretize\" sources\nbuilding extension \"Orange.preprocess._relieff\" sources\nbuilding extension \"Orange.widgets.utils._grid_density\" sources\nbuild_src: building npy-pkg config files\ncreating Orange3.egg-info\nwriting Orange3.egg-info/PKG-INFO\nwriting dependency_links to Orange3.egg-info/dependency_links.txt\nwriting entry points to Orange3.egg-info/entry_points.txt\nwriting requirements to Orange3.egg-info/requires.txt\nwriting top-level names to Orange3.egg-info/top_level.txt\nwriting manifest file 'Orange3.egg-info/SOURCES.txt'\nreading manifest file 'Orange3.egg-info/SOURCES.txt'\nreading manifest template 'MANIFEST.in'\nwarning: no files found matching 'README*' under directory 'Orange'\nwarning: no files found matching 'LICENSE' under directory 'Orange'\nwarning: no files found matching '*.basket' under directory 'Orange/datasets'\nwarning: no files found matching '*.js' under directory 'Orange/widgets'\nwarning: no files found matching '*.css' under directory 'Orange/widgets'\nwarning: no files found matching '*.html' under directory 'Orange/widgets'\nwarning: no files found matching 'COPYING'\nadding license file 'LICENSE'\nwriting manifest file 'Orange3.egg-info/SOURCES.txt'\nrunning build_ext\ncustomize UnixCCompiler\nC compiler: cc -pthread -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -I/tools/deps/include -I/tools/deps/include/ncursesw -fPIC\n\ncreating /tmp/tmp095kjl_n/tmp\ncreating /tmp/tmp095kjl_n/tmp/tmp095kjl_n\ncompile options: '-MMD -MF /tmp/tmp095kjl_n/file.c.d -c'\ncc: /tmp/tmp095kjl_n/file.c\ncustomize UnixCCompiler using build_ext\ncustomize UnixCCompiler\nC compiler: cc -pthread -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -I/tools/deps/include -I/tools/deps/include/ncursesw -fPIC\n\ncreating /tmp/tmpbb96gdcu/tmp\ncreating /tmp/tmpbb96gdcu/tmp/tmpbb96gdcu\ncompile options: '-MMD -MF /tmp/tmpbb96gdcu/file.c.d -c'\ncc: /tmp/tmpbb96gdcu/file.c\ncustomize UnixCCompiler using build_ext\nCreating /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages/Orange3.egg-link (link to .)\nAdding Orange3 3.23.0.dev0+69d9a7d to easy-install.pth file\nInstalling orange-canvas script to /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/bin\n\nInstalled /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8\nProcessing dependencies for Orange3==3.23.0.dev0+69d9a7d\nSearching for XlsxWriter==3.2.0\nBest match: XlsxWriter 3.2.0\nAdding XlsxWriter 3.2.0 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages\nSearching for xlrd==2.0.1\nBest match: xlrd 2.0.1\nAdding xlrd 2.0.1 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages\nSearching for setuptools==59.8.0\nBest match: setuptools 59.8.0\nAdding setuptools 59.8.0 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages\nSearching for serverfiles==0.3.1\nBest match: serverfiles 0.3.1\nAdding serverfiles 0.3.1 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages\nSearching for scipy==1.7.3\nBest match: scipy 1.7.3\nAdding scipy 1.7.3 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages\nSearching for scikit-learn==1.0.2\nBest match: scikit-learn 1.0.2\nAdding scikit-learn 1.0.2 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages\nSearching for requests==2.31.0\nBest match: requests 2.31.0\nAdding requests 2.31.0 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages\nSearching for python-louvain==0.16\nBest match: python-louvain 0.16\nAdding python-louvain 0.16 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages\nSearching for pyqtgraph==0.12.4\nBest match: pyqtgraph 0.12.4\nAdding pyqtgraph 0.12.4 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages\nSearching for pip==24.0\nBest match: pip 24.0\nAdding pip 24.0 to easy-install.pth file\nInstalling pip script to /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/bin\nInstalling pip3 script to /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/bin\nInstalling pip3.10 script to /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/bin\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages\nSearching for pandas==1.3.5\nBest match: pandas 1.3.5\nAdding pandas 1.3.5 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages\nSearching for orange-widget-base==4.0.1\nBest match: orange-widget-base 4.0.1\nAdding orange-widget-base 4.0.1 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages\nSearching for orange-canvas-core==0.1.35\nBest match: orange-canvas-core 0.1.35\nAdding orange-canvas-core 0.1.35 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages\nSearching for openTSNE==1.0.1\nBest match: openTSNE 1.0.1\nAdding openTSNE 1.0.1 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages\nSearching for numpy==1.17.5\nBest match: numpy 1.17.5\nAdding numpy 1.17.5 to easy-install.pth file\nInstalling f2py script to /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/bin\nInstalling f2py3 script to /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/bin\nInstalling f2py3.7 script to /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/bin\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages\nSearching for networkx==2.6.3\nBest match: networkx 2.6.3\nAdding networkx 2.6.3 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages\nSearching for matplotlib==3.5.3\nBest match: matplotlib 3.5.3\nAdding matplotlib 3.5.3 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages\nSearching for keyrings.alt==4.2.0\nBest match: keyrings.alt 4.2.0\nAdding keyrings.alt 4.2.0 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages\nSearching for keyring==24.1.1\nBest match: keyring 24.1.1\nAdding keyring 24.1.1 to easy-install.pth file\nInstalling keyring script to /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/bin\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages\nSearching for joblib==1.3.2\nBest match: joblib 1.3.2\nAdding joblib 1.3.2 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages\nSearching for docutils==0.20.1\nBest match: docutils 0.20.1\nAdding docutils 0.20.1 to easy-install.pth file\nInstalling docutils script to /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/bin\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages\nSearching for chardet==5.2.0\nBest match: chardet 5.2.0\nAdding chardet 5.2.0 to easy-install.pth file\nInstalling chardetect script to /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/bin\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages\nSearching for Bottleneck==1.4.0\nBest match: Bottleneck 1.4.0\nAdding Bottleneck 1.4.0 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages\nSearching for AnyQt==0.2.0\nBest match: AnyQt 0.2.0\nAdding AnyQt 0.2.0 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages\nSearching for threadpoolctl==3.1.0\nBest match: threadpoolctl 3.1.0\nAdding threadpoolctl 3.1.0 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages\nSearching for urllib3==2.0.7\nBest match: urllib3 2.0.7\nAdding urllib3 2.0.7 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages\nSearching for certifi==2024.12.14\nBest match: certifi 2024.12.14\nAdding certifi 2024.12.14 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages\nSearching for charset-normalizer==3.4.1\nBest match: charset-normalizer 3.4.1\nAdding charset-normalizer 3.4.1 to easy-install.pth file\nInstalling normalizer script to /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/bin\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages\nSearching for idna==3.10\nBest match: idna 3.10\nAdding idna 3.10 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages\nSearching for pytz==2024.2\nBest match: pytz 2024.2\nAdding pytz 2024.2 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages\nSearching for python-dateutil==2.9.0.post0\nBest match: python-dateutil 2.9.0.post0\nAdding python-dateutil 2.9.0.post0 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages\nSearching for packaging==24.0\nBest match: packaging 24.0\nAdding packaging 24.0 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages\nSearching for importlib-metadata==6.7.0\nBest match: importlib-metadata 6.7.0\nAdding importlib-metadata 6.7.0 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages\nSearching for commonmark==0.9.1\nBest match: commonmark 0.9.1\nAdding commonmark 0.9.1 to easy-install.pth file\nInstalling cmark script to /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/bin\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages\nSearching for dictdiffer==0.9.0\nBest match: dictdiffer 0.9.0\nAdding dictdiffer 0.9.0 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages\nSearching for qasync==0.25.0\nBest match: qasync 0.25.0\nAdding qasync 0.25.0 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages\nSearching for requests-cache==1.1.1\nBest match: requests-cache 1.1.1\nAdding requests-cache 1.1.1 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages\nSearching for cycler==0.11.0\nBest match: cycler 0.11.0\nAdding cycler 0.11.0 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages\nSearching for pyparsing==3.1.4\nBest match: pyparsing 3.1.4\nAdding pyparsing 3.1.4 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages\nSearching for fonttools==4.38.0\nBest match: fonttools 4.38.0\nAdding fonttools 4.38.0 to easy-install.pth file\nInstalling fonttools script to /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/bin\nInstalling pyftmerge script to /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/bin\nInstalling pyftsubset script to /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/bin\nInstalling ttx script to /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/bin\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages\nSearching for kiwisolver==1.4.5\nBest match: kiwisolver 1.4.5\nAdding kiwisolver 1.4.5 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages\nSearching for Pillow==9.5.0\nBest match: Pillow 9.5.0\nAdding Pillow 9.5.0 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages\nSearching for jaraco.classes==3.2.3\nBest match: jaraco.classes 3.2.3\nAdding jaraco.classes 3.2.3 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages\nSearching for jeepney==0.8.0\nBest match: jeepney 0.8.0\nAdding jeepney 0.8.0 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages\nSearching for importlib-resources==5.12.0\nBest match: importlib-resources 5.12.0\nAdding importlib-resources 5.12.0 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages\nSearching for SecretStorage==3.3.3\nBest match: SecretStorage 3.3.3\nAdding SecretStorage 3.3.3 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages\nSearching for six==1.17.0\nBest match: six 1.17.0\nAdding six 1.17.0 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages\nSearching for zipp==3.15.0\nBest match: zipp 3.15.0\nAdding zipp 3.15.0 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages\nSearching for typing-extensions==4.7.1\nBest match: typing-extensions 4.7.1\nAdding typing-extensions 4.7.1 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages\nSearching for platformdirs==4.0.0\nBest match: platformdirs 4.0.0\nAdding platformdirs 4.0.0 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages\nSearching for attrs==24.2.0\nBest match: attrs 24.2.0\nAdding attrs 24.2.0 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages\nSearching for url-normalize==1.4.3\nBest match: url-normalize 1.4.3\nAdding url-normalize 1.4.3 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages\nSearching for cattrs==23.1.2\nBest match: cattrs 23.1.2\nAdding cattrs 23.1.2 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages\nSearching for more-itertools==9.1.0\nBest match: more-itertools 9.1.0\nAdding more-itertools 9.1.0 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages\nSearching for cryptography==44.0.0\nBest match: cryptography 44.0.0\nAdding cryptography 44.0.0 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages\nSearching for exceptiongroup==1.2.2\nBest match: exceptiongroup 1.2.2\nAdding exceptiongroup 1.2.2 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages\nSearching for cffi==1.15.1\nBest match: cffi 1.15.1\nAdding cffi 1.15.1 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages\nSearching for pycparser==2.21\nBest match: pycparser 2.21\nAdding pycparser 2.21 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages\nFinished processing dependencies for Orange3==3.23.0.dev0+69d9a7d\nVerifying Orange installation...\n✅ Orange installation successful!\nSuccessfully installed orange using Python 3.7\n",
    "setup_res_stderr": "Using CPython 3.7.9\nCreating virtual environment at: .venv\nActivate with: source .venv/bin/activate\nResolved 18 packages in 45ms\nPrepared 18 packages in 8ms\nInstalled 18 packages in 243ms\n + cython==0.29.37\n + exceptiongroup==1.2.2\n + importlib-metadata==6.7.0\n + iniconfig==2.0.0\n + numpy==1.17.5\n + packaging==24.0\n + pluggy==1.2.0\n + pyqt5==5.15.10\n + pyqt5-qt5==5.15.16\n + pyqt5-sip==12.13.0\n + pyqtwebengine==5.15.6\n + pyqtwebengine-qt5==5.15.16\n + pytest==7.4.4\n + setuptools==59.8.0\n + tomli==2.0.1\n + typing-extensions==4.7.1\n + wheel==0.42.0\n + zipp==3.15.0\nResolved 37 packages in 190ms\nInstalled 32 packages in 794ms\n + bottleneck==1.4.0\n + certifi==2024.12.14\n + cffi==1.15.1\n + chardet==5.2.0\n + charset-normalizer==3.4.1\n + cryptography==44.0.0\n + idna==3.10\n + importlib-resources==5.12.0\n + jaraco-classes==3.2.3\n + jeepney==0.8.0\n + joblib==1.3.2\n + keyring==24.1.1\n + keyrings-alt==4.2.0\n + more-itertools==9.1.0\n + networkx==2.6.3\n + opentsne==1.0.1\n + pandas==1.3.5\n + pip==24.0\n + pycparser==2.21\n + python-dateutil==2.9.0.post0\n + python-louvain==0.16\n + pytz==2024.2\n + requests==2.31.0\n + scikit-learn==1.0.2\n + scipy==1.7.3\n + secretstorage==3.3.3\n + serverfiles==0.3.1\n + six==1.17.0\n + threadpoolctl==3.1.0\n + urllib3==2.0.7\n + xlrd==2.0.1\n + xlsxwriter==3.2.0\nResolved 34 packages in 122ms\nInstalled 19 packages in 115ms\n + anyqt==0.2.0\n + attrs==24.2.0\n + cattrs==23.1.2\n + commonmark==0.9.1\n + cycler==0.11.0\n + dictdiffer==0.9.0\n + docutils==0.20.1\n + fonttools==4.38.0\n + kiwisolver==1.4.5\n + matplotlib==3.5.3\n + orange-canvas-core==0.1.35\n + orange-widget-base==4.0.1\n + pillow==9.5.0\n + platformdirs==4.0.0\n + pyparsing==3.1.4\n + pyqtgraph==0.12.4\n + qasync==0.25.0\n + requests-cache==1.1.1\n + url-normalize==1.4.3\nResolved 2 packages in 6ms\nInstalled 2 packages in 11ms\n + psycopg2==2.9.9\n + pymssql==2.3.2\nAudited 1 package in 25ms\nAudited 2 packages in 2ms\nOrange/classification/_simple_tree.c: In function ‘gain_ratio_c’:\nOrange/classification/_simple_tree.c:63:9: warning: implicit declaration of function ‘qsort_r’; did you mean ‘qsort’? [-Wimplicit-function-declaration]\n   63 |         qsort_r(base, nel, size, compar, thunk)\n      |         ^~~~~~~\nOrange/classification/_simple_tree.c:147:9: note: in expansion of macro ‘QSORT_R_FUNC’\n  147 |         QSORT_R_FUNC(examples, size, sizeof(struct Example), (void*) &compar_attr, compar_examples);\n      |         ^~~~~~~~~~~~\nIn file included from /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages/numpy/core/include/numpy/ndarraytypes.h:1830,\n                 from /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages/numpy/core/include/numpy/ndarrayobject.h:12,\n                 from /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages/numpy/core/include/numpy/arrayobject.h:4,\n                 from Orange/classification/_tree_scorers.c:567:\n/home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:17:2: warning: #warning \"Using deprecated NumPy API, disable it with \" \"#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION\" [-Wcpp]\n   17 | #warning \"Using deprecated NumPy API, disable it with \" \\\n      |  ^~~~~~~\nOrange/classification/_tree_scorers.c: In function ‘__pyx_pf_6Orange_14classification_13_tree_scorers_2find_threshold_entropy’:\nOrange/classification/_tree_scorers.c:3115:27: warning: comparison of integer expressions of different signedness: ‘unsigned int’ and ‘int’ [-Wsign-compare]\n 3115 |   __pyx_t_7 = ((__pyx_v_N <= __pyx_v_min_leaf) != 0);\n      |                           ^~\nOrange/classification/_tree_scorers.c: In function ‘__pyx_pf_6Orange_14classification_13_tree_scorers_6find_threshold_MSE’:\nOrange/classification/_tree_scorers.c:4619:27: warning: comparison of integer expressions of different signedness: ‘unsigned int’ and ‘int’ [-Wsign-compare]\n 4619 |   __pyx_t_1 = ((__pyx_v_N <= __pyx_v_min_leaf) != 0);\n      |                           ^~\nOrange/classification/_tree_scorers.c: In function ‘__pyx_pf_6Orange_14classification_13_tree_scorers_8find_binarization_MSE’:\nOrange/classification/_tree_scorers.c:5396:43: warning: comparison of integer expressions of different signedness: ‘unsigned int’ and ‘int’ [-Wsign-compare]\n 5396 |           for (__pyx_t_22 = 0; __pyx_t_22 < __pyx_t_21; __pyx_t_22+=1) {\n      |                                           ^\nOrange/classification/_tree_scorers.c:5517:39: warning: comparison of integer expressions of different signedness: ‘unsigned int’ and ‘int’ [-Wsign-compare]\n 5517 |           __pyx_t_27 = ((__pyx_v_left >= __pyx_v_min_leaf) != 0);\n      |                                       ^~\nOrange/classification/_tree_scorers.c:5523:53: warning: comparison of integer expressions of different signedness: ‘unsigned int’ and ‘int’ [-Wsign-compare]\n 5523 |           __pyx_t_27 = (((__pyx_v_N - __pyx_v_left) >= __pyx_v_min_leaf) != 0);\n      |                                                     ^~\nOrange/classification/_tree_scorers.c: In function ‘__pyx_pf_6Orange_14classification_13_tree_scorers_14compute_predictions_csr’:\nOrange/classification/_tree_scorers.c:7051:41: warning: comparison of integer expressions of different signedness: ‘unsigned int’ and ‘int’ [-Wsign-compare]\n 7051 |         for (__pyx_t_11 = 0; __pyx_t_11 < __pyx_t_10; __pyx_t_11+=1) {\n      |                                         ^\nOrange/classification/_tree_scorers.c: In function ‘__pyx_pf_6Orange_14classification_13_tree_scorers_16compute_predictions_csc’:\nOrange/classification/_tree_scorers.c:7741:41: warning: comparison of integer expressions of different signedness: ‘unsigned int’ and ‘int’ [-Wsign-compare]\n 7741 |         for (__pyx_t_11 = 0; __pyx_t_11 < __pyx_t_10; __pyx_t_11+=1) {\n      |                                         ^\nOrange/classification/_tree_scorers.c:7801:143: warning: comparison of integer expressions of different signedness: ‘__pyx_t_5numpy_int32_t’ {aka ‘int’} and ‘unsigned int’ [-Wsign-compare]\n 7801 |               __pyx_t_17 = (((*((__pyx_t_5numpy_int32_t *) ( /* dim=0 */ (__pyx_v_indices.data + __pyx_t_18 * __pyx_v_indices.strides[0]) ))) != __pyx_v_i) != 0);\n      |                                                                                                                                               ^~\nIn file included from /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages/numpy/core/include/numpy/ndarraytypes.h:1830,\n                 from /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages/numpy/core/include/numpy/ndarrayobject.h:12,\n                 from /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages/numpy/core/include/numpy/arrayobject.h:4,\n                 from Orange/data/_valuecount.c:567:\n/home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:17:2: warning: #warning \"Using deprecated NumPy API, disable it with \" \"#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION\" [-Wcpp]\n   17 | #warning \"Using deprecated NumPy API, disable it with \" \\\n      |  ^~~~~~~\nIn file included from /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages/numpy/core/include/numpy/ndarraytypes.h:1830,\n                 from /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages/numpy/core/include/numpy/ndarrayobject.h:12,\n                 from /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages/numpy/core/include/numpy/arrayobject.h:4,\n                 from Orange/data/_contingency.c:567:\n/home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:17:2: warning: #warning \"Using deprecated NumPy API, disable it with \" \"#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION\" [-Wcpp]\n   17 | #warning \"Using deprecated NumPy API, disable it with \" \\\n      |  ^~~~~~~\nOrange/data/_io.c: In function ‘__pyx_pf_6Orange_4data_3_io_sparse_read_float.constprop’:\nOrange/data/_io.c:3881:24: warning: ‘__pyx_v_decs’ may be used uninitialized in this function [-Wmaybe-uninitialized]\n 3881 |           __pyx_v_decs = (__pyx_v_decs / 10.0);\n      |           ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~\nOrange/data/_io.c:4070:24: warning: ‘__pyx_v_value’ may be used uninitialized in this function [-Wmaybe-uninitialized]\n 4070 |           __pyx_t_10 = PyFloat_FromDouble(__pyx_v_value); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 221, __pyx_L5_error)\n      |                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\nOrange/data/_io.c:480:40: warning: ‘__pyx_v_attr_index’ may be used uninitialized in this function [-Wmaybe-uninitialized]\n  480 |   #define PyInt_FromLong               PyLong_FromLong\n      |                                        ^~~~~~~~~~~~~~~\nOrange/data/_io.c:1301:7: note: ‘__pyx_v_attr_index’ was declared here\n 1301 |   int __pyx_v_attr_index;\n      |       ^~~~~~~~~~~~~~~~~~\nOrange/data/_io.c:2935:25: warning: ‘__pyx_v_atomp’ may be used uninitialized in this function [-Wmaybe-uninitialized]\n 2935 |           __pyx_v_atomp = (__pyx_v_atomp + 1);\n      |           ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~\nIn file included from /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages/numpy/core/include/numpy/ndarraytypes.h:1830,\n                 from /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages/numpy/core/include/numpy/ndarrayobject.h:12,\n                 from /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages/numpy/core/include/numpy/arrayobject.h:4,\n                 from Orange/distance/_distance.c:567:\n/home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:17:2: warning: #warning \"Using deprecated NumPy API, disable it with \" \"#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION\" [-Wcpp]\n   17 | #warning \"Using deprecated NumPy API, disable it with \" \\\n      |  ^~~~~~~\nIn file included from /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages/numpy/core/include/numpy/ndarraytypes.h:1830,\n                 from /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages/numpy/core/include/numpy/ndarrayobject.h:12,\n                 from /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages/numpy/core/include/numpy/arrayobject.h:4,\n                 from Orange/preprocess/_discretize.c:567:\n/home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:17:2: warning: #warning \"Using deprecated NumPy API, disable it with \" \"#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION\" [-Wcpp]\n   17 | #warning \"Using deprecated NumPy API, disable it with \" \\\n      |  ^~~~~~~\nIn file included from /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages/numpy/core/include/numpy/ndarraytypes.h:1830,\n                 from /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages/numpy/core/include/numpy/ndarrayobject.h:12,\n                 from /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages/numpy/core/include/numpy/arrayobject.h:4,\n                 from Orange/preprocess/_relieff.cpp:581:\n/home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:17:2: warning: #warning \"Using deprecated NumPy API, disable it with \" \"#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION\" [-Wcpp]\n   17 | #warning \"Using deprecated NumPy API, disable it with \" \\\n      |  ^~~~~~~\n/home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages/setuptools/command/install.py:37: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.\n  setuptools.SetuptoolsDeprecationWarning,\n/home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages/setuptools/command/easy_install.py:159: EasyInstallDeprecationWarning: easy_install command is deprecated. Use build and pip and other standards-based tools.\n  EasyInstallDeprecationWarning,\n/home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages/setuptools/command/install.py:37: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.\n  setuptools.SetuptoolsDeprecationWarning,\n/home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8/.venv/lib/python3.7/site-packages/setuptools/command/egg_info.py:628: SetuptoolsDeprecationWarning: Custom 'build_py' does not implement 'get_data_files_without_manifest'.\nPlease extend command classes from setuptools instead of distutils.\n  SetuptoolsDeprecationWarning\n",
    "new_commit_res_code": 0,
    "new_commit_res_stdout": "============================= test session starts ==============================\nplatform linux -- Python 3.7.9, pytest-7.4.4, pluggy-1.2.0\nrootdir: /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8\ncollected 17 items\n\nr2e_tests/test_1.py ss...............                                    [100%]\n\n==================================== PASSES ====================================\n=========================== short test summary info ============================\nPASSED r2e_tests/test_1.py::TestOWDistributions::test_controls_disabling\nPASSED r2e_tests/test_1.py::TestOWDistributions::test_minimum_size\nPASSED r2e_tests/test_1.py::TestOWDistributions::test_msg_base_class\nPASSED r2e_tests/test_1.py::TestOWDistributions::test_on_bins_changed\nPASSED r2e_tests/test_1.py::TestOWDistributions::test_plot_types_combinations\nPASSED r2e_tests/test_1.py::TestOWDistributions::test_report\nPASSED r2e_tests/test_1.py::TestOWDistributions::test_selection_grouping\nPASSED r2e_tests/test_1.py::TestOWDistributions::test_set_data\nPASSED r2e_tests/test_1.py::TestOWDistributions::test_set_data_no_class\nPASSED r2e_tests/test_1.py::TestOWDistributions::test_set_data_no_class_no_discrete\nPASSED r2e_tests/test_1.py::TestOWDistributions::test_set_data_reg_class\nPASSED r2e_tests/test_1.py::TestOWDistributions::test_set_data_reg_class_no_discrete\nPASSED r2e_tests/test_1.py::TestOWDistributions::test_set_valid_data\nPASSED r2e_tests/test_1.py::TestOWDistributions::test_switch_cvar\nPASSED r2e_tests/test_1.py::TestOWDistributions::test_switch_var\nSKIPPED [1] .venv/lib/python3.7/site-packages/orangewidget/tests/base.py:86: minimum size not tested as .widget was not set\nSKIPPED [1] .venv/lib/python3.7/site-packages/orangewidget/tests/base.py:92: msg base class not tested as .widget was not set\n======================== 15 passed, 2 skipped in 22.01s ========================\n",
    "new_commit_res_stderr": "",
    "old_commit_res_code": 1,
    "old_commit_res_stdout": "============================= test session starts ==============================\nplatform linux -- Python 3.7.9, pytest-7.4.4, pluggy-1.2.0\nrootdir: /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_69d9a7d9922769ffc0bd1aa6f050690775f378b8\ncollected 17 items\n\nr2e_tests/test_1.py ss...F..F........                                    [100%]\n\n=================================== FAILURES ===================================\n___________________ TestOWDistributions.test_on_bins_changed ___________________\n\nself = <r2e_tests.test_1.TestOWDistributions testMethod=test_on_bins_changed>\n\n    def test_on_bins_changed(self):\n        \"\"\"Widget replots and outputs data when the number of bins is changed\"\"\"\n        widget = self.widget\n        self.send_signal(widget.Inputs.data, self.iris)\n    \n        self._set_slider(0)\n        widget.selection.add(1)\n        n_bars = len(widget.bar_items)\n        widget.apply = Mock()\n    \n        self._set_slider(1)\n        self.assertEqual(widget.selection, set())\n>       self.assertGreater(n_bars, len(widget.bar_items))\nE       AssertionError: 2 not greater than 4\n\nr2e_tests/test_1.py:256: AssertionError\n_________________ TestOWDistributions.test_selection_grouping __________________\n\nself = <r2e_tests.test_1.TestOWDistributions testMethod=test_selection_grouping>\n\n    def test_selection_grouping(self):\n        \"\"\"Widget groups consecutive selected bars\"\"\"\n        widget = self.widget\n        self.send_signal(widget.Inputs.data, self.iris)\n        self._set_slider(0)\n        widget.selection = {1, 2, 3, 5, 6, 9}\n        widget.plot_mark.addItem = Mock()\n>       widget.show_selection()\n\nr2e_tests/test_1.py:455: \n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\nself = <Orange.widgets.visualize.owdistributions.OWDistributions object at 0x74ce0c1acd70>\n\n    def show_selection(self):\n        self.plot_mark.clear()\n        if not self.is_valid:  # though if it's not, selection is empty anyway\n            return\n    \n        blue = QColor(Qt.blue)\n        pen = QPen(QBrush(blue), 3)\n        pen.setCosmetic(True)\n        brush = QBrush(blue.lighter(190))\n    \n        for group in self.grouped_selection():\n            group = list(group)\n            left_idx, right_idx = group[0], group[-1]\n            left_pad, right_pad = self._determine_padding(left_idx, right_idx)\n            x0 = self.bar_items[left_idx].x0 - left_pad\n>           x1 = self.bar_items[right_idx].x1 + right_pad\nE           IndexError: list index out of range\n\nOrange/widgets/visualize/owdistributions.py:826: IndexError\n==================================== PASSES ====================================\n=========================== short test summary info ============================\nPASSED r2e_tests/test_1.py::TestOWDistributions::test_controls_disabling\nPASSED r2e_tests/test_1.py::TestOWDistributions::test_minimum_size\nPASSED r2e_tests/test_1.py::TestOWDistributions::test_msg_base_class\nPASSED r2e_tests/test_1.py::TestOWDistributions::test_plot_types_combinations\nPASSED r2e_tests/test_1.py::TestOWDistributions::test_report\nPASSED r2e_tests/test_1.py::TestOWDistributions::test_set_data\nPASSED r2e_tests/test_1.py::TestOWDistributions::test_set_data_no_class\nPASSED r2e_tests/test_1.py::TestOWDistributions::test_set_data_no_class_no_discrete\nPASSED r2e_tests/test_1.py::TestOWDistributions::test_set_data_reg_class\nPASSED r2e_tests/test_1.py::TestOWDistributions::test_set_data_reg_class_no_discrete\nPASSED r2e_tests/test_1.py::TestOWDistributions::test_set_valid_data\nPASSED r2e_tests/test_1.py::TestOWDistributions::test_switch_cvar\nPASSED r2e_tests/test_1.py::TestOWDistributions::test_switch_var\nSKIPPED [1] .venv/lib/python3.7/site-packages/orangewidget/tests/base.py:86: minimum size not tested as .widget was not set\nSKIPPED [1] .venv/lib/python3.7/site-packages/orangewidget/tests/base.py:92: msg base class not tested as .widget was not set\nFAILED r2e_tests/test_1.py::TestOWDistributions::test_on_bins_changed - Asser...\nFAILED r2e_tests/test_1.py::TestOWDistributions::test_selection_grouping - In...\n=================== 2 failed, 13 passed, 2 skipped in 21.26s ===================\n",
    "old_commit_res_stderr": ""
}
Orange/widgets/visualize/owdistributions.py Orange/widgets/visualize/tests/test_owdistributions.py
We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
[ISSUE]
**Title:** Adjusting Bin Width Slider Clears Selection and Causes Indexing Errors in OWDistributions Widget

**Description:**
When interacting with the OWDistributions widget, changing the number of bins using the bin width slider leads to unexpected behavior. Specifically, altering the slider clears the current selection of bars, and attempting to group the selected bars afterward results in an IndexError.

**Example Code:**
```python
# Initialize the widget and load data
widget = create_widget(OWDistributions)
send_signal(widget.Inputs.data, iris_table)

# Select multiple bars
widget.selection.add(1)
widget.selection.add(2)
widget.selection.add(3)

# Change the number of bins using the slider
set_slider_value(1)

# Attempt to group the selected bars
widget.show_selection()
```

**Expected Behavior:**
- Changing the bin width slider should update the distribution without affecting the current selection of bars.
- Grouping the selected bars after adjusting the slider should function correctly without any errors.

**Actual Behavior:**
- Adjusting the bin width slider unexpectedly clears the current selection of bars.
- Attempting to group the previously selected bars results in an `IndexError: list index out of range`, indicating that the widget is trying to access bar items that no longer exist.

This issue hinders the usability of the OWDistributions widget by disrupting user selections and causing application crashes when grouping selections after modifying the bin width.

[/ISSUE]
--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.

--- BEGIN FILE ---
```
### Orange/widgets/visualize/owdistributions.py
from functools import partial
from itertools import count, groupby, repeat
from xml.sax.saxutils import escape

import numpy as np
from scipy.stats import norm, rayleigh, beta, gamma, pareto, expon

from AnyQt.QtWidgets import QGraphicsRectItem
from AnyQt.QtGui import QColor, QPen, QBrush, QPainter, QPalette, QPolygonF
from AnyQt.QtCore import Qt, QRectF, QPointF, pyqtSignal as Signal
import pyqtgraph as pg

from Orange.data import Table, DiscreteVariable, ContinuousVariable
from Orange.preprocess.discretize import decimal_binnings
from Orange.statistics import distribution, contingency
from Orange.widgets import gui, settings
from Orange.widgets.utils.annotated_data import \
    create_groups_table, create_annotated_table, ANNOTATED_DATA_SIGNAL_NAME
from Orange.widgets.utils.itemmodels import DomainModel
from Orange.widgets.utils.widgetpreview import WidgetPreview
from Orange.widgets.visualize.utils.plotutils import ElidedLabelsAxis
from Orange.widgets.widget import Input, Output, OWWidget, Msg

from Orange.widgets.visualize.owscatterplotgraph import \
    LegendItem as SPGLegendItem


class ScatterPlotItem(pg.ScatterPlotItem):
    Symbols = pg.graphicsItems.ScatterPlotItem.Symbols

    # pylint: disable=arguments-differ
    def paint(self, painter, option, widget=None):
        if self.opts["pxMode"]:
            painter.setRenderHint(QPainter.SmoothPixmapTransform, True)
        if self.opts["antialias"]:
            painter.setRenderHint(QPainter.Antialiasing, True)
        super().paint(painter, option, widget)


class LegendItem(SPGLegendItem):
    @staticmethod
    def mousePressEvent(event):
        if event.button() == Qt.LeftButton:
            event.accept()
        else:
            event.ignore()

    def mouseMoveEvent(self, event):
        if event.buttons() & Qt.LeftButton:
            event.accept()
            if self.parentItem() is not None:
                self.autoAnchor(
                    self.pos() + (event.pos() - event.lastPos()) / 2)
        else:
            event.ignore()

    @staticmethod
    def mouseReleaseEvent(event):
        if event.button() == Qt.LeftButton:
            event.accept()
        else:
            event.ignore()


class DistributionBarItem(pg.GraphicsObject):
    def __init__(self, x, width, padding, freqs, colors, stacked, expanded,
                 tooltip):
        super().__init__()
        self.x = x
        self.width = width
        self.freqs = freqs
        self.colors = colors
        self.padding = padding
        self.stacked = stacked
        self.expanded = expanded
        self.__picture = None
        self.polygon = None
        self.hovered = False
        self.setAcceptHoverEvents(True)
        self.setToolTip(tooltip)

    def hoverEnterEvent(self, event):
        super().hoverEnterEvent(event)
        self.hovered = True
        self.update()

    def hoverLeaveEvent(self, event):
        super().hoverLeaveEvent(event)
        self.hovered = False
        self.update()

    def paint(self, painter, _options, _widget):
        if self.expanded:
            tot = np.sum(self.freqs)
            if tot == 0:
                return
            freqs = self.freqs / tot
        else:
            freqs = self.freqs

        if not self.padding:
            padding = self.mapRectFromDevice(QRectF(0, 0, 0.5, 0)).width()
        else:
            padding = min(20, self.width * self.padding)
        sx = self.x + padding
        padded_width = self.width - 2 * padding

        if self.stacked:
            painter.setPen(Qt.NoPen)
            y = 0
            for freq, color in zip(freqs, self.colors):
                painter.setBrush(QBrush(color))
                painter.drawRect(QRectF(sx, y, padded_width, freq))
                y += freq
            self.polygon = QPolygonF(QRectF(sx, 0, padded_width, y))
        else:
            polypoints = [QPointF(sx, 0)]
            pen = QPen(QBrush(Qt.white), 0.5)
            pen.setCosmetic(True)
            painter.setPen(pen)
            wsingle = padded_width / len(self.freqs)
            for i, freq, color in zip(count(), freqs, self.colors):
                painter.setBrush(QBrush(color))
                x = sx + wsingle * i
                painter.drawRect(
                    QRectF(x, 0, wsingle, freq))
                polypoints += [QPointF(x, freq),
                               QPointF(x + wsingle, freq)]
            polypoints += [QPointF(polypoints[-1].x(), 0), QPointF(sx, 0)]
            self.polygon = QPolygonF(polypoints)

        if self.hovered:
            pen = QPen(QBrush(Qt.blue), 2, Qt.DashLine)
            pen.setCosmetic(True)
            painter.setPen(pen)
            painter.setBrush(Qt.NoBrush)
            painter.drawPolygon(self.polygon)

    @property
    def x0(self):
        return self.x

    @property
    def x1(self):
        return self.x + self.width

    def boundingRect(self):
        if self.expanded:
            height = 1
        elif self.stacked:
            height = sum(self.freqs)
        else:
            height = max(self.freqs)
        return QRectF(self.x, 0, self.width, height)


class DistributionWidget(pg.PlotWidget):
    item_clicked = Signal(DistributionBarItem, Qt.KeyboardModifiers, bool)
    blank_clicked = Signal()
    mouse_released = Signal()

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.last_item = None

    def _get_bar_item(self, pos):
        for item in self.items(pos):
            if isinstance(item, DistributionBarItem):
                return item
        return None

    def mousePressEvent(self, ev):
        super().mousePressEvent(ev)
        if ev.isAccepted():
            return
        if ev.button() != Qt.LeftButton:
            ev.ignore()
            return

        ev.accept()
        self.last_item = self._get_bar_item(ev.pos())
        if self.last_item:
            self.item_clicked.emit(self.last_item, ev.modifiers(), False)
        else:
            self.blank_clicked.emit()

    def mouseReleaseEvent(self, ev):
        self.last_item = None
        self.mouse_released.emit()

    def mouseMoveEvent(self, ev):
        super().mouseMoveEvent(ev)
        if self.last_item is not None:
            item = self._get_bar_item(ev.pos())
            if item is not None and item is not self.last_item:
                self.item_clicked.emit(item, ev.modifiers(), True)
                self.last_item = item


class OWDistributions(OWWidget):
    name = "Distributions"
    description = "Display value distributions of a data feature in a graph."
    icon = "icons/Distribution.svg"
    priority = 120
    keywords = []

    class Inputs:
        data = Input("Data", Table, doc="Set the input dataset")

    class Outputs:
        selected_data = Output("Selected Data", Table, default=True)
        annotated_data = Output(ANNOTATED_DATA_SIGNAL_NAME, Table)
        histogram_data = Output("Histogram Data", Table)

    class Error(OWWidget.Error):
        no_defined_values_var = \
            Msg("Variable '{}' does not have any defined values")
        no_defined_values_pair = \
            Msg("No data instances with '{}' and '{}' defined")

    class Warning(OWWidget.Warning):
        ignored_nans = Msg("Data instances with missing values are ignored")

    settingsHandler = settings.DomainContextHandler()
    var = settings.ContextSetting(None)
    cvar = settings.ContextSetting(None)
    selection = settings.ContextSetting(set(), schema_only=True)
    # number_of_bins must be a context setting because selection depends on it
    number_of_bins = settings.ContextSetting(5, schema_only=True)

    fitted_distribution = settings.Setting(0)
    show_probs = settings.Setting(False)
    stacked_columns = settings.Setting(False)
    cumulative_distr = settings.Setting(False)

    auto_apply = settings.Setting(True)

    graph_name = "plot"

    Fitters = (
        ("None", None, (), ()),
        ("Normal", norm, ("loc", "scale"), ("μ", "σ²")),
        ("Beta", beta, ("a", "b", "loc", "scale"),
         ("α", "β", "-loc", "-scale")),
        ("Gamma", gamma, ("a", "loc", "scale"), ("α", "β", "-loc", "-scale")),
        ("Rayleigh", rayleigh, ("loc", "scale"), ("-loc", "σ²")),
        ("Pareto", pareto, ("b", "loc", "scale"), ("α", "-loc", "-scale")),
        ("Exponential", expon, ("loc", "scale"), ("-loc", "λ")),
    )

    DragNone, DragAdd, DragRemove = range(3)

    def __init__(self):
        super().__init__()
        self.data = None
        self.valid_data = self.valid_group_data = None
        self.bar_items = []
        self.curve_descriptions = None
        self.binnings = []

        self.last_click_idx = None
        self.drag_operation = self.DragNone
        self.key_operation = None
        self._user_var_bins = {}

        gui.listView(
            self.controlArea, self, "var", box="Variable",
            model=DomainModel(valid_types=DomainModel.PRIMITIVE,
                              separators=False),
            callback=self._on_var_changed)

        box = self.continuous_box = gui.vBox(self.controlArea, "Distribution")
        slider = gui.hSlider(
            box, self, "number_of_bins",
            label="Bin width", orientation=Qt.Horizontal,
            minValue=0, maxValue=max(1, len(self.binnings) - 1),
            createLabel=False, callback=self._on_bins_changed)
        self.bin_width_label = gui.widgetLabel(slider.box)
        self.bin_width_label.setFixedWidth(35)
        self.bin_width_label.setAlignment(Qt.AlignRight)
        slider.sliderReleased.connect(self._on_bin_slider_released)
        gui.comboBox(
            box, self, "fitted_distribution", label="Fitted distribution",
            orientation=Qt.Horizontal, items=(name[0] for name in self.Fitters),
            callback=self.replot)
        gui.checkBox(
            box, self, "cumulative_distr", "Show cumulative distribution",
            callback=self.replot)

        box = gui.vBox(self.controlArea, "Columns")
        gui.comboBox(
            box, self, "cvar", label="Split by", orientation=Qt.Horizontal,
            model=DomainModel(placeholder="(None)",
                              valid_types=(DiscreteVariable), ),
            callback=self._on_cvar_changed, contentsLength=18)
        box2 = gui.indentedBox(box, sep=12)
        gui.checkBox(
            box2, self, "stacked_columns", "Stack columns",
            callback=self.replot)
        gui.checkBox(
            box2, self, "show_probs", "Show probabilities",
            callback=self._on_show_probabilities_changed)

        gui.auto_commit(
            self.controlArea, self, "auto_apply", "&Apply", commit=self.apply)

        self._setup_plots()
        self._setup_legend()

    def _setup_plots(self):
        def add_new_plot(zvalue):
            plot = pg.ViewBox(enableMouse=False, enableMenu=False)
            self.ploti.scene().addItem(plot)
            pg.AxisItem("right").linkToView(plot)
            plot.setXLink(self.ploti)
            plot.setZValue(zvalue)
            return plot

        self.plotview = DistributionWidget(background=None)
        self.plotview.item_clicked.connect(self._on_item_clicked)
        self.plotview.blank_clicked.connect(self._on_blank_clicked)
        self.plotview.mouse_released.connect(self._on_end_selecting)
        self.plotview.setRenderHint(QPainter.Antialiasing)
        self.mainArea.layout().addWidget(self.plotview)
        self.ploti = pg.PlotItem(
            enableMenu=False, enableMouse=False,
            axisItems={"bottom": ElidedLabelsAxis("bottom")})
        self.plot = self.ploti.vb
        self.plot.setMouseEnabled(False, False)
        self.ploti.hideButtons()
        self.plotview.setCentralItem(self.ploti)

        self.plot_pdf = add_new_plot(10)
        self.plot_mark = add_new_plot(-10)
        self.plot_mark.setYRange(0, 1)
        self.ploti.vb.sigResized.connect(self.update_views)
        self.update_views()

        pen = QPen(self.palette().color(QPalette.Text))
        self.ploti.getAxis("bottom").setPen(pen)
        left = self.ploti.getAxis("left")
        left.setPen(pen)
        left.setStyle(stopAxisAtTick=(True, True))

    def _setup_legend(self):
        self._legend = LegendItem()
        self._legend.setParentItem(self.plot)
        self._legend.hide()
        self._legend.anchor((1, 0), (1, 0))

    # -----------------------------
    # Event and signal handlers

    def update_views(self):
        for plot in (self.plot_pdf, self.plot_mark):
            plot.setGeometry(self.plot.sceneBoundingRect())
            plot.linkedViewChanged(self.plot, plot.XAxis)

    def onDeleteWidget(self):
        self.plot.clear()
        self.plot_pdf.clear()
        self.plot_mark.clear()
        super().onDeleteWidget()

    @Inputs.data
    def set_data(self, data):
        self.closeContext()
        self.var = self.cvar = None
        self.data = data
        domain = self.data.domain if self.data else None
        varmodel = self.controls.var.model()
        cvarmodel = self.controls.cvar.model()
        varmodel.set_domain(domain)
        cvarmodel.set_domain(domain)
        if varmodel:
            self.var = varmodel[min(len(domain.class_vars), len(varmodel) - 1)]
        if domain is not None and domain.has_discrete_class:
            self.cvar = domain.class_var
        self.reset_select()
        self._user_var_bins.clear()
        self.openContext(domain)
        self.set_valid_data()
        self.recompute_binnings()
        self.replot()
        self.apply()

    def _on_var_changed(self):
        self.reset_select()
        self.set_valid_data()
        self.recompute_binnings()
        self.replot()
        self.apply()

    def _on_cvar_changed(self):
        self.set_valid_data()
        self.replot()
        self.apply()

    def _on_bins_changed(self):
        self.reset_select()
        self._set_bin_width_slider_label()
        self.replot()
        # this is triggered when dragging, so don't call apply here;
        # apply is called on sliderReleased

    def _on_bin_slider_released(self):
        self._user_var_bins[self.var] = self.number_of_bins
        self.apply()

    def _set_bin_width_slider_label(self):
        text = ""
        if self.number_of_bins < len(self.binnings):
            bins = self.binnings[self.number_of_bins]
            if len(bins) > 1:
                text = self.var.repr_val(bins[1] - bins[0])
        self.bin_width_label.setText(text)

    def _on_show_probabilities_changed(self):
        label = self.controls.fitted_distribution.label
        if self.show_probs:
            label.setText("Fitted probability")
            label.setToolTip(
                "Chosen distribution is used to compute Bayesian probabilities")
        else:
            label.setText("Fitted distribution")
            label.setToolTip("")
        self.replot()

    @property
    def is_valid(self):
        return self.valid_data is not None

    def set_valid_data(self):
        err_def_var = self.Error.no_defined_values_var
        err_def_pair = self.Error.no_defined_values_pair
        err_def_var.clear()
        err_def_pair.clear()
        self.Warning.ignored_nans.clear()

        self.valid_data = self.valid_group_data = None
        if self.var is None:
            return

        column = self.data.get_column_view(self.var)[0].astype(float)
        valid_mask = np.isfinite(column)
        if not np.any(valid_mask):
            self.Error.no_defined_values_var(self.var.name)
            return
        if self.cvar:
            ccolumn = self.data.get_column_view(self.cvar)[0].astype(float)
            valid_mask *= np.isfinite(ccolumn)
            if not np.any(valid_mask):
                self.Error.no_defined_values_pair(self.var.name, self.cvar.name)
                return
            self.valid_group_data = ccolumn[valid_mask]
        if not np.all(valid_mask):
            self.Warning.ignored_nans()
        self.valid_data = column[valid_mask]

    # -----------------------------
    # Plotting

    def replot(self):
        self._clear_plot()
        if self.is_valid:
            self._set_axis_names()
            self._update_controls_state()
            self._call_plotting()
            self._display_legend()
        self.show_selection()

    def _clear_plot(self):
        self.plot.clear()
        self.plot_pdf.clear()
        self.plot_mark.clear()
        self.bar_items = []
        self._legend.clear()
        self._legend.hide()

    def _set_axis_names(self):
        assert self.is_valid  # called only from replot, so assumes data is OK
        bottomaxis = self.ploti.getAxis("bottom")
        bottomaxis.setLabel(self.var and self.var.name)

        leftaxis = self.ploti.getAxis("left")
        if self.show_probs and self.cvar:
            leftaxis.setLabel(
                f"Probability of '{self.cvar.name}' at given '{self.var.name}'")
        else:
            leftaxis.setLabel("Frequency")
        leftaxis.resizeEvent()

    def _update_controls_state(self):
        assert self.is_valid  # called only from replot, so assumes data is OK
        self.continuous_box.setDisabled(self.var.is_discrete)
        self.controls.show_probs.setDisabled(self.cvar is None)
        self.controls.stacked_columns.setDisabled(self.cvar is None)

    def _call_plotting(self):
        assert self.is_valid  # called only from replot, so assumes data is OK
        self.curve_descriptions = None
        if self.var.is_discrete:
            if self.cvar:
                self._disc_split_plot()
            else:
                self._disc_plot()
        else:
            if self.cvar:
                self._cont_split_plot()
            else:
                self._cont_plot()
        self.plot.autoRange()

    def _add_bar(self, x, width, padding, freqs, colors, stacked, expanded,
                 tooltip):
        item = DistributionBarItem(
            x, width, padding, freqs, colors, stacked, expanded, tooltip)
        self.plot.addItem(item)
        self.bar_items.append(item)

    def _disc_plot(self):
        var = self.var
        self.ploti.getAxis("bottom").setTicks([list(enumerate(var.values))])
        colors = [QColor(0, 128, 255)]
        dist = distribution.get_distribution(self.data, self.var)
        for i, freq in enumerate(dist):
            tooltip = \
                "<p style='white-space:pre;'>" \
                f"<b>{escape(var.values[i])}</b>: {int(freq)} " \
                f"({100 * freq / len(self.valid_data):.2f} %) "
            self._add_bar(
                i - 0.5, 1, 0.1, [freq], colors,
                stacked=False, expanded=False, tooltip=tooltip)

    def _disc_split_plot(self):
        var = self.var
        self.ploti.getAxis("bottom").setTicks([list(enumerate(var.values))])
        gcolors = [QColor(*col) for col in self.cvar.colors]
        gvalues = self.cvar.values
        conts = contingency.get_contingency(self.data, self.cvar, self.var)
        total = len(self.data)
        for i, freqs in enumerate(conts):
            self._add_bar(
                i - 0.5, 1, 0.1, freqs, gcolors,
                stacked=self.stacked_columns, expanded=self.show_probs,
                tooltip=self._split_tooltip(
                    var.values[i], np.sum(freqs), total, gvalues, freqs))

    def _cont_plot(self):
        self.ploti.getAxis("bottom").setTicks(None)
        data = self.valid_data
        y, x = np.histogram(data, bins=self.binnings[self.number_of_bins])
        total = len(data)
        colors = [QColor(0, 128, 255)]
        if self.fitted_distribution:
            colors[0] = colors[0].lighter(130)

        tot_freq = 0
        lasti = len(y) - 1
        for i, (x0, x1), freq in zip(count(), zip(x, x[1:]), y):
            tot_freq += freq
            tooltip = \
                "<p style='white-space:pre;'>" \
                f"<b>{escape(self.str_int(x0, x1, not i, i == lasti))}</b>: " \
                f"{freq} ({100 * freq / total:.2f} %)</p>"
            self._add_bar(
                x0, x1 - x0, 0, [tot_freq if self.cumulative_distr else freq],
                colors, stacked=False, expanded=False, tooltip=tooltip)

        if self.fitted_distribution:
            self._plot_approximations(
                x[0], x[-1], [self._fit_approximation(data)],
                [QColor(0, 0, 0)], (1,))

    def _cont_split_plot(self):
        self.ploti.getAxis("bottom").setTicks(None)
        data = self.valid_data
        _, bins = np.histogram(data, bins=self.binnings[self.number_of_bins])
        gvalues = self.cvar.values
        varcolors = [QColor(*col) for col in self.cvar.colors]
        if self.fitted_distribution:
            gcolors = [c.lighter(130) for c in varcolors]
        else:
            gcolors = varcolors
        nvalues = len(gvalues)
        ys = []
        fitters = []
        prior_sizes = []
        for val_idx in range(nvalues):
            group_data = data[self.valid_group_data == val_idx]
            prior_sizes.append(len(group_data))
            ys.append(np.histogram(group_data, bins)[0])
            if self.fitted_distribution:
                fitters.append(self._fit_approximation(group_data))
        total = len(data)
        prior_sizes = np.array(prior_sizes)
        tot_freqs = np.zeros(len(ys))

        lasti = len(ys[0]) - 1
        for i, x0, x1, freqs in zip(count(), bins, bins[1:], zip(*ys)):
            tot_freqs += freqs
            plotfreqs = tot_freqs.copy() if self.cumulative_distr else freqs
            self._add_bar(
                x0, x1 - x0, 0 if self.stacked_columns else 0.1, plotfreqs,
                gcolors, stacked=self.stacked_columns, expanded=self.show_probs,
                tooltip=self._split_tooltip(
                    self.str_int(x0, x1, not i, i == lasti),
                    np.sum(plotfreqs), total, gvalues, plotfreqs))

        if fitters:
            self._plot_approximations(bins[0], bins[-1], fitters, varcolors,
                                      prior_sizes / len(data))

    def _fit_approximation(self, y):
        def join_pars(pairs):
            strv = self.var.str_val
            return ", ".join(f"{sname}={strv(val)}" for sname, val in pairs)

        def str_params():
            s = join_pars(
                (sname, val) for sname, val in zip(str_names, fitted)
                if sname[0] != "-")
            par = join_pars(
                (sname[1:], val) for sname, val in zip(str_names, fitted)
                if sname[0] == "-")
            if par:
                s += f" ({par})"
            return s

        _, dist, names, str_names = self.Fitters[self.fitted_distribution]
        fitted = dist.fit(y)
        params = {name: val for name, val in zip(names, fitted)}
        return partial(dist.pdf, **params), str_params()

    def _plot_approximations(self, x0, x1, fitters, colors, prior_probs=0):
        x = np.linspace(x0, x1, 100)
        ys = np.empty((len(fitters), 100))
        self.curve_descriptions = [s for _, s in fitters]
        for y, (fitter, _), color in zip(ys, fitters, colors):
            y[:] = fitter(x)
            if self.cumulative_distr:
                y[:] = np.cumsum(y)
        tots = np.sum(ys, axis=0)

        show_probs = self.show_probs and self.cvar is not None
        plot = self.ploti if show_probs else self.plot_pdf

        for y, prior_prob, color in zip(ys, prior_probs, colors):
            if show_probs:
                y_p = y * prior_prob
                y = y_p / (y_p + (tots - y) * (1 - prior_prob))
            plot.addItem(pg.PlotCurveItem(
                x=x, y=y,
                pen=pg.mkPen(width=5, color=color),
                shadowPen=pg.mkPen(width=8, color=color.darker(120))))
        if not show_probs:
            self.plot_pdf.autoRange()

    @staticmethod
    def _split_tooltip(valname, tot_group, total, gvalues, freqs):
        div_group = tot_group or 1
        cs = "white-space:pre; text-align: right;"
        s = f"style='{cs} padding-left: 1em'"
        snp = f"style='{cs}'"
        return f"<table style='border-collapse: collapse'>" \
               f"<tr><th {s}>{escape(valname)}:</th>" \
               f"<td {snp}><b>{int(tot_group)}</b></td>" \
               "<td/>" \
               f"<td {s}><b>{100 * tot_group / total:.2f} %</b></td></tr>" + \
               f"<tr><td/><td/><td {s}>(in group)</td><td {s}>(overall)</td>" \
               "</tr>" + \
               "".join(
                   "<tr>"
                   f"<th {s}>{value}:</th>"
                   f"<td {snp}><b>{int(freq)}</b></td>"
                   f"<td {s}>{100 * freq / div_group:.2f} %</td>"
                   f"<td {s}>{100 * freq / total:.2f} %</td>"
                   "</tr>"
                   for value, freq in zip(gvalues, freqs)) + \
               "</table>"

    def _display_legend(self):
        assert self.is_valid  # called only from replot, so assumes data is OK
        if self.cvar is None:
            if not self.curve_descriptions:
                self._legend.hide()
                return
            self._legend.addItem(
                pg.PlotCurveItem(pen=pg.mkPen(width=5, color=0.0)),
                self.curve_descriptions[0])
        else:
            cvar_values = self.cvar.values
            colors = [QColor(*col) for col in self.cvar.colors]
            descriptions = self.curve_descriptions or repeat(None)
            for color, name, desc in zip(colors, cvar_values, descriptions):
                self._legend.addItem(
                    ScatterPlotItem(pen=color, brush=color, size=10, shape="s"),
                    escape(name + (f" ({desc})" if desc else "")))
        self._legend.show()

    # -----------------------------
    # Bins

    def recompute_binnings(self):
        self.binnings = []
        max_bins = 0
        if self.is_valid and self.var.is_continuous:
            # binning is computed on valid var data, ignoring any cvar nans
            column = self.data.get_column_view(self.var)[0].astype(float)
            if np.any(np.isfinite(column)):
                self.binnings = decimal_binnings(
                    column, min_width=self.min_var_resolution(self.var),
                    add_unique=10, min_unique=5)
                max_bins = len(self.binnings) - 1

        self.controls.number_of_bins.setMaximum(max_bins)
        self.number_of_bins = min(
            max_bins, self._user_var_bins.get(self.var, self.number_of_bins))
        self._set_bin_width_slider_label()

    @staticmethod
    def min_var_resolution(var):
        # pylint: disable=unidiomatic-typecheck
        if type(var) is not ContinuousVariable:
            return 0
        return 10 ** -var.number_of_decimals

    def str_int(self, x0, x1, first, last):
        var = self.var
        sx0, sx1 = var.repr_val(x0), var.repr_val(x1)
        if self.cumulative_distr:
            return f"{var.name} < {sx1}"
        elif first and last:
            return f"{var.name} = {sx0}"
        elif first:
            return f"{var.name} < {sx1}"
        elif last:
            return f"{var.name} ≥ {sx0}"
        elif sx0 == sx1 or x1 - x0 <= self.min_var_resolution(var):
            return f"{var.name} = {sx0}"
        else:
            return f"{sx0} ≤ {var.name} < {sx1}"

    # -----------------------------
    # Selection

    def _on_item_clicked(self, item, modifiers, drag):
        def add_or_remove(idx, add):
            self.drag_operation = [self.DragRemove, self.DragAdd][add]
            if add:
                self.selection.add(idx)
            else:
                if idx in self.selection:
                    # This can be False when removing with dragging and the
                    # mouse crosses unselected items
                    self.selection.remove(idx)

        def add_range(add):
            if self.last_click_idx is None:
                add = True
                idx_range = {idx}
            else:
                from_idx, to_idx = sorted((self.last_click_idx, idx))
                idx_range = set(range(from_idx, to_idx + 1))
            self.drag_operation = [self.DragRemove, self.DragAdd][add]
            if add:
                self.selection |= idx_range
            else:
                self.selection -= idx_range

        self.key_operation = None
        if item is None:
            self.reset_select()
            return

        idx = self.bar_items.index(item)
        if drag:
            # Dragging has to add a range, otherwise fast dragging skips bars
            add_range(self.drag_operation == self.DragAdd)
        else:
            if modifiers & Qt.ShiftModifier:
                add_range(self.drag_operation == self.DragAdd)
            elif modifiers & Qt.ControlModifier:
                add_or_remove(idx, add=idx not in self.selection)
            else:
                if self.selection == {idx}:
                    # Clicking on a single selected bar  deselects it,
                    # but dragging from here will select
                    add_or_remove(idx, add=False)
                    self.drag_operation = self.DragAdd
                else:
                    self.selection.clear()
                    add_or_remove(idx, add=True)
        self.last_click_idx = idx

        self.show_selection()

    def _on_blank_clicked(self):
        self.reset_select()

    def reset_select(self):
        self.selection.clear()
        self.last_click_idx = None
        self.drag_operation = None
        self.key_operation = None
        self.show_selection()

    def _on_end_selecting(self):
        self.apply()

    def show_selection(self):
        self.plot_mark.clear()
        if not self.is_valid:  # though if it's not, selection is empty anyway
            return

        blue = QColor(Qt.blue)
        pen = QPen(QBrush(blue), 3)
        pen.setCosmetic(True)
        brush = QBrush(blue.lighter(190))

        for group in self.grouped_selection():
            group = list(group)
            left_idx, right_idx = group[0], group[-1]
            left_pad, right_pad = self._determine_padding(left_idx, right_idx)
            x0 = self.bar_items[left_idx].x0 - left_pad
            x1 = self.bar_items[right_idx].x1 + right_pad
            item = QGraphicsRectItem(x0, 0, x1 - x0, 1)
            item.setPen(pen)
            item.setBrush(brush)
            if self.var.is_continuous:
                valname = self.str_int(
                    x0, x1, not left_idx, right_idx == len(self.bar_items) - 1)
                inside = sum(np.sum(self.bar_items[i].freqs) for i in group)
                total = len(self.valid_data)
                item.setToolTip(
                    "<p style='white-space:pre;'>"
                    f"<b>{escape(valname)}</b>: "
                    f"{inside} ({100 * inside / total:.2f} %)")
            self.plot_mark.addItem(item)

    def _determine_padding(self, left_idx, right_idx):
        def _padding(i):
            return (self.bar_items[i + 1].x0 - self.bar_items[i].x1) / 2

        if len(self.bar_items) == 1:
            return 6, 6
        if left_idx == 0 and right_idx == len(self.bar_items) - 1:
            return (_padding(0), ) * 2

        if left_idx > 0:
            left_pad = _padding(left_idx - 1)
        if right_idx < len(self.bar_items) - 1:
            right_pad = _padding(right_idx)
        else:
            right_pad = left_pad
        if left_idx == 0:
            left_pad = right_pad
        return left_pad, right_pad

    def grouped_selection(self):
        return [[g[1] for g in group]
                for _, group in groupby(enumerate(sorted(self.selection)),
                                        key=lambda x: x[1] - x[0])]

    def keyPressEvent(self, e):
        def on_nothing_selected():
            if e.key() == Qt.Key_Left:
                self.last_click_idx = len(self.bar_items) - 1
            else:
                self.last_click_idx = 0
            self.selection.add(self.last_click_idx)

        def on_key_left():
            if e.modifiers() & Qt.ShiftModifier:
                if self.key_operation == Qt.Key_Right and first != last:
                    self.selection.remove(last)
                    self.last_click_idx = last - 1
                elif first:
                    self.key_operation = Qt.Key_Left
                    self.selection.add(first - 1)
                    self.last_click_idx = first - 1
            else:
                self.selection.clear()
                self.last_click_idx = max(first - 1, 0)
                self.selection.add(self.last_click_idx)

        def on_key_right():
            if e.modifiers() & Qt.ShiftModifier:
                if self.key_operation == Qt.Key_Left and first != last:
                    self.selection.remove(first)
                    self.last_click_idx = first + 1
                elif not self._is_last_bar(last):
                    self.key_operation = Qt.Key_Right
                    self.selection.add(last + 1)
                    self.last_click_idx = last + 1
            else:
                self.selection.clear()
                self.last_click_idx = min(last + 1, len(self.bar_items) - 1)
                self.selection.add(self.last_click_idx)

        if not self.is_valid or not self.bar_items \
                or e.key() not in (Qt.Key_Left, Qt.Key_Right):
            super().keyPressEvent(e)
            return

        prev_selection = self.selection.copy()
        if not self.selection:
            on_nothing_selected()
        else:
            first, last = min(self.selection), max(self.selection)
            if e.key() == Qt.Key_Left:
                on_key_left()
            else:
                on_key_right()

        if self.selection != prev_selection:
            self.drag_operation = self.DragAdd
            self.show_selection()
            self.apply()

    def keyReleaseEvent(self, ev):
        if ev.key() == Qt.Key_Shift:
            self.key_operation = None
        super().keyReleaseEvent(ev)


    # -----------------------------
    # Output

    def apply(self):
        data = self.data
        selected_data = annotated_data = histogram_data = None
        if self.is_valid:
            if self.var.is_discrete:
                group_indices, values = self._get_output_indices_disc()
            else:
                group_indices, values = self._get_output_indices_cont()
                hist_indices, hist_values = self._get_histogram_indices()
                histogram_data = create_groups_table(
                    data, hist_indices, values=hist_values)
            selected = np.nonzero(group_indices)[0]
            if selected.size:
                selected_data = create_groups_table(
                    data, group_indices,
                    include_unselected=False, values=values)
                annotated_data = create_annotated_table(data, selected)

        self.Outputs.selected_data.send(selected_data)
        self.Outputs.annotated_data.send(annotated_data)
        self.Outputs.histogram_data.send(histogram_data)

    def _get_output_indices_disc(self):
        group_indices = np.zeros(len(self.data), dtype=np.int32)
        col = self.data.get_column_view(self.var)[0].astype(float)
        for group_idx, val_idx in enumerate(self.selection, start=1):
            group_indices[col == val_idx] = group_idx
        values = [self.var.values[i] for i in self.selection]
        return group_indices, values

    def _get_output_indices_cont(self):
        group_indices = np.zeros(len(self.data), dtype=np.int32)
        col = self.data.get_column_view(self.var)[0].astype(float)
        values = []
        for group_idx, group in enumerate(self.grouped_selection(), start=1):
            x0 = x1 = None
            for bar_idx in group:
                minx, maxx, mask = self._get_cont_baritem_indices(col, bar_idx)
                if x0 is None:
                    x0 = minx
                x1 = maxx
                group_indices[mask] = group_idx
            # pylint: disable=undefined-loop-variable
            values.append(
                self.str_int(x0, x1, not bar_idx, self._is_last_bar(bar_idx)))
        return group_indices, values

    def _get_histogram_indices(self):
        group_indices = np.zeros(len(self.data), dtype=np.int32)
        col = self.data.get_column_view(self.var)[0].astype(float)
        values = []
        for bar_idx in range(len(self.bar_items)):
            x0, x1, mask = self._get_cont_baritem_indices(col, bar_idx)
            group_indices[mask] = bar_idx + 1
            values.append(
                self.str_int(x0, x1, not bar_idx, self._is_last_bar(bar_idx)))
        return group_indices, values

    def _get_cont_baritem_indices(self, col, bar_idx):
        bar_item = self.bar_items[bar_idx]
        minx = bar_item.x0
        maxx = bar_item.x1 + (bar_idx == len(self.bar_items) - 1)
        with np.errstate(invalid="ignore"):
            return minx, maxx, (col >= minx) * (col < maxx)

    def _is_last_bar(self, idx):
        return idx == len(self.bar_items) - 1

    # -----------------------------
    # Report

    def get_widget_name_extension(self):
        return self.var

    def send_report(self):
        self.plotview.scene().setSceneRect(self.plotview.sceneRect())
        if not self.is_valid:
            return
        self.report_plot()
        if self.cumulative_distr:
            text = f"Cummulative distribution of '{self.var.name}'"
        else:
            text = f"Distribution of '{self.var.name}'"
        if self.cvar:
            text += f" with columns split by '{self.cvar.name}'"
        self.report_caption(text)


if __name__ == "__main__":  # pragma: no cover
    WidgetPreview(OWDistributions).run(Table("heart_disease.tab"))

```
--- END FILE ---

Please first localize the bug based on the issue statement, and then generate *SEARCH/REPLACE* edits to fix the issue.

Every *SEARCH/REPLACE* edit must use this format:
1. The file path
2. The start of search block: <<<<<<< SEARCH
3. A contiguous chunk of lines to search for in the existing source code
4. The dividing line: =======
5. The lines to replace into the source code
6. The end of the replace block: >>>>>>> REPLACE

Here is an example:

```python
### mathweb/flask/app.py
<<<<<<< SEARCH
from flask import Flask
=======
import math
from flask import Flask
>>>>>>> REPLACE
```
</solution>

Please note that the *SEARCH/REPLACE* edit REQUIRES PROPER INDENTATION. If you would like to add the line '        print(x)', you must fully write that out, with all those spaces before the code!
Wrap each *SEARCH/REPLACE* edit in a code block as shown in the example above. If you have multiple *SEARCH/REPLACE* edits, use a separate code block for each one.
[ISSUE]
**Title:** Adjusting Bin Width Slider Clears Selection and Causes Indexing Errors in OWDistributions Widget

**Description:**
When interacting with the OWDistributions widget, changing the number of bins using the bin width slider leads to unexpected behavior. Specifically, altering the slider clears the current selection of bars, and attempting to group the selected bars afterward results in an IndexError.

**Example Code:**
```python
# Initialize the widget and load data
widget = create_widget(OWDistributions)
send_signal(widget.Inputs.data, iris_table)

# Select multiple bars
widget.selection.add(1)
widget.selection.add(2)
widget.selection.add(3)

# Change the number of bins using the slider
set_slider_value(1)

# Attempt to group the selected bars
widget.show_selection()
```

**Expected Behavior:**
- Changing the bin width slider should update the distribution without affecting the current selection of bars.
- Grouping the selected bars after adjusting the slider should function correctly without any errors.

**Actual Behavior:**
- Adjusting the bin width slider unexpectedly clears the current selection of bars.
- Attempting to group the previously selected bars results in an `IndexError: list index out of range`, indicating that the widget is trying to access bar items that no longer exist.

This issue hinders the usability of the OWDistributions widget by disrupting user selections and causing application crashes when grouping selections after modifying the bin width.

[/ISSUE]
{
    "TestOWDistributions.test_controls_disabling": "PASSED",
    "TestOWDistributions.test_minimum_size": "PASSED",
    "TestOWDistributions.test_msg_base_class": "PASSED",
    "TestOWDistributions.test_on_bins_changed": "PASSED",
    "TestOWDistributions.test_plot_types_combinations": "PASSED",
    "TestOWDistributions.test_report": "PASSED",
    "TestOWDistributions.test_selection_grouping": "PASSED",
    "TestOWDistributions.test_set_data": "PASSED",
    "TestOWDistributions.test_set_data_no_class": "PASSED",
    "TestOWDistributions.test_set_data_no_class_no_discrete": "PASSED",
    "TestOWDistributions.test_set_data_reg_class": "PASSED",
    "TestOWDistributions.test_set_data_reg_class_no_discrete": "PASSED",
    "TestOWDistributions.test_set_valid_data": "PASSED",
    "TestOWDistributions.test_switch_cvar": "PASSED",
    "TestOWDistributions.test_switch_var": "PASSED"
}
diff --git a/Orange/widgets/visualize/owdistributions.py b/Orange/widgets/visualize/owdistributions.py
index 0bac00e0a..820c0ea47 100644
--- a/Orange/widgets/visualize/owdistributions.py
+++ b/Orange/widgets/visualize/owdistributions.py
@@ -710,7 +710,7 @@ class OWDistributions(OWWidget):
             if np.any(np.isfinite(column)):
                 self.binnings = decimal_binnings(
                     column, min_width=self.min_var_resolution(self.var),
-                    add_unique=10, min_unique=5)
+                    add_unique=10, min_unique=5)[::-1]
                 max_bins = len(self.binnings) - 1
 
         self.controls.number_of_bins.setMaximum(max_bins)

{"Orange/widgets/visualize/owdistributions.py": "from functools import partial\nfrom itertools import count, groupby, repeat\nfrom xml.sax.saxutils import escape\n\nimport numpy as np\nfrom scipy.stats import norm, rayleigh, beta, gamma, pareto, expon\n\nfrom AnyQt.QtWidgets import QGraphicsRectItem\nfrom AnyQt.QtGui import QColor, QPen, QBrush, QPainter, QPalette, QPolygonF\nfrom AnyQt.QtCore import Qt, QRectF, QPointF, pyqtSignal as Signal\nimport pyqtgraph as pg\n\nfrom Orange.data import Table, DiscreteVariable, ContinuousVariable\nfrom Orange.preprocess.discretize import decimal_binnings\nfrom Orange.statistics import distribution, contingency\nfrom Orange.widgets import gui, settings\nfrom Orange.widgets.utils.annotated_data import \\\n    create_groups_table, create_annotated_table, ANNOTATED_DATA_SIGNAL_NAME\nfrom Orange.widgets.utils.itemmodels import DomainModel\nfrom Orange.widgets.utils.widgetpreview import WidgetPreview\nfrom Orange.widgets.visualize.utils.plotutils import ElidedLabelsAxis\nfrom Orange.widgets.widget import Input, Output, OWWidget, Msg\n\nfrom Orange.widgets.visualize.owscatterplotgraph import \\\n    LegendItem as SPGLegendItem\n\n\nclass ScatterPlotItem(pg.ScatterPlotItem):\n    Symbols = pg.graphicsItems.ScatterPlotItem.Symbols\n\n    # pylint: disable=arguments-differ\n    def paint(self, painter, option, widget=None):\n        if self.opts[\"pxMode\"]:\n            painter.setRenderHint(QPainter.SmoothPixmapTransform, True)\n        if self.opts[\"antialias\"]:\n            painter.setRenderHint(QPainter.Antialiasing, True)\n        super().paint(painter, option, widget)\n\n\nclass LegendItem(SPGLegendItem):\n    @staticmethod\n    def mousePressEvent(event):\n        if event.button() == Qt.LeftButton:\n            event.accept()\n        else:\n            event.ignore()\n\n    def mouseMoveEvent(self, event):\n        if event.buttons() & Qt.LeftButton:\n            event.accept()\n            if self.parentItem() is not None:\n                self.autoAnchor(\n                    self.pos() + (event.pos() - event.lastPos()) / 2)\n        else:\n            event.ignore()\n\n    @staticmethod\n    def mouseReleaseEvent(event):\n        if event.button() == Qt.LeftButton:\n            event.accept()\n        else:\n            event.ignore()\n\n\nclass DistributionBarItem(pg.GraphicsObject):\n    def __init__(self, x, width, padding, freqs, colors, stacked, expanded,\n                 tooltip):\n        super().__init__()\n        self.x = x\n        self.width = width\n        self.freqs = freqs\n        self.colors = colors\n        self.padding = padding\n        self.stacked = stacked\n        self.expanded = expanded\n        self.__picture = None\n        self.polygon = None\n        self.hovered = False\n        self.setAcceptHoverEvents(True)\n        self.setToolTip(tooltip)\n\n    def hoverEnterEvent(self, event):\n        super().hoverEnterEvent(event)\n        self.hovered = True\n        self.update()\n\n    def hoverLeaveEvent(self, event):\n        super().hoverLeaveEvent(event)\n        self.hovered = False\n        self.update()\n\n    def paint(self, painter, _options, _widget):\n        if self.expanded:\n            tot = np.sum(self.freqs)\n            if tot == 0:\n                return\n            freqs = self.freqs / tot\n        else:\n            freqs = self.freqs\n\n        if not self.padding:\n            padding = self.mapRectFromDevice(QRectF(0, 0, 0.5, 0)).width()\n        else:\n            padding = min(20, self.width * self.padding)\n        sx = self.x + padding\n        padded_width = self.width - 2 * padding\n\n        if self.stacked:\n            painter.setPen(Qt.NoPen)\n            y = 0\n            for freq, color in zip(freqs, self.colors):\n                painter.setBrush(QBrush(color))\n                painter.drawRect(QRectF(sx, y, padded_width, freq))\n                y += freq\n            self.polygon = QPolygonF(QRectF(sx, 0, padded_width, y))\n        else:\n            polypoints = [QPointF(sx, 0)]\n            pen = QPen(QBrush(Qt.white), 0.5)\n            pen.setCosmetic(True)\n            painter.setPen(pen)\n            wsingle = padded_width / len(self.freqs)\n            for i, freq, color in zip(count(), freqs, self.colors):\n                painter.setBrush(QBrush(color))\n                x = sx + wsingle * i\n                painter.drawRect(\n                    QRectF(x, 0, wsingle, freq))\n                polypoints += [QPointF(x, freq),\n                               QPointF(x + wsingle, freq)]\n            polypoints += [QPointF(polypoints[-1].x(), 0), QPointF(sx, 0)]\n            self.polygon = QPolygonF(polypoints)\n\n        if self.hovered:\n            pen = QPen(QBrush(Qt.blue), 2, Qt.DashLine)\n            pen.setCosmetic(True)\n            painter.setPen(pen)\n            painter.setBrush(Qt.NoBrush)\n            painter.drawPolygon(self.polygon)\n\n    @property\n    def x0(self):\n        return self.x\n\n    @property\n    def x1(self):\n        return self.x + self.width\n\n    def boundingRect(self):\n        if self.expanded:\n            height = 1\n        elif self.stacked:\n            height = sum(self.freqs)\n        else:\n            height = max(self.freqs)\n        return QRectF(self.x, 0, self.width, height)\n\n\nclass DistributionWidget(pg.PlotWidget):\n    item_clicked = Signal(DistributionBarItem, Qt.KeyboardModifiers, bool)\n    blank_clicked = Signal()\n    mouse_released = Signal()\n\n    def __init__(self, *args, **kwargs):\n        super().__init__(*args, **kwargs)\n        self.last_item = None\n\n    def _get_bar_item(self, pos):\n        for item in self.items(pos):\n            if isinstance(item, DistributionBarItem):\n                return item\n        return None\n\n    def mousePressEvent(self, ev):\n        super().mousePressEvent(ev)\n        if ev.isAccepted():\n            return\n        if ev.button() != Qt.LeftButton:\n            ev.ignore()\n            return\n\n        ev.accept()\n        self.last_item = self._get_bar_item(ev.pos())\n        if self.last_item:\n            self.item_clicked.emit(self.last_item, ev.modifiers(), False)\n        else:\n            self.blank_clicked.emit()\n\n    def mouseReleaseEvent(self, ev):\n        self.last_item = None\n        self.mouse_released.emit()\n\n    def mouseMoveEvent(self, ev):\n        super().mouseMoveEvent(ev)\n        if self.last_item is not None:\n            item = self._get_bar_item(ev.pos())\n            if item is not None and item is not self.last_item:\n                self.item_clicked.emit(item, ev.modifiers(), True)\n                self.last_item = item\n\n\nclass OWDistributions(OWWidget):\n    name = \"Distributions\"\n    description = \"Display value distributions of a data feature in a graph.\"\n    icon = \"icons/Distribution.svg\"\n    priority = 120\n    keywords = []\n\n    class Inputs:\n        data = Input(\"Data\", Table, doc=\"Set the input dataset\")\n\n    class Outputs:\n        selected_data = Output(\"Selected Data\", Table, default=True)\n        annotated_data = Output(ANNOTATED_DATA_SIGNAL_NAME, Table)\n        histogram_data = Output(\"Histogram Data\", Table)\n\n    class Error(OWWidget.Error):\n        no_defined_values_var = \\\n            Msg(\"Variable '{}' does not have any defined values\")\n        no_defined_values_pair = \\\n            Msg(\"No data instances with '{}' and '{}' defined\")\n\n    class Warning(OWWidget.Warning):\n        ignored_nans = Msg(\"Data instances with missing values are ignored\")\n\n    settingsHandler = settings.DomainContextHandler()\n    var = settings.ContextSetting(None)\n    cvar = settings.ContextSetting(None)\n    selection = settings.ContextSetting(set(), schema_only=True)\n    # number_of_bins must be a context setting because selection depends on it\n    number_of_bins = settings.ContextSetting(5, schema_only=True)\n\n    fitted_distribution = settings.Setting(0)\n    show_probs = settings.Setting(False)\n    stacked_columns = settings.Setting(False)\n    cumulative_distr = settings.Setting(False)\n\n    auto_apply = settings.Setting(True)\n\n    graph_name = \"plot\"\n\n    Fitters = (\n        (\"None\", None, (), ()),\n        (\"Normal\", norm, (\"loc\", \"scale\"), (\"\u03bc\", \"\u03c3\u00b2\")),\n        (\"Beta\", beta, (\"a\", \"b\", \"loc\", \"scale\"),\n         (\"\u03b1\", \"\u03b2\", \"-loc\", \"-scale\")),\n        (\"Gamma\", gamma, (\"a\", \"loc\", \"scale\"), (\"\u03b1\", \"\u03b2\", \"-loc\", \"-scale\")),\n        (\"Rayleigh\", rayleigh, (\"loc\", \"scale\"), (\"-loc\", \"\u03c3\u00b2\")),\n        (\"Pareto\", pareto, (\"b\", \"loc\", \"scale\"), (\"\u03b1\", \"-loc\", \"-scale\")),\n        (\"Exponential\", expon, (\"loc\", \"scale\"), (\"-loc\", \"\u03bb\")),\n    )\n\n    DragNone, DragAdd, DragRemove = range(3)\n\n    def __init__(self):\n        super().__init__()\n        self.data = None\n        self.valid_data = self.valid_group_data = None\n        self.bar_items = []\n        self.curve_descriptions = None\n        self.binnings = []\n\n        self.last_click_idx = None\n        self.drag_operation = self.DragNone\n        self.key_operation = None\n        self._user_var_bins = {}\n\n        gui.listView(\n            self.controlArea, self, \"var\", box=\"Variable\",\n            model=DomainModel(valid_types=DomainModel.PRIMITIVE,\n                              separators=False),\n            callback=self._on_var_changed)\n\n        box = self.continuous_box = gui.vBox(self.controlArea, \"Distribution\")\n        slider = gui.hSlider(\n            box, self, \"number_of_bins\",\n            label=\"Bin width\", orientation=Qt.Horizontal,\n            minValue=0, maxValue=max(1, len(self.binnings) - 1),\n            createLabel=False, callback=self._on_bins_changed)\n        self.bin_width_label = gui.widgetLabel(slider.box)\n        self.bin_width_label.setFixedWidth(35)\n        self.bin_width_label.setAlignment(Qt.AlignRight)\n        slider.sliderReleased.connect(self._on_bin_slider_released)\n        gui.comboBox(\n            box, self, \"fitted_distribution\", label=\"Fitted distribution\",\n            orientation=Qt.Horizontal, items=(name[0] for name in self.Fitters),\n            callback=self.replot)\n        gui.checkBox(\n            box, self, \"cumulative_distr\", \"Show cumulative distribution\",\n            callback=self.replot)\n\n        box = gui.vBox(self.controlArea, \"Columns\")\n        gui.comboBox(\n            box, self, \"cvar\", label=\"Split by\", orientation=Qt.Horizontal,\n            model=DomainModel(placeholder=\"(None)\",\n                              valid_types=(DiscreteVariable), ),\n            callback=self._on_cvar_changed, contentsLength=18)\n        box2 = gui.indentedBox(box, sep=12)\n        gui.checkBox(\n            box2, self, \"stacked_columns\", \"Stack columns\",\n            callback=self.replot)\n        gui.checkBox(\n            box2, self, \"show_probs\", \"Show probabilities\",\n            callback=self._on_show_probabilities_changed)\n\n        gui.auto_commit(\n            self.controlArea, self, \"auto_apply\", \"&Apply\", commit=self.apply)\n\n        self._setup_plots()\n        self._setup_legend()\n\n    def _setup_plots(self):\n        def add_new_plot(zvalue):\n            plot = pg.ViewBox(enableMouse=False, enableMenu=False)\n            self.ploti.scene().addItem(plot)\n            pg.AxisItem(\"right\").linkToView(plot)\n            plot.setXLink(self.ploti)\n            plot.setZValue(zvalue)\n            return plot\n\n        self.plotview = DistributionWidget(background=None)\n        self.plotview.item_clicked.connect(self._on_item_clicked)\n        self.plotview.blank_clicked.connect(self._on_blank_clicked)\n        self.plotview.mouse_released.connect(self._on_end_selecting)\n        self.plotview.setRenderHint(QPainter.Antialiasing)\n        self.mainArea.layout().addWidget(self.plotview)\n        self.ploti = pg.PlotItem(\n            enableMenu=False, enableMouse=False,\n            axisItems={\"bottom\": ElidedLabelsAxis(\"bottom\")})\n        self.plot = self.ploti.vb\n        self.plot.setMouseEnabled(False, False)\n        self.ploti.hideButtons()\n        self.plotview.setCentralItem(self.ploti)\n\n        self.plot_pdf = add_new_plot(10)\n        self.plot_mark = add_new_plot(-10)\n        self.plot_mark.setYRange(0, 1)\n        self.ploti.vb.sigResized.connect(self.update_views)\n        self.update_views()\n\n        pen = QPen(self.palette().color(QPalette.Text))\n        self.ploti.getAxis(\"bottom\").setPen(pen)\n        left = self.ploti.getAxis(\"left\")\n        left.setPen(pen)\n        left.setStyle(stopAxisAtTick=(True, True))\n\n    def _setup_legend(self):\n        self._legend = LegendItem()\n        self._legend.setParentItem(self.plot)\n        self._legend.hide()\n        self._legend.anchor((1, 0), (1, 0))\n\n    # -----------------------------\n    # Event and signal handlers\n\n    def update_views(self):\n        for plot in (self.plot_pdf, self.plot_mark):\n            plot.setGeometry(self.plot.sceneBoundingRect())\n            plot.linkedViewChanged(self.plot, plot.XAxis)\n\n    def onDeleteWidget(self):\n        self.plot.clear()\n        self.plot_pdf.clear()\n        self.plot_mark.clear()\n        super().onDeleteWidget()\n\n    @Inputs.data\n    def set_data(self, data):\n        self.closeContext()\n        self.var = self.cvar = None\n        self.data = data\n        domain = self.data.domain if self.data else None\n        varmodel = self.controls.var.model()\n        cvarmodel = self.controls.cvar.model()\n        varmodel.set_domain(domain)\n        cvarmodel.set_domain(domain)\n        if varmodel:\n            self.var = varmodel[min(len(domain.class_vars), len(varmodel) - 1)]\n        if domain is not None and domain.has_discrete_class:\n            self.cvar = domain.class_var\n        self.reset_select()\n        self._user_var_bins.clear()\n        self.openContext(domain)\n        self.set_valid_data()\n        self.recompute_binnings()\n        self.replot()\n        self.apply()\n\n    def _on_var_changed(self):\n        self.reset_select()\n        self.set_valid_data()\n        self.recompute_binnings()\n        self.replot()\n        self.apply()\n\n    def _on_cvar_changed(self):\n        self.set_valid_data()\n        self.replot()\n        self.apply()\n\n    def _on_bins_changed(self):\n        self.reset_select()\n        self._set_bin_width_slider_label()\n        self.replot()\n        # this is triggered when dragging, so don't call apply here;\n        # apply is called on sliderReleased\n\n    def _on_bin_slider_released(self):\n        self._user_var_bins[self.var] = self.number_of_bins\n        self.apply()\n\n    def _set_bin_width_slider_label(self):\n        text = \"\"\n        if self.number_of_bins < len(self.binnings):\n            bins = self.binnings[self.number_of_bins]\n            if len(bins) > 1:\n                text = self.var.repr_val(bins[1] - bins[0])\n        self.bin_width_label.setText(text)\n\n    def _on_show_probabilities_changed(self):\n        label = self.controls.fitted_distribution.label\n        if self.show_probs:\n            label.setText(\"Fitted probability\")\n            label.setToolTip(\n                \"Chosen distribution is used to compute Bayesian probabilities\")\n        else:\n            label.setText(\"Fitted distribution\")\n            label.setToolTip(\"\")\n        self.replot()\n\n    @property\n    def is_valid(self):\n        return self.valid_data is not None\n\n    def set_valid_data(self):\n        err_def_var = self.Error.no_defined_values_var\n        err_def_pair = self.Error.no_defined_values_pair\n        err_def_var.clear()\n        err_def_pair.clear()\n        self.Warning.ignored_nans.clear()\n\n        self.valid_data = self.valid_group_data = None\n        if self.var is None:\n            return\n\n        column = self.data.get_column_view(self.var)[0].astype(float)\n        valid_mask = np.isfinite(column)\n        if not np.any(valid_mask):\n            self.Error.no_defined_values_var(self.var.name)\n            return\n        if self.cvar:\n            ccolumn = self.data.get_column_view(self.cvar)[0].astype(float)\n            valid_mask *= np.isfinite(ccolumn)\n            if not np.any(valid_mask):\n                self.Error.no_defined_values_pair(self.var.name, self.cvar.name)\n                return\n            self.valid_group_data = ccolumn[valid_mask]\n        if not np.all(valid_mask):\n            self.Warning.ignored_nans()\n        self.valid_data = column[valid_mask]\n\n    # -----------------------------\n    # Plotting\n\n    def replot(self):\n        self._clear_plot()\n        if self.is_valid:\n            self._set_axis_names()\n            self._update_controls_state()\n            self._call_plotting()\n            self._display_legend()\n        self.show_selection()\n\n    def _clear_plot(self):\n        self.plot.clear()\n        self.plot_pdf.clear()\n        self.plot_mark.clear()\n        self.bar_items = []\n        self._legend.clear()\n        self._legend.hide()\n\n    def _set_axis_names(self):\n        assert self.is_valid  # called only from replot, so assumes data is OK\n        bottomaxis = self.ploti.getAxis(\"bottom\")\n        bottomaxis.setLabel(self.var and self.var.name)\n\n        leftaxis = self.ploti.getAxis(\"left\")\n        if self.show_probs and self.cvar:\n            leftaxis.setLabel(\n                f\"Probability of '{self.cvar.name}' at given '{self.var.name}'\")\n        else:\n            leftaxis.setLabel(\"Frequency\")\n        leftaxis.resizeEvent()\n\n    def _update_controls_state(self):\n        assert self.is_valid  # called only from replot, so assumes data is OK\n        self.continuous_box.setDisabled(self.var.is_discrete)\n        self.controls.show_probs.setDisabled(self.cvar is None)\n        self.controls.stacked_columns.setDisabled(self.cvar is None)\n\n    def _call_plotting(self):\n        assert self.is_valid  # called only from replot, so assumes data is OK\n        self.curve_descriptions = None\n        if self.var.is_discrete:\n            if self.cvar:\n                self._disc_split_plot()\n            else:\n                self._disc_plot()\n        else:\n            if self.cvar:\n                self._cont_split_plot()\n            else:\n                self._cont_plot()\n        self.plot.autoRange()\n\n    def _add_bar(self, x, width, padding, freqs, colors, stacked, expanded,\n                 tooltip):\n        item = DistributionBarItem(\n            x, width, padding, freqs, colors, stacked, expanded, tooltip)\n        self.plot.addItem(item)\n        self.bar_items.append(item)\n\n    def _disc_plot(self):\n        var = self.var\n        self.ploti.getAxis(\"bottom\").setTicks([list(enumerate(var.values))])\n        colors = [QColor(0, 128, 255)]\n        dist = distribution.get_distribution(self.data, self.var)\n        for i, freq in enumerate(dist):\n            tooltip = \\\n                \"<p style='white-space:pre;'>\" \\\n                f\"<b>{escape(var.values[i])}</b>: {int(freq)} \" \\\n                f\"({100 * freq / len(self.valid_data):.2f} %) \"\n            self._add_bar(\n                i - 0.5, 1, 0.1, [freq], colors,\n                stacked=False, expanded=False, tooltip=tooltip)\n\n    def _disc_split_plot(self):\n        var = self.var\n        self.ploti.getAxis(\"bottom\").setTicks([list(enumerate(var.values))])\n        gcolors = [QColor(*col) for col in self.cvar.colors]\n        gvalues = self.cvar.values\n        conts = contingency.get_contingency(self.data, self.cvar, self.var)\n        total = len(self.data)\n        for i, freqs in enumerate(conts):\n            self._add_bar(\n                i - 0.5, 1, 0.1, freqs, gcolors,\n                stacked=self.stacked_columns, expanded=self.show_probs,\n                tooltip=self._split_tooltip(\n                    var.values[i], np.sum(freqs), total, gvalues, freqs))\n\n    def _cont_plot(self):\n        self.ploti.getAxis(\"bottom\").setTicks(None)\n        data = self.valid_data\n        y, x = np.histogram(data, bins=self.binnings[self.number_of_bins])\n        total = len(data)\n        colors = [QColor(0, 128, 255)]\n        if self.fitted_distribution:\n            colors[0] = colors[0].lighter(130)\n\n        tot_freq = 0\n        lasti = len(y) - 1\n        for i, (x0, x1), freq in zip(count(), zip(x, x[1:]), y):\n            tot_freq += freq\n            tooltip = \\\n                \"<p style='white-space:pre;'>\" \\\n                f\"<b>{escape(self.str_int(x0, x1, not i, i == lasti))}</b>: \" \\\n                f\"{freq} ({100 * freq / total:.2f} %)</p>\"\n            self._add_bar(\n                x0, x1 - x0, 0, [tot_freq if self.cumulative_distr else freq],\n                colors, stacked=False, expanded=False, tooltip=tooltip)\n\n        if self.fitted_distribution:\n            self._plot_approximations(\n                x[0], x[-1], [self._fit_approximation(data)],\n                [QColor(0, 0, 0)], (1,))\n\n    def _cont_split_plot(self):\n        self.ploti.getAxis(\"bottom\").setTicks(None)\n        data = self.valid_data\n        _, bins = np.histogram(data, bins=self.binnings[self.number_of_bins])\n        gvalues = self.cvar.values\n        varcolors = [QColor(*col) for col in self.cvar.colors]\n        if self.fitted_distribution:\n            gcolors = [c.lighter(130) for c in varcolors]\n        else:\n            gcolors = varcolors\n        nvalues = len(gvalues)\n        ys = []\n        fitters = []\n        prior_sizes = []\n        for val_idx in range(nvalues):\n            group_data = data[self.valid_group_data == val_idx]\n            prior_sizes.append(len(group_data))\n            ys.append(np.histogram(group_data, bins)[0])\n            if self.fitted_distribution:\n                fitters.append(self._fit_approximation(group_data))\n        total = len(data)\n        prior_sizes = np.array(prior_sizes)\n        tot_freqs = np.zeros(len(ys))\n\n        lasti = len(ys[0]) - 1\n        for i, x0, x1, freqs in zip(count(), bins, bins[1:], zip(*ys)):\n            tot_freqs += freqs\n            plotfreqs = tot_freqs.copy() if self.cumulative_distr else freqs\n            self._add_bar(\n                x0, x1 - x0, 0 if self.stacked_columns else 0.1, plotfreqs,\n                gcolors, stacked=self.stacked_columns, expanded=self.show_probs,\n                tooltip=self._split_tooltip(\n                    self.str_int(x0, x1, not i, i == lasti),\n                    np.sum(plotfreqs), total, gvalues, plotfreqs))\n\n        if fitters:\n            self._plot_approximations(bins[0], bins[-1], fitters, varcolors,\n                                      prior_sizes / len(data))\n\n    def _fit_approximation(self, y):\n        def join_pars(pairs):\n            strv = self.var.str_val\n            return \", \".join(f\"{sname}={strv(val)}\" for sname, val in pairs)\n\n        def str_params():\n            s = join_pars(\n                (sname, val) for sname, val in zip(str_names, fitted)\n                if sname[0] != \"-\")\n            par = join_pars(\n                (sname[1:], val) for sname, val in zip(str_names, fitted)\n                if sname[0] == \"-\")\n            if par:\n                s += f\" ({par})\"\n            return s\n\n        _, dist, names, str_names = self.Fitters[self.fitted_distribution]\n        fitted = dist.fit(y)\n        params = {name: val for name, val in zip(names, fitted)}\n        return partial(dist.pdf, **params), str_params()\n\n    def _plot_approximations(self, x0, x1, fitters, colors, prior_probs=0):\n        x = np.linspace(x0, x1, 100)\n        ys = np.empty((len(fitters), 100))\n        self.curve_descriptions = [s for _, s in fitters]\n        for y, (fitter, _), color in zip(ys, fitters, colors):\n            y[:] = fitter(x)\n            if self.cumulative_distr:\n                y[:] = np.cumsum(y)\n        tots = np.sum(ys, axis=0)\n\n        show_probs = self.show_probs and self.cvar is not None\n        plot = self.ploti if show_probs else self.plot_pdf\n\n        for y, prior_prob, color in zip(ys, prior_probs, colors):\n            if show_probs:\n                y_p = y * prior_prob\n                y = y_p / (y_p + (tots - y) * (1 - prior_prob))\n            plot.addItem(pg.PlotCurveItem(\n                x=x, y=y,\n                pen=pg.mkPen(width=5, color=color),\n                shadowPen=pg.mkPen(width=8, color=color.darker(120))))\n        if not show_probs:\n            self.plot_pdf.autoRange()\n\n    @staticmethod\n    def _split_tooltip(valname, tot_group, total, gvalues, freqs):\n        div_group = tot_group or 1\n        cs = \"white-space:pre; text-align: right;\"\n        s = f\"style='{cs} padding-left: 1em'\"\n        snp = f\"style='{cs}'\"\n        return f\"<table style='border-collapse: collapse'>\" \\\n               f\"<tr><th {s}>{escape(valname)}:</th>\" \\\n               f\"<td {snp}><b>{int(tot_group)}</b></td>\" \\\n               \"<td/>\" \\\n               f\"<td {s}><b>{100 * tot_group / total:.2f} %</b></td></tr>\" + \\\n               f\"<tr><td/><td/><td {s}>(in group)</td><td {s}>(overall)</td>\" \\\n               \"</tr>\" + \\\n               \"\".join(\n                   \"<tr>\"\n                   f\"<th {s}>{value}:</th>\"\n                   f\"<td {snp}><b>{int(freq)}</b></td>\"\n                   f\"<td {s}>{100 * freq / div_group:.2f} %</td>\"\n                   f\"<td {s}>{100 * freq / total:.2f} %</td>\"\n                   \"</tr>\"\n                   for value, freq in zip(gvalues, freqs)) + \\\n               \"</table>\"\n\n    def _display_legend(self):\n        assert self.is_valid  # called only from replot, so assumes data is OK\n        if self.cvar is None:\n            if not self.curve_descriptions:\n                self._legend.hide()\n                return\n            self._legend.addItem(\n                pg.PlotCurveItem(pen=pg.mkPen(width=5, color=0.0)),\n                self.curve_descriptions[0])\n        else:\n            cvar_values = self.cvar.values\n            colors = [QColor(*col) for col in self.cvar.colors]\n            descriptions = self.curve_descriptions or repeat(None)\n            for color, name, desc in zip(colors, cvar_values, descriptions):\n                self._legend.addItem(\n                    ScatterPlotItem(pen=color, brush=color, size=10, shape=\"s\"),\n                    escape(name + (f\" ({desc})\" if desc else \"\")))\n        self._legend.show()\n\n    # -----------------------------\n    # Bins\n\n    def recompute_binnings(self):\n        self.binnings = []\n        max_bins = 0\n        if self.is_valid and self.var.is_continuous:\n            # binning is computed on valid var data, ignoring any cvar nans\n            column = self.data.get_column_view(self.var)[0].astype(float)\n            if np.any(np.isfinite(column)):\n                self.binnings = decimal_binnings(\n                    column, min_width=self.min_var_resolution(self.var),\n                    add_unique=10, min_unique=5)\n                max_bins = len(self.binnings) - 1\n\n        self.controls.number_of_bins.setMaximum(max_bins)\n        self.number_of_bins = min(\n            max_bins, self._user_var_bins.get(self.var, self.number_of_bins))\n        self._set_bin_width_slider_label()\n\n    @staticmethod\n    def min_var_resolution(var):\n        # pylint: disable=unidiomatic-typecheck\n        if type(var) is not ContinuousVariable:\n            return 0\n        return 10 ** -var.number_of_decimals\n\n    def str_int(self, x0, x1, first, last):\n        var = self.var\n        sx0, sx1 = var.repr_val(x0), var.repr_val(x1)\n        if self.cumulative_distr:\n            return f\"{var.name} < {sx1}\"\n        elif first and last:\n            return f\"{var.name} = {sx0}\"\n        elif first:\n            return f\"{var.name} < {sx1}\"\n        elif last:\n            return f\"{var.name} \u2265 {sx0}\"\n        elif sx0 == sx1 or x1 - x0 <= self.min_var_resolution(var):\n            return f\"{var.name} = {sx0}\"\n        else:\n            return f\"{sx0} \u2264 {var.name} < {sx1}\"\n\n    # -----------------------------\n    # Selection\n\n    def _on_item_clicked(self, item, modifiers, drag):\n        def add_or_remove(idx, add):\n            self.drag_operation = [self.DragRemove, self.DragAdd][add]\n            if add:\n                self.selection.add(idx)\n            else:\n                if idx in self.selection:\n                    # This can be False when removing with dragging and the\n                    # mouse crosses unselected items\n                    self.selection.remove(idx)\n\n        def add_range(add):\n            if self.last_click_idx is None:\n                add = True\n                idx_range = {idx}\n            else:\n                from_idx, to_idx = sorted((self.last_click_idx, idx))\n                idx_range = set(range(from_idx, to_idx + 1))\n            self.drag_operation = [self.DragRemove, self.DragAdd][add]\n            if add:\n                self.selection |= idx_range\n            else:\n                self.selection -= idx_range\n\n        self.key_operation = None\n        if item is None:\n            self.reset_select()\n            return\n\n        idx = self.bar_items.index(item)\n        if drag:\n            # Dragging has to add a range, otherwise fast dragging skips bars\n            add_range(self.drag_operation == self.DragAdd)\n        else:\n            if modifiers & Qt.ShiftModifier:\n                add_range(self.drag_operation == self.DragAdd)\n            elif modifiers & Qt.ControlModifier:\n                add_or_remove(idx, add=idx not in self.selection)\n            else:\n                if self.selection == {idx}:\n                    # Clicking on a single selected bar  deselects it,\n                    # but dragging from here will select\n                    add_or_remove(idx, add=False)\n                    self.drag_operation = self.DragAdd\n                else:\n                    self.selection.clear()\n                    add_or_remove(idx, add=True)\n        self.last_click_idx = idx\n\n        self.show_selection()\n\n    def _on_blank_clicked(self):\n        self.reset_select()\n\n    def reset_select(self):\n        self.selection.clear()\n        self.last_click_idx = None\n        self.drag_operation = None\n        self.key_operation = None\n        self.show_selection()\n\n    def _on_end_selecting(self):\n        self.apply()\n\n    def show_selection(self):\n        self.plot_mark.clear()\n        if not self.is_valid:  # though if it's not, selection is empty anyway\n            return\n\n        blue = QColor(Qt.blue)\n        pen = QPen(QBrush(blue), 3)\n        pen.setCosmetic(True)\n        brush = QBrush(blue.lighter(190))\n\n        for group in self.grouped_selection():\n            group = list(group)\n            left_idx, right_idx = group[0], group[-1]\n            left_pad, right_pad = self._determine_padding(left_idx, right_idx)\n            x0 = self.bar_items[left_idx].x0 - left_pad\n            x1 = self.bar_items[right_idx].x1 + right_pad\n            item = QGraphicsRectItem(x0, 0, x1 - x0, 1)\n            item.setPen(pen)\n            item.setBrush(brush)\n            if self.var.is_continuous:\n                valname = self.str_int(\n                    x0, x1, not left_idx, right_idx == len(self.bar_items) - 1)\n                inside = sum(np.sum(self.bar_items[i].freqs) for i in group)\n                total = len(self.valid_data)\n                item.setToolTip(\n                    \"<p style='white-space:pre;'>\"\n                    f\"<b>{escape(valname)}</b>: \"\n                    f\"{inside} ({100 * inside / total:.2f} %)\")\n            self.plot_mark.addItem(item)\n\n    def _determine_padding(self, left_idx, right_idx):\n        def _padding(i):\n            return (self.bar_items[i + 1].x0 - self.bar_items[i].x1) / 2\n\n        if len(self.bar_items) == 1:\n            return 6, 6\n        if left_idx == 0 and right_idx == len(self.bar_items) - 1:\n            return (_padding(0), ) * 2\n\n        if left_idx > 0:\n            left_pad = _padding(left_idx - 1)\n        if right_idx < len(self.bar_items) - 1:\n            right_pad = _padding(right_idx)\n        else:\n            right_pad = left_pad\n        if left_idx == 0:\n            left_pad = right_pad\n        return left_pad, right_pad\n\n    def grouped_selection(self):\n        return [[g[1] for g in group]\n                for _, group in groupby(enumerate(sorted(self.selection)),\n                                        key=lambda x: x[1] - x[0])]\n\n    def keyPressEvent(self, e):\n        def on_nothing_selected():\n            if e.key() == Qt.Key_Left:\n                self.last_click_idx = len(self.bar_items) - 1\n            else:\n                self.last_click_idx = 0\n            self.selection.add(self.last_click_idx)\n\n        def on_key_left():\n            if e.modifiers() & Qt.ShiftModifier:\n                if self.key_operation == Qt.Key_Right and first != last:\n                    self.selection.remove(last)\n                    self.last_click_idx = last - 1\n                elif first:\n                    self.key_operation = Qt.Key_Left\n                    self.selection.add(first - 1)\n                    self.last_click_idx = first - 1\n            else:\n                self.selection.clear()\n                self.last_click_idx = max(first - 1, 0)\n                self.selection.add(self.last_click_idx)\n\n        def on_key_right():\n            if e.modifiers() & Qt.ShiftModifier:\n                if self.key_operation == Qt.Key_Left and first != last:\n                    self.selection.remove(first)\n                    self.last_click_idx = first + 1\n                elif not self._is_last_bar(last):\n                    self.key_operation = Qt.Key_Right\n                    self.selection.add(last + 1)\n                    self.last_click_idx = last + 1\n            else:\n                self.selection.clear()\n                self.last_click_idx = min(last + 1, len(self.bar_items) - 1)\n                self.selection.add(self.last_click_idx)\n\n        if not self.is_valid or not self.bar_items \\\n                or e.key() not in (Qt.Key_Left, Qt.Key_Right):\n            super().keyPressEvent(e)\n            return\n\n        prev_selection = self.selection.copy()\n        if not self.selection:\n            on_nothing_selected()\n        else:\n            first, last = min(self.selection), max(self.selection)\n            if e.key() == Qt.Key_Left:\n                on_key_left()\n            else:\n                on_key_right()\n\n        if self.selection != prev_selection:\n            self.drag_operation = self.DragAdd\n            self.show_selection()\n            self.apply()\n\n    def keyReleaseEvent(self, ev):\n        if ev.key() == Qt.Key_Shift:\n            self.key_operation = None\n        super().keyReleaseEvent(ev)\n\n\n    # -----------------------------\n    # Output\n\n    def apply(self):\n        data = self.data\n        selected_data = annotated_data = histogram_data = None\n        if self.is_valid:\n            if self.var.is_discrete:\n                group_indices, values = self._get_output_indices_disc()\n            else:\n                group_indices, values = self._get_output_indices_cont()\n                hist_indices, hist_values = self._get_histogram_indices()\n                histogram_data = create_groups_table(\n                    data, hist_indices, values=hist_values)\n            selected = np.nonzero(group_indices)[0]\n            if selected.size:\n                selected_data = create_groups_table(\n                    data, group_indices,\n                    include_unselected=False, values=values)\n                annotated_data = create_annotated_table(data, selected)\n\n        self.Outputs.selected_data.send(selected_data)\n        self.Outputs.annotated_data.send(annotated_data)\n        self.Outputs.histogram_data.send(histogram_data)\n\n    def _get_output_indices_disc(self):\n        group_indices = np.zeros(len(self.data), dtype=np.int32)\n        col = self.data.get_column_view(self.var)[0].astype(float)\n        for group_idx, val_idx in enumerate(self.selection, start=1):\n            group_indices[col == val_idx] = group_idx\n        values = [self.var.values[i] for i in self.selection]\n        return group_indices, values\n\n    def _get_output_indices_cont(self):\n        group_indices = np.zeros(len(self.data), dtype=np.int32)\n        col = self.data.get_column_view(self.var)[0].astype(float)\n        values = []\n        for group_idx, group in enumerate(self.grouped_selection(), start=1):\n            x0 = x1 = None\n            for bar_idx in group:\n                minx, maxx, mask = self._get_cont_baritem_indices(col, bar_idx)\n                if x0 is None:\n                    x0 = minx\n                x1 = maxx\n                group_indices[mask] = group_idx\n            # pylint: disable=undefined-loop-variable\n            values.append(\n                self.str_int(x0, x1, not bar_idx, self._is_last_bar(bar_idx)))\n        return group_indices, values\n\n    def _get_histogram_indices(self):\n        group_indices = np.zeros(len(self.data), dtype=np.int32)\n        col = self.data.get_column_view(self.var)[0].astype(float)\n        values = []\n        for bar_idx in range(len(self.bar_items)):\n            x0, x1, mask = self._get_cont_baritem_indices(col, bar_idx)\n            group_indices[mask] = bar_idx + 1\n            values.append(\n                self.str_int(x0, x1, not bar_idx, self._is_last_bar(bar_idx)))\n        return group_indices, values\n\n    def _get_cont_baritem_indices(self, col, bar_idx):\n        bar_item = self.bar_items[bar_idx]\n        minx = bar_item.x0\n        maxx = bar_item.x1 + (bar_idx == len(self.bar_items) - 1)\n        with np.errstate(invalid=\"ignore\"):\n            return minx, maxx, (col >= minx) * (col < maxx)\n\n    def _is_last_bar(self, idx):\n        return idx == len(self.bar_items) - 1\n\n    # -----------------------------\n    # Report\n\n    def get_widget_name_extension(self):\n        return self.var\n\n    def send_report(self):\n        self.plotview.scene().setSceneRect(self.plotview.sceneRect())\n        if not self.is_valid:\n            return\n        self.report_plot()\n        if self.cumulative_distr:\n            text = f\"Cummulative distribution of '{self.var.name}'\"\n        else:\n            text = f\"Distribution of '{self.var.name}'\"\n        if self.cvar:\n            text += f\" with columns split by '{self.cvar.name}'\"\n        self.report_caption(text)\n\n\nif __name__ == \"__main__\":  # pragma: no cover\n    WidgetPreview(OWDistributions).run(Table(\"heart_disease.tab\"))\n"}
A user will ask you to solve a task. You should first draft your thinking process (inner monologue). Then, generate the solution.

Your response format must follow the template below:
<think>
Your thoughts or/and draft, like working through an exercise on scratch paper. Be as casual and as long as you want until you are confident to generate a correct solution.
</think>
<solution>
Final solution presented to the user.
</solution>
system
We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
[ISSUE]
**Title:** Adjusting Bin Width Slider Clears Selection and Causes Indexing Errors in OWDistributions Widget

**Description:**
When interacting with the OWDistributions widget, changing the number of bins using the bin width slider leads to unexpected behavior. Specifically, altering the slider clears the current selection of bars, and attempting to group the selected bars afterward results in an IndexError.

**Example Code:**
```python
# Initialize the widget and load data
widget = create_widget(OWDistributions)
send_signal(widget.Inputs.data, iris_table)

# Select multiple bars
widget.selection.add(1)
widget.selection.add(2)
widget.selection.add(3)

# Change the number of bins using the slider
set_slider_value(1)

# Attempt to group the selected bars
widget.show_selection()
```

**Expected Behavior:**
- Changing the bin width slider should update the distribution without affecting the current selection of bars.
- Grouping the selected bars after adjusting the slider should function correctly without any errors.

**Actual Behavior:**
- Adjusting the bin width slider unexpectedly clears the current selection of bars.
- Attempting to group the previously selected bars results in an `IndexError: list index out of range`, indicating that the widget is trying to access bar items that no longer exist.

This issue hinders the usability of the OWDistributions widget by disrupting user selections and causing application crashes when grouping selections after modifying the bin width.

[/ISSUE]
--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.

--- BEGIN FILE ---
```
### Orange/widgets/visualize/owdistributions.py
from functools import partial
from itertools import count, groupby, repeat
from xml.sax.saxutils import escape

import numpy as np
from scipy.stats import norm, rayleigh, beta, gamma, pareto, expon

from AnyQt.QtWidgets import QGraphicsRectItem
from AnyQt.QtGui import QColor, QPen, QBrush, QPainter, QPalette, QPolygonF
from AnyQt.QtCore import Qt, QRectF, QPointF, pyqtSignal as Signal
import pyqtgraph as pg

from Orange.data import Table, DiscreteVariable, ContinuousVariable
from Orange.preprocess.discretize import decimal_binnings
from Orange.statistics import distribution, contingency
from Orange.widgets import gui, settings
from Orange.widgets.utils.annotated_data import \
    create_groups_table, create_annotated_table, ANNOTATED_DATA_SIGNAL_NAME
from Orange.widgets.utils.itemmodels import DomainModel
from Orange.widgets.utils.widgetpreview import WidgetPreview
from Orange.widgets.visualize.utils.plotutils import ElidedLabelsAxis
from Orange.widgets.widget import Input, Output, OWWidget, Msg

from Orange.widgets.visualize.owscatterplotgraph import \
    LegendItem as SPGLegendItem


class ScatterPlotItem(pg.ScatterPlotItem):
    Symbols = pg.graphicsItems.ScatterPlotItem.Symbols

    # pylint: disable=arguments-differ
    def paint(self, painter, option, widget=None):
        if self.opts["pxMode"]:
            painter.setRenderHint(QPainter.SmoothPixmapTransform, True)
        if self.opts["antialias"]:
            painter.setRenderHint(QPainter.Antialiasing, True)
        super().paint(painter, option, widget)


class LegendItem(SPGLegendItem):
    @staticmethod
    def mousePressEvent(event):
        if event.button() == Qt.LeftButton:
            event.accept()
        else:
            event.ignore()

    def mouseMoveEvent(self, event):
        if event.buttons() & Qt.LeftButton:
            event.accept()
            if self.parentItem() is not None:
                self.autoAnchor(
                    self.pos() + (event.pos() - event.lastPos()) / 2)
        else:
            event.ignore()

    @staticmethod
    def mouseReleaseEvent(event):
        if event.button() == Qt.LeftButton:
            event.accept()
        else:
            event.ignore()


class DistributionBarItem(pg.GraphicsObject):
    def __init__(self, x, width, padding, freqs, colors, stacked, expanded,
                 tooltip):
        super().__init__()
        self.x = x
        self.width = width
        self.freqs = freqs
        self.colors = colors
        self.padding = padding
        self.stacked = stacked
        self.expanded = expanded
        self.__picture = None
        self.polygon = None
        self.hovered = False
        self.setAcceptHoverEvents(True)
        self.setToolTip(tooltip)

    def hoverEnterEvent(self, event):
        super().hoverEnterEvent(event)
        self.hovered = True
        self.update()

    def hoverLeaveEvent(self, event):
        super().hoverLeaveEvent(event)
        self.hovered = False
        self.update()

    def paint(self, painter, _options, _widget):
        if self.expanded:
            tot = np.sum(self.freqs)
            if tot == 0:
                return
            freqs = self.freqs / tot
        else:
            freqs = self.freqs

        if not self.padding:
            padding = self.mapRectFromDevice(QRectF(0, 0, 0.5, 0)).width()
        else:
            padding = min(20, self.width * self.padding)
        sx = self.x + padding
        padded_width = self.width - 2 * padding

        if self.stacked:
            painter.setPen(Qt.NoPen)
            y = 0
            for freq, color in zip(freqs, self.colors):
                painter.setBrush(QBrush(color))
                painter.drawRect(QRectF(sx, y, padded_width, freq))
                y += freq
            self.polygon = QPolygonF(QRectF(sx, 0, padded_width, y))
        else:
            polypoints = [QPointF(sx, 0)]
            pen = QPen(QBrush(Qt.white), 0.5)
            pen.setCosmetic(True)
            painter.setPen(pen)
            wsingle = padded_width / len(self.freqs)
            for i, freq, color in zip(count(), freqs, self.colors):
                painter.setBrush(QBrush(color))
                x = sx + wsingle * i
                painter.drawRect(
                    QRectF(x, 0, wsingle, freq))
                polypoints += [QPointF(x, freq),
                               QPointF(x + wsingle, freq)]
            polypoints += [QPointF(polypoints[-1].x(), 0), QPointF(sx, 0)]
            self.polygon = QPolygonF(polypoints)

        if self.hovered:
            pen = QPen(QBrush(Qt.blue), 2, Qt.DashLine)
            pen.setCosmetic(True)
            painter.setPen(pen)
            painter.setBrush(Qt.NoBrush)
            painter.drawPolygon(self.polygon)

    @property
    def x0(self):
        return self.x

    @property
    def x1(self):
        return self.x + self.width

    def boundingRect(self):
        if self.expanded:
            height = 1
        elif self.stacked:
            height = sum(self.freqs)
        else:
            height = max(self.freqs)
        return QRectF(self.x, 0, self.width, height)


class DistributionWidget(pg.PlotWidget):
    item_clicked = Signal(DistributionBarItem, Qt.KeyboardModifiers, bool)
    blank_clicked = Signal()
    mouse_released = Signal()

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.last_item = None

    def _get_bar_item(self, pos):
        for item in self.items(pos):
            if isinstance(item, DistributionBarItem):
                return item
        return None

    def mousePressEvent(self, ev):
        super().mousePressEvent(ev)
        if ev.isAccepted():
            return
        if ev.button() != Qt.LeftButton:
            ev.ignore()
            return

        ev.accept()
        self.last_item = self._get_bar_item(ev.pos())
        if self.last_item:
            self.item_clicked.emit(self.last_item, ev.modifiers(), False)
        else:
            self.blank_clicked.emit()

    def mouseReleaseEvent(self, ev):
        self.last_item = None
        self.mouse_released.emit()

    def mouseMoveEvent(self, ev):
        super().mouseMoveEvent(ev)
        if self.last_item is not None:
            item = self._get_bar_item(ev.pos())
            if item is not None and item is not self.last_item:
                self.item_clicked.emit(item, ev.modifiers(), True)
                self.last_item = item


class OWDistributions(OWWidget):
    name = "Distributions"
    description = "Display value distributions of a data feature in a graph."
    icon = "icons/Distribution.svg"
    priority = 120
    keywords = []

    class Inputs:
        data = Input("Data", Table, doc="Set the input dataset")

    class Outputs:
        selected_data = Output("Selected Data", Table, default=True)
        annotated_data = Output(ANNOTATED_DATA_SIGNAL_NAME, Table)
        histogram_data = Output("Histogram Data", Table)

    class Error(OWWidget.Error):
        no_defined_values_var = \
            Msg("Variable '{}' does not have any defined values")
        no_defined_values_pair = \
            Msg("No data instances with '{}' and '{}' defined")

    class Warning(OWWidget.Warning):
        ignored_nans = Msg("Data instances with missing values are ignored")

    settingsHandler = settings.DomainContextHandler()
    var = settings.ContextSetting(None)
    cvar = settings.ContextSetting(None)
    selection = settings.ContextSetting(set(), schema_only=True)
    # number_of_bins must be a context setting because selection depends on it
    number_of_bins = settings.ContextSetting(5, schema_only=True)

    fitted_distribution = settings.Setting(0)
    show_probs = settings.Setting(False)
    stacked_columns = settings.Setting(False)
    cumulative_distr = settings.Setting(False)

    auto_apply = settings.Setting(True)

    graph_name = "plot"

    Fitters = (
        ("None", None, (), ()),
        ("Normal", norm, ("loc", "scale"), ("μ", "σ²")),
        ("Beta", beta, ("a", "b", "loc", "scale"),
         ("α", "β", "-loc", "-scale")),
        ("Gamma", gamma, ("a", "loc", "scale"), ("α", "β", "-loc", "-scale")),
        ("Rayleigh", rayleigh, ("loc", "scale"), ("-loc", "σ²")),
        ("Pareto", pareto, ("b", "loc", "scale"), ("α", "-loc", "-scale")),
        ("Exponential", expon, ("loc", "scale"), ("-loc", "λ")),
    )

    DragNone, DragAdd, DragRemove = range(3)

    def __init__(self):
        super().__init__()
        self.data = None
        self.valid_data = self.valid_group_data = None
        self.bar_items = []
        self.curve_descriptions = None
        self.binnings = []

        self.last_click_idx = None
        self.drag_operation = self.DragNone
        self.key_operation = None
        self._user_var_bins = {}

        gui.listView(
            self.controlArea, self, "var", box="Variable",
            model=DomainModel(valid_types=DomainModel.PRIMITIVE,
                              separators=False),
            callback=self._on_var_changed)

        box = self.continuous_box = gui.vBox(self.controlArea, "Distribution")
        slider = gui.hSlider(
            box, self, "number_of_bins",
            label="Bin width", orientation=Qt.Horizontal,
            minValue=0, maxValue=max(1, len(self.binnings) - 1),
            createLabel=False, callback=self._on_bins_changed)
        self.bin_width_label = gui.widgetLabel(slider.box)
        self.bin_width_label.setFixedWidth(35)
        self.bin_width_label.setAlignment(Qt.AlignRight)
        slider.sliderReleased.connect(self._on_bin_slider_released)
        gui.comboBox(
            box, self, "fitted_distribution", label="Fitted distribution",
            orientation=Qt.Horizontal, items=(name[0] for name in self.Fitters),
            callback=self.replot)
        gui.checkBox(
            box, self, "cumulative_distr", "Show cumulative distribution",
            callback=self.replot)

        box = gui.vBox(self.controlArea, "Columns")
        gui.comboBox(
            box, self, "cvar", label="Split by", orientation=Qt.Horizontal,
            model=DomainModel(placeholder="(None)",
                              valid_types=(DiscreteVariable), ),
            callback=self._on_cvar_changed, contentsLength=18)
        box2 = gui.indentedBox(box, sep=12)
        gui.checkBox(
            box2, self, "stacked_columns", "Stack columns",
            callback=self.replot)
        gui.checkBox(
            box2, self, "show_probs", "Show probabilities",
            callback=self._on_show_probabilities_changed)

        gui.auto_commit(
            self.controlArea, self, "auto_apply", "&Apply", commit=self.apply)

        self._setup_plots()
        self._setup_legend()

    def _setup_plots(self):
        def add_new_plot(zvalue):
            plot = pg.ViewBox(enableMouse=False, enableMenu=False)
            self.ploti.scene().addItem(plot)
            pg.AxisItem("right").linkToView(plot)
            plot.setXLink(self.ploti)
            plot.setZValue(zvalue)
            return plot

        self.plotview = DistributionWidget(background=None)
        self.plotview.item_clicked.connect(self._on_item_clicked)
        self.plotview.blank_clicked.connect(self._on_blank_clicked)
        self.plotview.mouse_released.connect(self._on_end_selecting)
        self.plotview.setRenderHint(QPainter.Antialiasing)
        self.mainArea.layout().addWidget(self.plotview)
        self.ploti = pg.PlotItem(
            enableMenu=False, enableMouse=False,
            axisItems={"bottom": ElidedLabelsAxis("bottom")})
        self.plot = self.ploti.vb
        self.plot.setMouseEnabled(False, False)
        self.ploti.hideButtons()
        self.plotview.setCentralItem(self.ploti)

        self.plot_pdf = add_new_plot(10)
        self.plot_mark = add_new_plot(-10)
        self.plot_mark.setYRange(0, 1)
        self.ploti.vb.sigResized.connect(self.update_views)
        self.update_views()

        pen = QPen(self.palette().color(QPalette.Text))
        self.ploti.getAxis("bottom").setPen(pen)
        left = self.ploti.getAxis("left")
        left.setPen(pen)
        left.setStyle(stopAxisAtTick=(True, True))

    def _setup_legend(self):
        self._legend = LegendItem()
        self._legend.setParentItem(self.plot)
        self._legend.hide()
        self._legend.anchor((1, 0), (1, 0))

    # -----------------------------
    # Event and signal handlers

    def update_views(self):
        for plot in (self.plot_pdf, self.plot_mark):
            plot.setGeometry(self.plot.sceneBoundingRect())
            plot.linkedViewChanged(self.plot, plot.XAxis)

    def onDeleteWidget(self):
        self.plot.clear()
        self.plot_pdf.clear()
        self.plot_mark.clear()
        super().onDeleteWidget()

    @Inputs.data
    def set_data(self, data):
        self.closeContext()
        self.var = self.cvar = None
        self.data = data
        domain = self.data.domain if self.data else None
        varmodel = self.controls.var.model()
        cvarmodel = self.controls.cvar.model()
        varmodel.set_domain(domain)
        cvarmodel.set_domain(domain)
        if varmodel:
            self.var = varmodel[min(len(domain.class_vars), len(varmodel) - 1)]
        if domain is not None and domain.has_discrete_class:
            self.cvar = domain.class_var
        self.reset_select()
        self._user_var_bins.clear()
        self.openContext(domain)
        self.set_valid_data()
        self.recompute_binnings()
        self.replot()
        self.apply()

    def _on_var_changed(self):
        self.reset_select()
        self.set_valid_data()
        self.recompute_binnings()
        self.replot()
        self.apply()

    def _on_cvar_changed(self):
        self.set_valid_data()
        self.replot()
        self.apply()

    def _on_bins_changed(self):
        self.reset_select()
        self._set_bin_width_slider_label()
        self.replot()
        # this is triggered when dragging, so don't call apply here;
        # apply is called on sliderReleased

    def _on_bin_slider_released(self):
        self._user_var_bins[self.var] = self.number_of_bins
        self.apply()

    def _set_bin_width_slider_label(self):
        text = ""
        if self.number_of_bins < len(self.binnings):
            bins = self.binnings[self.number_of_bins]
            if len(bins) > 1:
                text = self.var.repr_val(bins[1] - bins[0])
        self.bin_width_label.setText(text)

    def _on_show_probabilities_changed(self):
        label = self.controls.fitted_distribution.label
        if self.show_probs:
            label.setText("Fitted probability")
            label.setToolTip(
                "Chosen distribution is used to compute Bayesian probabilities")
        else:
            label.setText("Fitted distribution")
            label.setToolTip("")
        self.replot()

    @property
    def is_valid(self):
        return self.valid_data is not None

    def set_valid_data(self):
        err_def_var = self.Error.no_defined_values_var
        err_def_pair = self.Error.no_defined_values_pair
        err_def_var.clear()
        err_def_pair.clear()
        self.Warning.ignored_nans.clear()

        self.valid_data = self.valid_group_data = None
        if self.var is None:
            return

        column = self.data.get_column_view(self.var)[0].astype(float)
        valid_mask = np.isfinite(column)
        if not np.any(valid_mask):
            self.Error.no_defined_values_var(self.var.name)
            return
        if self.cvar:
            ccolumn = self.data.get_column_view(self.cvar)[0].astype(float)
            valid_mask *= np.isfinite(ccolumn)
            if not np.any(valid_mask):
                self.Error.no_defined_values_pair(self.var.name, self.cvar.name)
                return
            self.valid_group_data = ccolumn[valid_mask]
        if not np.all(valid_mask):
            self.Warning.ignored_nans()
        self.valid_data = column[valid_mask]

    # -----------------------------
    # Plotting

    def replot(self):
        self._clear_plot()
        if self.is_valid:
            self._set_axis_names()
            self._update_controls_state()
            self._call_plotting()
            self._display_legend()
        self.show_selection()

    def _clear_plot(self):
        self.plot.clear()
        self.plot_pdf.clear()
        self.plot_mark.clear()
        self.bar_items = []
        self._legend.clear()
        self._legend.hide()

    def _set_axis_names(self):
        assert self.is_valid  # called only from replot, so assumes data is OK
        bottomaxis = self.ploti.getAxis("bottom")
        bottomaxis.setLabel(self.var and self.var.name)

        leftaxis = self.ploti.getAxis("left")
        if self.show_probs and self.cvar:
            leftaxis.setLabel(
                f"Probability of '{self.cvar.name}' at given '{self.var.name}'")
        else:
            leftaxis.setLabel("Frequency")
        leftaxis.resizeEvent()

    def _update_controls_state(self):
        assert self.is_valid  # called only from replot, so assumes data is OK
        self.continuous_box.setDisabled(self.var.is_discrete)
        self.controls.show_probs.setDisabled(self.cvar is None)
        self.controls.stacked_columns.setDisabled(self.cvar is None)

    def _call_plotting(self):
        assert self.is_valid  # called only from replot, so assumes data is OK
        self.curve_descriptions = None
        if self.var.is_discrete:
            if self.cvar:
                self._disc_split_plot()
            else:
                self._disc_plot()
        else:
            if self.cvar:
                self._cont_split_plot()
            else:
                self._cont_plot()
        self.plot.autoRange()

    def _add_bar(self, x, width, padding, freqs, colors, stacked, expanded,
                 tooltip):
        item = DistributionBarItem(
            x, width, padding, freqs, colors, stacked, expanded, tooltip)
        self.plot.addItem(item)
        self.bar_items.append(item)

    def _disc_plot(self):
        var = self.var
        self.ploti.getAxis("bottom").setTicks([list(enumerate(var.values))])
        colors = [QColor(0, 128, 255)]
        dist = distribution.get_distribution(self.data, self.var)
        for i, freq in enumerate(dist):
            tooltip = \
                "<p style='white-space:pre;'>" \
                f"<b>{escape(var.values[i])}</b>: {int(freq)} " \
                f"({100 * freq / len(self.valid_data):.2f} %) "
            self._add_bar(
                i - 0.5, 1, 0.1, [freq], colors,
                stacked=False, expanded=False, tooltip=tooltip)

    def _disc_split_plot(self):
        var = self.var
        self.ploti.getAxis("bottom").setTicks([list(enumerate(var.values))])
        gcolors = [QColor(*col) for col in self.cvar.colors]
        gvalues = self.cvar.values
        conts = contingency.get_contingency(self.data, self.cvar, self.var)
        total = len(self.data)
        for i, freqs in enumerate(conts):
            self._add_bar(
                i - 0.5, 1, 0.1, freqs, gcolors,
                stacked=self.stacked_columns, expanded=self.show_probs,
                tooltip=self._split_tooltip(
                    var.values[i], np.sum(freqs), total, gvalues, freqs))

    def _cont_plot(self):
        self.ploti.getAxis("bottom").setTicks(None)
        data = self.valid_data
        y, x = np.histogram(data, bins=self.binnings[self.number_of_bins])
        total = len(data)
        colors = [QColor(0, 128, 255)]
        if self.fitted_distribution:
            colors[0] = colors[0].lighter(130)

        tot_freq = 0
        lasti = len(y) - 1
        for i, (x0, x1), freq in zip(count(), zip(x, x[1:]), y):
            tot_freq += freq
            tooltip = \
                "<p style='white-space:pre;'>" \
                f"<b>{escape(self.str_int(x0, x1, not i, i == lasti))}</b>: " \
                f"{freq} ({100 * freq / total:.2f} %)</p>"
            self._add_bar(
                x0, x1 - x0, 0, [tot_freq if self.cumulative_distr else freq],
                colors, stacked=False, expanded=False, tooltip=tooltip)

        if self.fitted_distribution:
            self._plot_approximations(
                x[0], x[-1], [self._fit_approximation(data)],
                [QColor(0, 0, 0)], (1,))

    def _cont_split_plot(self):
        self.ploti.getAxis("bottom").setTicks(None)
        data = self.valid_data
        _, bins = np.histogram(data, bins=self.binnings[self.number_of_bins])
        gvalues = self.cvar.values
        varcolors = [QColor(*col) for col in self.cvar.colors]
        if self.fitted_distribution:
            gcolors = [c.lighter(130) for c in varcolors]
        else:
            gcolors = varcolors
        nvalues = len(gvalues)
        ys = []
        fitters = []
        prior_sizes = []
        for val_idx in range(nvalues):
            group_data = data[self.valid_group_data == val_idx]
            prior_sizes.append(len(group_data))
            ys.append(np.histogram(group_data, bins)[0])
            if self.fitted_distribution:
                fitters.append(self._fit_approximation(group_data))
        total = len(data)
        prior_sizes = np.array(prior_sizes)
        tot_freqs = np.zeros(len(ys))

        lasti = len(ys[0]) - 1
        for i, x0, x1, freqs in zip(count(), bins, bins[1:], zip(*ys)):
            tot_freqs += freqs
            plotfreqs = tot_freqs.copy() if self.cumulative_distr else freqs
            self._add_bar(
                x0, x1 - x0, 0 if self.stacked_columns else 0.1, plotfreqs,
                gcolors, stacked=self.stacked_columns, expanded=self.show_probs,
                tooltip=self._split_tooltip(
                    self.str_int(x0, x1, not i, i == lasti),
                    np.sum(plotfreqs), total, gvalues, plotfreqs))

        if fitters:
            self._plot_approximations(bins[0], bins[-1], fitters, varcolors,
                                      prior_sizes / len(data))

    def _fit_approximation(self, y):
        def join_pars(pairs):
            strv = self.var.str_val
            return ", ".join(f"{sname}={strv(val)}" for sname, val in pairs)

        def str_params():
            s = join_pars(
                (sname, val) for sname, val in zip(str_names, fitted)
                if sname[0] != "-")
            par = join_pars(
                (sname[1:], val) for sname, val in zip(str_names, fitted)
                if sname[0] == "-")
            if par:
                s += f" ({par})"
            return s

        _, dist, names, str_names = self.Fitters[self.fitted_distribution]
        fitted = dist.fit(y)
        params = {name: val for name, val in zip(names, fitted)}
        return partial(dist.pdf, **params), str_params()

    def _plot_approximations(self, x0, x1, fitters, colors, prior_probs=0):
        x = np.linspace(x0, x1, 100)
        ys = np.empty((len(fitters), 100))
        self.curve_descriptions = [s for _, s in fitters]
        for y, (fitter, _), color in zip(ys, fitters, colors):
            y[:] = fitter(x)
            if self.cumulative_distr:
                y[:] = np.cumsum(y)
        tots = np.sum(ys, axis=0)

        show_probs = self.show_probs and self.cvar is not None
        plot = self.ploti if show_probs else self.plot_pdf

        for y, prior_prob, color in zip(ys, prior_probs, colors):
            if show_probs:
                y_p = y * prior_prob
                y = y_p / (y_p + (tots - y) * (1 - prior_prob))
            plot.addItem(pg.PlotCurveItem(
                x=x, y=y,
                pen=pg.mkPen(width=5, color=color),
                shadowPen=pg.mkPen(width=8, color=color.darker(120))))
        if not show_probs:
            self.plot_pdf.autoRange()

    @staticmethod
    def _split_tooltip(valname, tot_group, total, gvalues, freqs):
        div_group = tot_group or 1
        cs = "white-space:pre; text-align: right;"
        s = f"style='{cs} padding-left: 1em'"
        snp = f"style='{cs}'"
        return f"<table style='border-collapse: collapse'>" \
               f"<tr><th {s}>{escape(valname)}:</th>" \
               f"<td {snp}><b>{int(tot_group)}</b></td>" \
               "<td/>" \
               f"<td {s}><b>{100 * tot_group / total:.2f} %</b></td></tr>" + \
               f"<tr><td/><td/><td {s}>(in group)</td><td {s}>(overall)</td>" \
               "</tr>" + \
               "".join(
                   "<tr>"
                   f"<th {s}>{value}:</th>"
                   f"<td {snp}><b>{int(freq)}</b></td>"
                   f"<td {s}>{100 * freq / div_group:.2f} %</td>"
                   f"<td {s}>{100 * freq / total:.2f} %</td>"
                   "</tr>"
                   for value, freq in zip(gvalues, freqs)) + \
               "</table>"

    def _display_legend(self):
        assert self.is_valid  # called only from replot, so assumes data is OK
        if self.cvar is None:
            if not self.curve_descriptions:
                self._legend.hide()
                return
            self._legend.addItem(
                pg.PlotCurveItem(pen=pg.mkPen(width=5, color=0.0)),
                self.curve_descriptions[0])
        else:
            cvar_values = self.cvar.values
            colors = [QColor(*col) for col in self.cvar.colors]
            descriptions = self.curve_descriptions or repeat(None)
            for color, name, desc in zip(colors, cvar_values, descriptions):
                self._legend.addItem(
                    ScatterPlotItem(pen=color, brush=color, size=10, shape="s"),
                    escape(name + (f" ({desc})" if desc else "")))
        self._legend.show()

    # -----------------------------
    # Bins

    def recompute_binnings(self):
        self.binnings = []
        max_bins = 0
        if self.is_valid and self.var.is_continuous:
            # binning is computed on valid var data, ignoring any cvar nans
            column = self.data.get_column_view(self.var)[0].astype(float)
            if np.any(np.isfinite(column)):
                self.binnings = decimal_binnings(
                    column, min_width=self.min_var_resolution(self.var),
                    add_unique=10, min_unique=5)
                max_bins = len(self.binnings) - 1

        self.controls.number_of_bins.setMaximum(max_bins)
        self.number_of_bins = min(
            max_bins, self._user_var_bins.get(self.var, self.number_of_bins))
        self._set_bin_width_slider_label()

    @staticmethod
    def min_var_resolution(var):
        # pylint: disable=unidiomatic-typecheck
        if type(var) is not ContinuousVariable:
            return 0
        return 10 ** -var.number_of_decimals

    def str_int(self, x0, x1, first, last):
        var = self.var
        sx0, sx1 = var.repr_val(x0), var.repr_val(x1)
        if self.cumulative_distr:
            return f"{var.name} < {sx1}"
        elif first and last:
            return f"{var.name} = {sx0}"
        elif first:
            return f"{var.name} < {sx1}"
        elif last:
            return f"{var.name} ≥ {sx0}"
        elif sx0 == sx1 or x1 - x0 <= self.min_var_resolution(var):
            return f"{var.name} = {sx0}"
        else:
            return f"{sx0} ≤ {var.name} < {sx1}"

    # -----------------------------
    # Selection

    def _on_item_clicked(self, item, modifiers, drag):
        def add_or_remove(idx, add):
            self.drag_operation = [self.DragRemove, self.DragAdd][add]
            if add:
                self.selection.add(idx)
            else:
                if idx in self.selection:
                    # This can be False when removing with dragging and the
                    # mouse crosses unselected items
                    self.selection.remove(idx)

        def add_range(add):
            if self.last_click_idx is None:
                add = True
                idx_range = {idx}
            else:
                from_idx, to_idx = sorted((self.last_click_idx, idx))
                idx_range = set(range(from_idx, to_idx + 1))
            self.drag_operation = [self.DragRemove, self.DragAdd][add]
            if add:
                self.selection |= idx_range
            else:
                self.selection -= idx_range

        self.key_operation = None
        if item is None:
            self.reset_select()
            return

        idx = self.bar_items.index(item)
        if drag:
            # Dragging has to add a range, otherwise fast dragging skips bars
            add_range(self.drag_operation == self.DragAdd)
        else:
            if modifiers & Qt.ShiftModifier:
                add_range(self.drag_operation == self.DragAdd)
            elif modifiers & Qt.ControlModifier:
                add_or_remove(idx, add=idx not in self.selection)
            else:
                if self.selection == {idx}:
                    # Clicking on a single selected bar  deselects it,
                    # but dragging from here will select
                    add_or_remove(idx, add=False)
                    self.drag_operation = self.DragAdd
                else:
                    self.selection.clear()
                    add_or_remove(idx, add=True)
        self.last_click_idx = idx

        self.show_selection()

    def _on_blank_clicked(self):
        self.reset_select()

    def reset_select(self):
        self.selection.clear()
        self.last_click_idx = None
        self.drag_operation = None
        self.key_operation = None
        self.show_selection()

    def _on_end_selecting(self):
        self.apply()

    def show_selection(self):
        self.plot_mark.clear()
        if not self.is_valid:  # though if it's not, selection is empty anyway
            return

        blue = QColor(Qt.blue)
        pen = QPen(QBrush(blue), 3)
        pen.setCosmetic(True)
        brush = QBrush(blue.lighter(190))

        for group in self.grouped_selection():
            group = list(group)
            left_idx, right_idx = group[0], group[-1]
            left_pad, right_pad = self._determine_padding(left_idx, right_idx)
            x0 = self.bar_items[left_idx].x0 - left_pad
            x1 = self.bar_items[right_idx].x1 + right_pad
            item = QGraphicsRectItem(x0, 0, x1 - x0, 1)
            item.setPen(pen)
            item.setBrush(brush)
            if self.var.is_continuous:
                valname = self.str_int(
                    x0, x1, not left_idx, right_idx == len(self.bar_items) - 1)
                inside = sum(np.sum(self.bar_items[i].freqs) for i in group)
                total = len(self.valid_data)
                item.setToolTip(
                    "<p style='white-space:pre;'>"
                    f"<b>{escape(valname)}</b>: "
                    f"{inside} ({100 * inside / total:.2f} %)")
            self.plot_mark.addItem(item)

    def _determine_padding(self, left_idx, right_idx):
        def _padding(i):
            return (self.bar_items[i + 1].x0 - self.bar_items[i].x1) / 2

        if len(self.bar_items) == 1:
            return 6, 6
        if left_idx == 0 and right_idx == len(self.bar_items) - 1:
            return (_padding(0), ) * 2

        if left_idx > 0:
            left_pad = _padding(left_idx - 1)
        if right_idx < len(self.bar_items) - 1:
            right_pad = _padding(right_idx)
        else:
            right_pad = left_pad
        if left_idx == 0:
            left_pad = right_pad
        return left_pad, right_pad

    def grouped_selection(self):
        return [[g[1] for g in group]
                for _, group in groupby(enumerate(sorted(self.selection)),
                                        key=lambda x: x[1] - x[0])]

    def keyPressEvent(self, e):
        def on_nothing_selected():
            if e.key() == Qt.Key_Left:
                self.last_click_idx = len(self.bar_items) - 1
            else:
                self.last_click_idx = 0
            self.selection.add(self.last_click_idx)

        def on_key_left():
            if e.modifiers() & Qt.ShiftModifier:
                if self.key_operation == Qt.Key_Right and first != last:
                    self.selection.remove(last)
                    self.last_click_idx = last - 1
                elif first:
                    self.key_operation = Qt.Key_Left
                    self.selection.add(first - 1)
                    self.last_click_idx = first - 1
            else:
                self.selection.clear()
                self.last_click_idx = max(first - 1, 0)
                self.selection.add(self.last_click_idx)

        def on_key_right():
            if e.modifiers() & Qt.ShiftModifier:
                if self.key_operation == Qt.Key_Left and first != last:
                    self.selection.remove(first)
                    self.last_click_idx = first + 1
                elif not self._is_last_bar(last):
                    self.key_operation = Qt.Key_Right
                    self.selection.add(last + 1)
                    self.last_click_idx = last + 1
            else:
                self.selection.clear()
                self.last_click_idx = min(last + 1, len(self.bar_items) - 1)
                self.selection.add(self.last_click_idx)

        if not self.is_valid or not self.bar_items \
                or e.key() not in (Qt.Key_Left, Qt.Key_Right):
            super().keyPressEvent(e)
            return

        prev_selection = self.selection.copy()
        if not self.selection:
            on_nothing_selected()
        else:
            first, last = min(self.selection), max(self.selection)
            if e.key() == Qt.Key_Left:
                on_key_left()
            else:
                on_key_right()

        if self.selection != prev_selection:
            self.drag_operation = self.DragAdd
            self.show_selection()
            self.apply()

    def keyReleaseEvent(self, ev):
        if ev.key() == Qt.Key_Shift:
            self.key_operation = None
        super().keyReleaseEvent(ev)


    # -----------------------------
    # Output

    def apply(self):
        data = self.data
        selected_data = annotated_data = histogram_data = None
        if self.is_valid:
            if self.var.is_discrete:
                group_indices, values = self._get_output_indices_disc()
            else:
                group_indices, values = self._get_output_indices_cont()
                hist_indices, hist_values = self._get_histogram_indices()
                histogram_data = create_groups_table(
                    data, hist_indices, values=hist_values)
            selected = np.nonzero(group_indices)[0]
            if selected.size:
                selected_data = create_groups_table(
                    data, group_indices,
                    include_unselected=False, values=values)
                annotated_data = create_annotated_table(data, selected)

        self.Outputs.selected_data.send(selected_data)
        self.Outputs.annotated_data.send(annotated_data)
        self.Outputs.histogram_data.send(histogram_data)

    def _get_output_indices_disc(self):
        group_indices = np.zeros(len(self.data), dtype=np.int32)
        col = self.data.get_column_view(self.var)[0].astype(float)
        for group_idx, val_idx in enumerate(self.selection, start=1):
            group_indices[col == val_idx] = group_idx
        values = [self.var.values[i] for i in self.selection]
        return group_indices, values

    def _get_output_indices_cont(self):
        group_indices = np.zeros(len(self.data), dtype=np.int32)
        col = self.data.get_column_view(self.var)[0].astype(float)
        values = []
        for group_idx, group in enumerate(self.grouped_selection(), start=1):
            x0 = x1 = None
            for bar_idx in group:
                minx, maxx, mask = self._get_cont_baritem_indices(col, bar_idx)
                if x0 is None:
                    x0 = minx
                x1 = maxx
                group_indices[mask] = group_idx
            # pylint: disable=undefined-loop-variable
            values.append(
                self.str_int(x0, x1, not bar_idx, self._is_last_bar(bar_idx)))
        return group_indices, values

    def _get_histogram_indices(self):
        group_indices = np.zeros(len(self.data), dtype=np.int32)
        col = self.data.get_column_view(self.var)[0].astype(float)
        values = []
        for bar_idx in range(len(self.bar_items)):
            x0, x1, mask = self._get_cont_baritem_indices(col, bar_idx)
            group_indices[mask] = bar_idx + 1
            values.append(
                self.str_int(x0, x1, not bar_idx, self._is_last_bar(bar_idx)))
        return group_indices, values

    def _get_cont_baritem_indices(self, col, bar_idx):
        bar_item = self.bar_items[bar_idx]
        minx = bar_item.x0
        maxx = bar_item.x1 + (bar_idx == len(self.bar_items) - 1)
        with np.errstate(invalid="ignore"):
            return minx, maxx, (col >= minx) * (col < maxx)

    def _is_last_bar(self, idx):
        return idx == len(self.bar_items) - 1

    # -----------------------------
    # Report

    def get_widget_name_extension(self):
        return self.var

    def send_report(self):
        self.plotview.scene().setSceneRect(self.plotview.sceneRect())
        if not self.is_valid:
            return
        self.report_plot()
        if self.cumulative_distr:
            text = f"Cummulative distribution of '{self.var.name}'"
        else:
            text = f"Distribution of '{self.var.name}'"
        if self.cvar:
            text += f" with columns split by '{self.cvar.name}'"
        self.report_caption(text)


if __name__ == "__main__":  # pragma: no cover
    WidgetPreview(OWDistributions).run(Table("heart_disease.tab"))

```
--- END FILE ---

Please first localize the bug based on the issue statement, and then generate *SEARCH/REPLACE* edits to fix the issue.

Every *SEARCH/REPLACE* edit must use this format:
1. The file path
2. The start of search block: <<<<<<< SEARCH
3. A contiguous chunk of lines to search for in the existing source code
4. The dividing line: =======
5. The lines to replace into the source code
6. The end of the replace block: >>>>>>> REPLACE

Here is an example:

```python
### mathweb/flask/app.py
<<<<<<< SEARCH
from flask import Flask
=======
import math
from flask import Flask
>>>>>>> REPLACE
```
</solution>

Please note that the *SEARCH/REPLACE* edit REQUIRES PROPER INDENTATION. If you would like to add the line '        print(x)', you must fully write that out, with all those spaces before the code!
Wrap each *SEARCH/REPLACE* edit in a code block as shown in the example above. If you have multiple *SEARCH/REPLACE* edits, use a separate code block for each one.
user