gurudesh/pytracebugs huggingface dataset:
# Buggy code
def _range_filter_to_indicator(filter, col, fmin, fmax):
    if filter.oper == filter.Equal:
        return col == fmin
    if filter.oper == filter.NotEqual:
        return col != fmin
    if filter.oper == filter.Less:
        return col < fmin
    if filter.oper == filter.LessEqual:
        return col <= fmin
    if filter.oper == filter.Greater:
        return col > fmin
    if filter.oper == filter.GreaterEqual:
        return col >= fmin
    if filter.oper == filter.Between:
        return (col >= fmin) * (col <= fmax)
    if filter.oper == filter.Outside:
        return (col < fmin) + (col > fmax)

    raise TypeError("Invalid operator")


# Traceback (TypeError)
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "<string>", line 10, in <module>
File "C:\Users\reads\AppData\Local\Continuum\miniconda3\envs\orange-spectroscopy\lib\site-packages\Orange\data\filter.py", line 64, in __call__
return data._filter_is_defined(self.columns, self.negate)
File "C:\Users\reads\AppData\Local\Continuum\miniconda3\envs\orange-spectroscopy\lib\site-packages\Orange\data\table.py", line 1141, in _filter_is_defined
remove = np.logical_or(remove, bn.anynan([col], axis=0))
File "C:\Users\reads\AppData\Local\Continuum\miniconda3\envs\orange-spectroscopy\lib\site-packages\bottleneck\slow\reduce.py", line 86, in anynan
return np.isnan(a).any(axis)
TypeError: ufunc 'isnan' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''

# Fixed code
def _range_filter_to_indicator(filter, col, fmin, fmax):
    with np.errstate(invalid="ignore"):  # nan's are properly discarded
        if filter.oper == filter.Equal:
            return col == fmin
        if filter.oper == filter.NotEqual:
            return col != fmin
        if filter.oper == filter.Less:
            return col < fmin
        if filter.oper == filter.LessEqual:
            return col <= fmin
        if filter.oper == filter.Greater:
            return col > fmin
        if filter.oper == filter.GreaterEqual:
            return col >= fmin
        if filter.oper == filter.Between:
            return (col >= fmin) * (col <= fmax)
        if filter.oper == filter.Outside:
            return (col < fmin) + (col > fmax)

        raise TypeError("Invalid operator")
# Buggy code
def _visible_variables(domain):
    """Generate variables in order they should be presented in in combos."""
    return filter_visible(chain(domain.class_vars, domain.metas, domain.attributes))


# Traceback (TypeError)
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "<string>", line 10, in <module>
File "C:\Users\reads\AppData\Local\Continuum\miniconda3\envs\orange-spectroscopy\lib\site-packages\Orange\data\filter.py", line 64, in __call__
return data._filter_is_defined(self.columns, self.negate)
File "C:\Users\reads\AppData\Local\Continuum\miniconda3\envs\orange-spectroscopy\lib\site-packages\Orange\data\table.py", line 1141, in _filter_is_defined
remove = np.logical_or(remove, bn.anynan([col], axis=0))
File "C:\Users\reads\AppData\Local\Continuum\miniconda3\envs\orange-spectroscopy\lib\site-packages\bottleneck\slow\reduce.py", line 86, in anynan
return np.isnan(a).any(axis)
TypeError: ufunc 'isnan' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''

# Fixed code
def _visible_variables(cls, domain):
    """Generate variables in order they should be presented in in combos."""
    return chain(
        cls.AllTypes,
        filter_visible(chain(domain.class_vars, domain.metas, domain.attributes)),
    )
# Buggy code
def set_new_operators(
    self, attr_combo, adding_all, selected_index=None, selected_values=None
):
    oper_combo = QComboBox()
    oper_combo.row = attr_combo.row
    oper_combo.attr_combo = attr_combo
    var = self.data.domain[attr_combo.currentText()]
    oper_combo.addItems(self.operator_names[type(var)])
    oper_combo.setCurrentIndex(selected_index or 0)
    self.cond_list.setCellWidget(oper_combo.row, 1, oper_combo)
    self.set_new_values(oper_combo, adding_all, selected_values)
    oper_combo.currentIndexChanged.connect(
        lambda _: self.set_new_values(oper_combo, False)
    )


# Traceback (TypeError)
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "<string>", line 10, in <module>
File "C:\Users\reads\AppData\Local\Continuum\miniconda3\envs\orange-spectroscopy\lib\site-packages\Orange\data\filter.py", line 64, in __call__
return data._filter_is_defined(self.columns, self.negate)
File "C:\Users\reads\AppData\Local\Continuum\miniconda3\envs\orange-spectroscopy\lib\site-packages\Orange\data\table.py", line 1141, in _filter_is_defined
remove = np.logical_or(remove, bn.anynan([col], axis=0))
File "C:\Users\reads\AppData\Local\Continuum\miniconda3\envs\orange-spectroscopy\lib\site-packages\bottleneck\slow\reduce.py", line 86, in anynan
return np.isnan(a).any(axis)
TypeError: ufunc 'isnan' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''

# Fixed code
def set_new_operators(
    self, attr_combo, adding_all, selected_index=None, selected_values=None
):
    oper_combo = QComboBox()
    oper_combo.row = attr_combo.row
    oper_combo.attr_combo = attr_combo
    attr_name = attr_combo.currentText()
    if attr_name in self.AllTypes:
        oper_combo.addItems(self.operator_names[attr_name])
    else:
        var = self.data.domain[attr_name]
        oper_combo.addItems(self.operator_names[type(var)])
    oper_combo.setCurrentIndex(selected_index or 0)
    self.cond_list.setCellWidget(oper_combo.row, 1, oper_combo)
    self.set_new_values(oper_combo, adding_all, selected_values)
    oper_combo.currentIndexChanged.connect(
        lambda _: self.set_new_values(oper_combo, False)
    )
# Buggy code
def set_data(self, data):
    self.closeContext()
    self.data = data
    self.cb_pa.setEnabled(not isinstance(data, SqlTable))
    self.cb_pc.setEnabled(not isinstance(data, SqlTable))
    self.remove_all_rows()
    self.add_button.setDisabled(data is None)
    self.add_all_button.setDisabled(
        data is None or len(data.domain.variables) + len(data.domain.metas) > 100
    )
    if not data:
        self.data_desc = None
        self.commit()
        return
    self.data_desc = report.describe_data_brief(data)
    self.conditions = []
    try:
        self.openContext(data)
    except Exception:
        pass

    variables = list(self._visible_variables(self.data.domain))
    varnames = [v.name for v in variables]
    if self.conditions:
        for attr, cond_type, cond_value in self.conditions:
            if attr in varnames:
                self.add_row(varnames.index(attr), cond_type, cond_value)
    elif variables:
        self.add_row()

    self.update_info(data, self.data_in_variables, "In: ")
    self.unconditional_commit()


# Traceback (TypeError)
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "<string>", line 10, in <module>
File "C:\Users\reads\AppData\Local\Continuum\miniconda3\envs\orange-spectroscopy\lib\site-packages\Orange\data\filter.py", line 64, in __call__
return data._filter_is_defined(self.columns, self.negate)
File "C:\Users\reads\AppData\Local\Continuum\miniconda3\envs\orange-spectroscopy\lib\site-packages\Orange\data\table.py", line 1141, in _filter_is_defined
remove = np.logical_or(remove, bn.anynan([col], axis=0))
File "C:\Users\reads\AppData\Local\Continuum\miniconda3\envs\orange-spectroscopy\lib\site-packages\bottleneck\slow\reduce.py", line 86, in anynan
return np.isnan(a).any(axis)
TypeError: ufunc 'isnan' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''

# Fixed code
def set_data(self, data):
    self.closeContext()
    self.data = data
    self.cb_pa.setEnabled(not isinstance(data, SqlTable))
    self.cb_pc.setEnabled(not isinstance(data, SqlTable))
    self.remove_all_rows()
    self.add_button.setDisabled(data is None)
    self.add_all_button.setDisabled(
        data is None or len(data.domain.variables) + len(data.domain.metas) > 100
    )
    if not data:
        self.data_desc = None
        self.commit()
        return
    self.data_desc = report.describe_data_brief(data)
    self.conditions = []
    try:
        self.openContext(data)
    except Exception:
        pass

    variables = list(self._visible_variables(self.data.domain))
    varnames = [v.name if isinstance(v, Variable) else v for v in variables]
    if self.conditions:
        for attr, cond_type, cond_value in self.conditions:
            if attr in varnames:
                self.add_row(varnames.index(attr), cond_type, cond_value)
            elif attr in self.AllTypes:
                self.add_row(attr, cond_type, cond_value)
    else:
        self.add_row()

    self.update_info(data, self.data_in_variables, "In: ")
    self.unconditional_commit()
# Buggy code
def __call__(self, data, attribute, fixed=None):
    if fixed:
        min, max = fixed[attribute.name]
        points = self._split_eq_width(min, max)
    else:
        if type(data) == SqlTable:
            stats = BasicStats(data, attribute)
            points = self._split_eq_width(stats.min, stats.max)
        else:
            values = data[:, attribute]
            values = values.X if values.X.size else values.Y
            min, max = np.nanmin(values), np.nanmax(values)
            points = self._split_eq_width(min, max)
    return Discretizer.create_discretized_var(data.domain[attribute], points)


# Traceback (TypeError)
----------------------------- TypeError Exception -----------------------------
Traceback (most recent call last):
File "/Users/ajda/orange/orange3/Orange/widgets/gui.py", line 2316, in __call__
self.func(**kwds)
File "/Users/ajda/orange/orange3/Orange/widgets/visualize/owdistributions.py", line 644, in _on_groupvar_idx_changed
self._setup()
File "/Users/ajda/orange/orange3/Orange/widgets/visualize/owdistributions.py", line 372, in _setup
data = Discretize(method=disc, remove_const=False)(data)
File "/Users/ajda/orange/orange3/Orange/preprocess/preprocess.py", line 113, in __call__
discretized(data.domain.attributes, True),
File "/Users/ajda/orange/orange3/Orange/preprocess/preprocess.py", line 108, in discretized
vars = [var for var in vars if var is not None]
File "/Users/ajda/orange/orange3/Orange/preprocess/preprocess.py", line 108, in <listcomp>
vars = [var for var in vars if var is not None]
File "/Users/ajda/orange/orange3/Orange/preprocess/preprocess.py", line 107, in <genexpr>
vars = (transform(var) for var in vars)
File "/Users/ajda/orange/orange3/Orange/preprocess/preprocess.py", line 96, in transform
new_var = method(data, var)
File "/Users/ajda/orange/orange3/Orange/preprocess/discretize.py", line 166, in __call__
points = self._split_eq_width(min, max)
File "/Users/ajda/orange/orange3/Orange/preprocess/discretize.py", line 171, in _split_eq_width
if np.isnan(min) or np.isnan(max) or min == max:
TypeError: ufunc 'isnan' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''
-------------------------------------------------------------------------------

# Fixed code
def __call__(self, data, attribute, fixed=None):
    if fixed:
        min, max = fixed[attribute.name]
        points = self._split_eq_width(min, max)
    else:
        if type(data) == SqlTable:
            stats = BasicStats(data, attribute)
            points = self._split_eq_width(stats.min, stats.max)
        else:
            values = data[:, attribute]
            values = values.X if values.X.size else values.Y
            min, max = ut.nanmin(values), ut.nanmax(values)
            points = self._split_eq_width(min, max)
    return Discretizer.create_discretized_var(data.domain[attribute], points)
# Buggy code
def attribute(self, node):
    feature_idx = self.splitting_attribute(node)
    if feature_idx != self.FEATURE_UNDEFINED:
        return self.domain.attributes[self.splitting_attribute(node)]


# Traceback (IndexError)
Traceback (most recent call last):
File "/home/pavlin/dev/orange3/Orange/widgets/visualize/owpythagorastree.py", line 309, in commit
data = self.tree_adapter.get_instances_in_nodes(nodes)
File "/home/pavlin/dev/orange3/Orange/widgets/visualize/utils/tree/skltreeadapter.py", line 260, in get_instances_in_nodes
leaf_samples = self.get_samples_in_leaves()
File "/home/pavlin/dev/orange3/Orange/widgets/visualize/utils/tree/skltreeadapter.py", line 243, in get_samples_in_leaves
leaf_indices = assign(0, items)
File "/home/pavlin/dev/orange3/Orange/widgets/visualize/utils/tree/skltreeadapter.py", line 229, in assign
column = self.instances.X[indices, feature_idx]
IndexError: index 10 is out of bounds for axis 1 with size 9

# Fixed code
def attribute(self, node):
    feature_idx = self.splitting_attribute(node)
    if feature_idx == self.FEATURE_UNDEFINED:
        return None
    return self.domain.attributes[self.splitting_attribute(node)]
# Buggy code
def assign(node_id, indices):
    if self._tree.children_left[node_id] == self.NO_CHILD:
        return [indices]
    else:
        feature_idx = self._tree.feature[node_id]
        thresh = self._tree.threshold[node_id]

        column = self.instances.X[indices, feature_idx]
        leftmask = column <= thresh
        leftind = assign(self._tree.children_left[node_id], indices[leftmask])
        rightind = assign(self._tree.children_right[node_id], indices[~leftmask])
        return list.__iadd__(leftind, rightind)


# Traceback (IndexError)
Traceback (most recent call last):
File "/home/pavlin/dev/orange3/Orange/widgets/visualize/owpythagorastree.py", line 309, in commit
data = self.tree_adapter.get_instances_in_nodes(nodes)
File "/home/pavlin/dev/orange3/Orange/widgets/visualize/utils/tree/skltreeadapter.py", line 260, in get_instances_in_nodes
leaf_samples = self.get_samples_in_leaves()
File "/home/pavlin/dev/orange3/Orange/widgets/visualize/utils/tree/skltreeadapter.py", line 243, in get_samples_in_leaves
leaf_indices = assign(0, items)
File "/home/pavlin/dev/orange3/Orange/widgets/visualize/utils/tree/skltreeadapter.py", line 229, in assign
column = self.instances.X[indices, feature_idx]
IndexError: index 10 is out of bounds for axis 1 with size 9

# Fixed code
def assign(node_id, indices):
    if self._tree.children_left[node_id] == self.NO_CHILD:
        return [indices]
    else:
        feature_idx = self._tree.feature[node_id]
        thresh = self._tree.threshold[node_id]

        column = self.instances_transformed.X[indices, feature_idx]
        leftmask = column <= thresh
        leftind = assign(self._tree.children_left[node_id], indices[leftmask])
        rightind = assign(self._tree.children_right[node_id], indices[~leftmask])
        return list.__iadd__(leftind, rightind)
# Buggy code
def __init__(self, model):
    self.model = model
    self.domain = model.domain
    self.instances = model.instances


# Traceback (IndexError)
Traceback (most recent call last):
File "/home/pavlin/dev/orange3/Orange/widgets/visualize/owpythagorastree.py", line 309, in commit
data = self.tree_adapter.get_instances_in_nodes(nodes)
File "/home/pavlin/dev/orange3/Orange/widgets/visualize/utils/tree/skltreeadapter.py", line 260, in get_instances_in_nodes
leaf_samples = self.get_samples_in_leaves()
File "/home/pavlin/dev/orange3/Orange/widgets/visualize/utils/tree/skltreeadapter.py", line 243, in get_samples_in_leaves
leaf_indices = assign(0, items)
File "/home/pavlin/dev/orange3/Orange/widgets/visualize/utils/tree/skltreeadapter.py", line 229, in assign
column = self.instances.X[indices, feature_idx]
IndexError: index 10 is out of bounds for axis 1 with size 9

# Fixed code
def __init__(self, model):
    self.model = model
    self.domain = model.domain
    self.instances = model.instances
    self.instances_transformed = self.instances.transform(self.domain)
# Buggy code
def weight(self, node):
    """Get the weight of the given node.

    The weights of the children always sum up to 1.

    Parameters
    ----------
    node : object
        The label of the node.

    Returns
    -------
    float
        The weight of the node relative to its siblings.

    """
    pass


# Traceback (IndexError)
Traceback (most recent call last):
File "/home/pavlin/dev/orange3/Orange/widgets/visualize/owpythagorastree.py", line 309, in commit
data = self.tree_adapter.get_instances_in_nodes(nodes)
File "/home/pavlin/dev/orange3/Orange/widgets/visualize/utils/tree/skltreeadapter.py", line 260, in get_instances_in_nodes
leaf_samples = self.get_samples_in_leaves()
File "/home/pavlin/dev/orange3/Orange/widgets/visualize/utils/tree/skltreeadapter.py", line 243, in get_samples_in_leaves
leaf_indices = assign(0, items)
File "/home/pavlin/dev/orange3/Orange/widgets/visualize/utils/tree/skltreeadapter.py", line 229, in assign
column = self.instances.X[indices, feature_idx]
IndexError: index 10 is out of bounds for axis 1 with size 9

# Fixed code
def weight(self, node):
    """Get the weight of the given node.

    The weights of the children always sum up to 1.

    Parameters
    ----------
    node : object
        The label of the node.

    Returns
    -------
    float
        The weight of the node relative to its siblings.

    """
# Buggy code
def num_samples(self, node):
    """Get the number of samples that a given node contains.

    Parameters
    ----------
    node : object
        A unique identifier of a node.

    Returns
    -------
    int

    """
    pass


# Traceback (IndexError)
Traceback (most recent call last):
File "/home/pavlin/dev/orange3/Orange/widgets/visualize/owpythagorastree.py", line 309, in commit
data = self.tree_adapter.get_instances_in_nodes(nodes)
File "/home/pavlin/dev/orange3/Orange/widgets/visualize/utils/tree/skltreeadapter.py", line 260, in get_instances_in_nodes
leaf_samples = self.get_samples_in_leaves()
File "/home/pavlin/dev/orange3/Orange/widgets/visualize/utils/tree/skltreeadapter.py", line 243, in get_samples_in_leaves
leaf_indices = assign(0, items)
File "/home/pavlin/dev/orange3/Orange/widgets/visualize/utils/tree/skltreeadapter.py", line 229, in assign
column = self.instances.X[indices, feature_idx]
IndexError: index 10 is out of bounds for axis 1 with size 9

# Fixed code
def num_samples(self, node):
    """Get the number of samples that a given node contains.

    Parameters
    ----------
    node : object
        A unique identifier of a node.

    Returns
    -------
    int

    """
# Buggy code
def parent(self, node):
    """Get the parent of a given node or ROOT_PARENT if the node is the root.

    Parameters
    ----------
    node : object

    Returns
    -------
    object

    """
    pass


# Traceback (IndexError)
Traceback (most recent call last):
File "/home/pavlin/dev/orange3/Orange/widgets/visualize/owpythagorastree.py", line 309, in commit
data = self.tree_adapter.get_instances_in_nodes(nodes)
File "/home/pavlin/dev/orange3/Orange/widgets/visualize/utils/tree/skltreeadapter.py", line 260, in get_instances_in_nodes
leaf_samples = self.get_samples_in_leaves()
File "/home/pavlin/dev/orange3/Orange/widgets/visualize/utils/tree/skltreeadapter.py", line 243, in get_samples_in_leaves
leaf_indices = assign(0, items)
File "/home/pavlin/dev/orange3/Orange/widgets/visualize/utils/tree/skltreeadapter.py", line 229, in assign
column = self.instances.X[indices, feature_idx]
IndexError: index 10 is out of bounds for axis 1 with size 9

# Fixed code
def parent(self, node):
    """Get the parent of a given node or ROOT_PARENT if the node is the root.

    Parameters
    ----------
    node : object

    Returns
    -------
    object

    """
# Buggy code
def has_children(self, node):
    """Check if the given node has any children.

    Parameters
    ----------
    node : object

    Returns
    -------
    bool

    """
    pass


# Traceback (IndexError)
Traceback (most recent call last):
File "/home/pavlin/dev/orange3/Orange/widgets/visualize/owpythagorastree.py", line 309, in commit
data = self.tree_adapter.get_instances_in_nodes(nodes)
File "/home/pavlin/dev/orange3/Orange/widgets/visualize/utils/tree/skltreeadapter.py", line 260, in get_instances_in_nodes
leaf_samples = self.get_samples_in_leaves()
File "/home/pavlin/dev/orange3/Orange/widgets/visualize/utils/tree/skltreeadapter.py", line 243, in get_samples_in_leaves
leaf_indices = assign(0, items)
File "/home/pavlin/dev/orange3/Orange/widgets/visualize/utils/tree/skltreeadapter.py", line 229, in assign
column = self.instances.X[indices, feature_idx]
IndexError: index 10 is out of bounds for axis 1 with size 9

# Fixed code
def has_children(self, node):
    """Check if the given node has any children.

    Parameters
    ----------
    node : object

    Returns
    -------
    bool

    """
# Buggy code
def children(self, node):
    """Get all the children of a given node.

    Parameters
    ----------
    node : object

    Returns
    -------
    Iterable[object]
        A iterable object containing the labels of the child nodes.

    """
    pass


# Traceback (IndexError)
Traceback (most recent call last):
File "/home/pavlin/dev/orange3/Orange/widgets/visualize/owpythagorastree.py", line 309, in commit
data = self.tree_adapter.get_instances_in_nodes(nodes)
File "/home/pavlin/dev/orange3/Orange/widgets/visualize/utils/tree/skltreeadapter.py", line 260, in get_instances_in_nodes
leaf_samples = self.get_samples_in_leaves()
File "/home/pavlin/dev/orange3/Orange/widgets/visualize/utils/tree/skltreeadapter.py", line 243, in get_samples_in_leaves
leaf_indices = assign(0, items)
File "/home/pavlin/dev/orange3/Orange/widgets/visualize/utils/tree/skltreeadapter.py", line 229, in assign
column = self.instances.X[indices, feature_idx]
IndexError: index 10 is out of bounds for axis 1 with size 9

# Fixed code
def children(self, node):
    """Get all the children of a given node.

    Parameters
    ----------
    node : object

    Returns
    -------
    Iterable[object]
        A iterable object containing the labels of the child nodes.

    """
# Buggy code
def reverse_children(self, node):
    """Reverse children of a given node.

    Parameters
    ----------
    node : object
    """
    pass


# Traceback (IndexError)
Traceback (most recent call last):
File "/home/pavlin/dev/orange3/Orange/widgets/visualize/owpythagorastree.py", line 309, in commit
data = self.tree_adapter.get_instances_in_nodes(nodes)
File "/home/pavlin/dev/orange3/Orange/widgets/visualize/utils/tree/skltreeadapter.py", line 260, in get_instances_in_nodes
leaf_samples = self.get_samples_in_leaves()
File "/home/pavlin/dev/orange3/Orange/widgets/visualize/utils/tree/skltreeadapter.py", line 243, in get_samples_in_leaves
leaf_indices = assign(0, items)
File "/home/pavlin/dev/orange3/Orange/widgets/visualize/utils/tree/skltreeadapter.py", line 229, in assign
column = self.instances.X[indices, feature_idx]
IndexError: index 10 is out of bounds for axis 1 with size 9

# Fixed code
def reverse_children(self, node):
    """Reverse children of a given node.

    Parameters
    ----------
    node : object
    """
# Buggy code
def shuffle_children(self):
    """Randomly shuffle node's children in the entire tree."""
    pass


# Traceback (IndexError)
Traceback (most recent call last):
File "/home/pavlin/dev/orange3/Orange/widgets/visualize/owpythagorastree.py", line 309, in commit
data = self.tree_adapter.get_instances_in_nodes(nodes)
File "/home/pavlin/dev/orange3/Orange/widgets/visualize/utils/tree/skltreeadapter.py", line 260, in get_instances_in_nodes
leaf_samples = self.get_samples_in_leaves()
File "/home/pavlin/dev/orange3/Orange/widgets/visualize/utils/tree/skltreeadapter.py", line 243, in get_samples_in_leaves
leaf_indices = assign(0, items)
File "/home/pavlin/dev/orange3/Orange/widgets/visualize/utils/tree/skltreeadapter.py", line 229, in assign
column = self.instances.X[indices, feature_idx]
IndexError: index 10 is out of bounds for axis 1 with size 9

# Fixed code
def shuffle_children(self):
    """Randomly shuffle node's children in the entire tree."""
# Buggy code
def get_distribution(self, node):
    """Get the distribution of types for a given node.

    This may be the number of nodes that belong to each different classe in
    a node.

    Parameters
    ----------
    node : object

    Returns
    -------
    Iterable[int, ...]
        The return type is an iterable with as many fields as there are
        different classes in the given node. The values of the fields are
        the number of nodes that belong to a given class inside the node.

    """
    pass


# Traceback (IndexError)
Traceback (most recent call last):
File "/home/pavlin/dev/orange3/Orange/widgets/visualize/owpythagorastree.py", line 309, in commit
data = self.tree_adapter.get_instances_in_nodes(nodes)
File "/home/pavlin/dev/orange3/Orange/widgets/visualize/utils/tree/skltreeadapter.py", line 260, in get_instances_in_nodes
leaf_samples = self.get_samples_in_leaves()
File "/home/pavlin/dev/orange3/Orange/widgets/visualize/utils/tree/skltreeadapter.py", line 243, in get_samples_in_leaves
leaf_indices = assign(0, items)
File "/home/pavlin/dev/orange3/Orange/widgets/visualize/utils/tree/skltreeadapter.py", line 229, in assign
column = self.instances.X[indices, feature_idx]
IndexError: index 10 is out of bounds for axis 1 with size 9

# Fixed code
def get_distribution(self, node):
    """Get the distribution of types for a given node.

    This may be the number of nodes that belong to each different classe in
    a node.

    Parameters
    ----------
    node : object

    Returns
    -------
    Iterable[int, ...]
        The return type is an iterable with as many fields as there are
        different classes in the given node. The values of the fields are
        the number of nodes that belong to a given class inside the node.

    """
# Buggy code
def get_impurity(self, node):
    """Get the impurity of a given node.

    Parameters
    ----------
    node : object

    Returns
    -------
    object

    """
    pass


# Traceback (IndexError)
Traceback (most recent call last):
File "/home/pavlin/dev/orange3/Orange/widgets/visualize/owpythagorastree.py", line 309, in commit
data = self.tree_adapter.get_instances_in_nodes(nodes)
File "/home/pavlin/dev/orange3/Orange/widgets/visualize/utils/tree/skltreeadapter.py", line 260, in get_instances_in_nodes
leaf_samples = self.get_samples_in_leaves()
File "/home/pavlin/dev/orange3/Orange/widgets/visualize/utils/tree/skltreeadapter.py", line 243, in get_samples_in_leaves
leaf_indices = assign(0, items)
File "/home/pavlin/dev/orange3/Orange/widgets/visualize/utils/tree/skltreeadapter.py", line 229, in assign
column = self.instances.X[indices, feature_idx]
IndexError: index 10 is out of bounds for axis 1 with size 9

# Fixed code
def get_impurity(self, node):
    """Get the impurity of a given node.

    Parameters
    ----------
    node : object

    Returns
    -------
    object

    """
# Buggy code
def rules(self, node):
    """Get a list of rules that define the given node.

    Parameters
    ----------
    node : object

    Returns
    -------
    Iterable[Rule]
        A list of Rule objects, can be of any type.

    """
    pass


# Traceback (IndexError)
Traceback (most recent call last):
File "/home/pavlin/dev/orange3/Orange/widgets/visualize/owpythagorastree.py", line 309, in commit
data = self.tree_adapter.get_instances_in_nodes(nodes)
File "/home/pavlin/dev/orange3/Orange/widgets/visualize/utils/tree/skltreeadapter.py", line 260, in get_instances_in_nodes
leaf_samples = self.get_samples_in_leaves()
File "/home/pavlin/dev/orange3/Orange/widgets/visualize/utils/tree/skltreeadapter.py", line 243, in get_samples_in_leaves
leaf_indices = assign(0, items)
File "/home/pavlin/dev/orange3/Orange/widgets/visualize/utils/tree/skltreeadapter.py", line 229, in assign
column = self.instances.X[indices, feature_idx]
IndexError: index 10 is out of bounds for axis 1 with size 9

# Fixed code
def rules(self, node):
    """Get a list of rules that define the given node.

    Parameters
    ----------
    node : object

    Returns
    -------
    Iterable[Rule]
        A list of Rule objects, can be of any type.

    """
# Buggy code
def attribute(self, node):
    """Get the attribute that splits the given tree.

    Parameters
    ----------
    node

    Returns
    -------

    """
    pass


# Traceback (IndexError)
Traceback (most recent call last):
File "/home/pavlin/dev/orange3/Orange/widgets/visualize/owpythagorastree.py", line 309, in commit
data = self.tree_adapter.get_instances_in_nodes(nodes)
File "/home/pavlin/dev/orange3/Orange/widgets/visualize/utils/tree/skltreeadapter.py", line 260, in get_instances_in_nodes
leaf_samples = self.get_samples_in_leaves()
File "/home/pavlin/dev/orange3/Orange/widgets/visualize/utils/tree/skltreeadapter.py", line 243, in get_samples_in_leaves
leaf_indices = assign(0, items)
File "/home/pavlin/dev/orange3/Orange/widgets/visualize/utils/tree/skltreeadapter.py", line 229, in assign
column = self.instances.X[indices, feature_idx]
IndexError: index 10 is out of bounds for axis 1 with size 9

# Fixed code
def attribute(self, node):
    """Get the attribute that splits the given tree.

    Parameters
    ----------
    node

    Returns
    -------

    """
# Buggy code
def leaves(self, node):
    """Get all the leavse that belong to the subtree of a given node.

    Parameters
    ----------
    node

    Returns
    -------

    """
    pass


# Traceback (IndexError)
Traceback (most recent call last):
File "/home/pavlin/dev/orange3/Orange/widgets/visualize/owpythagorastree.py", line 309, in commit
data = self.tree_adapter.get_instances_in_nodes(nodes)
File "/home/pavlin/dev/orange3/Orange/widgets/visualize/utils/tree/skltreeadapter.py", line 260, in get_instances_in_nodes
leaf_samples = self.get_samples_in_leaves()
File "/home/pavlin/dev/orange3/Orange/widgets/visualize/utils/tree/skltreeadapter.py", line 243, in get_samples_in_leaves
leaf_indices = assign(0, items)
File "/home/pavlin/dev/orange3/Orange/widgets/visualize/utils/tree/skltreeadapter.py", line 229, in assign
column = self.instances.X[indices, feature_idx]
IndexError: index 10 is out of bounds for axis 1 with size 9

# Fixed code
def leaves(self, node):
    """Get all the leavse that belong to the subtree of a given node.

    Parameters
    ----------
    node

    Returns
    -------

    """
# Buggy code
def get_instances_in_nodes(self, dataset, nodes):
    """Get all the instances belonging to a set of nodes for a given
    dataset.

    Parameters
    ----------
    dataset : Table
        A Orange Table dataset.
    nodes : iterable[node]
        A list of tree nodes for which we want the instances.

    Returns
    -------

    """
    pass


# Traceback (IndexError)
Traceback (most recent call last):
File "/home/pavlin/dev/orange3/Orange/widgets/visualize/owpythagorastree.py", line 309, in commit
data = self.tree_adapter.get_instances_in_nodes(nodes)
File "/home/pavlin/dev/orange3/Orange/widgets/visualize/utils/tree/skltreeadapter.py", line 260, in get_instances_in_nodes
leaf_samples = self.get_samples_in_leaves()
File "/home/pavlin/dev/orange3/Orange/widgets/visualize/utils/tree/skltreeadapter.py", line 243, in get_samples_in_leaves
leaf_indices = assign(0, items)
File "/home/pavlin/dev/orange3/Orange/widgets/visualize/utils/tree/skltreeadapter.py", line 229, in assign
column = self.instances.X[indices, feature_idx]
IndexError: index 10 is out of bounds for axis 1 with size 9

# Fixed code
def get_instances_in_nodes(self, dataset, nodes):
    """Get all the instances belonging to a set of nodes for a given
    dataset.

    Parameters
    ----------
    dataset : Table
        A Orange Table dataset.
    nodes : iterable[node]
        A list of tree nodes for which we want the instances.

    Returns
    -------

    """
# Buggy code
def max_depth(self):
    """Get the maximum depth that the tree reaches.

    Returns
    -------
    int

    """
    pass


# Traceback (IndexError)
Traceback (most recent call last):
File "/home/pavlin/dev/orange3/Orange/widgets/visualize/owpythagorastree.py", line 309, in commit
data = self.tree_adapter.get_instances_in_nodes(nodes)
File "/home/pavlin/dev/orange3/Orange/widgets/visualize/utils/tree/skltreeadapter.py", line 260, in get_instances_in_nodes
leaf_samples = self.get_samples_in_leaves()
File "/home/pavlin/dev/orange3/Orange/widgets/visualize/utils/tree/skltreeadapter.py", line 243, in get_samples_in_leaves
leaf_indices = assign(0, items)
File "/home/pavlin/dev/orange3/Orange/widgets/visualize/utils/tree/skltreeadapter.py", line 229, in assign
column = self.instances.X[indices, feature_idx]
IndexError: index 10 is out of bounds for axis 1 with size 9

# Fixed code
def max_depth(self):
    """Get the maximum depth that the tree reaches.

    Returns
    -------
    int

    """
# Buggy code
def num_nodes(self):
    """Get the total number of nodes that the tree contains.

    This does not mean the number of samples inside the entire tree, just
    the number of nodes.

    Returns
    -------
    int

    """
    pass


# Traceback (IndexError)
Traceback (most recent call last):
File "/home/pavlin/dev/orange3/Orange/widgets/visualize/owpythagorastree.py", line 309, in commit
data = self.tree_adapter.get_instances_in_nodes(nodes)
File "/home/pavlin/dev/orange3/Orange/widgets/visualize/utils/tree/skltreeadapter.py", line 260, in get_instances_in_nodes
leaf_samples = self.get_samples_in_leaves()
File "/home/pavlin/dev/orange3/Orange/widgets/visualize/utils/tree/skltreeadapter.py", line 243, in get_samples_in_leaves
leaf_indices = assign(0, items)
File "/home/pavlin/dev/orange3/Orange/widgets/visualize/utils/tree/skltreeadapter.py", line 229, in assign
column = self.instances.X[indices, feature_idx]
IndexError: index 10 is out of bounds for axis 1 with size 9

# Fixed code
def num_nodes(self):
    """Get the total number of nodes that the tree contains.

    This does not mean the number of samples inside the entire tree, just
    the number of nodes.

    Returns
    -------
    int

    """
# Buggy code
def root(self):
    """Get the label of the root node.

    Returns
    -------
    object

    """
    pass


# Traceback (IndexError)
Traceback (most recent call last):
File "/home/pavlin/dev/orange3/Orange/widgets/visualize/owpythagorastree.py", line 309, in commit
data = self.tree_adapter.get_instances_in_nodes(nodes)
File "/home/pavlin/dev/orange3/Orange/widgets/visualize/utils/tree/skltreeadapter.py", line 260, in get_instances_in_nodes
leaf_samples = self.get_samples_in_leaves()
File "/home/pavlin/dev/orange3/Orange/widgets/visualize/utils/tree/skltreeadapter.py", line 243, in get_samples_in_leaves
leaf_indices = assign(0, items)
File "/home/pavlin/dev/orange3/Orange/widgets/visualize/utils/tree/skltreeadapter.py", line 229, in assign
column = self.instances.X[indices, feature_idx]
IndexError: index 10 is out of bounds for axis 1 with size 9

# Fixed code
def root(self):
    """Get the label of the root node.

    Returns
    -------
    object

    """
# Buggy code
def __repr__(self):
    # In addition to saving values onto self, SklLearners save into params
    with patch.object(self, "__dict__", dict(self.__dict__, **self.params)):
        return super().__repr__()


# Traceback (AttributeError)
Traceback (most recent call last):
File "<stdin>", line 4, in <module>
File "/Users/aleserjavec/workspace/orange3/Orange/base.py", line 33, in __repr__
return super().__repr__()
File "/Users/aleserjavec/workspace/orange3/Orange/base.py", line 26, in __repr__
return super().__repr__()
File "/Users/aleserjavec/workspace/orange3/Orange/util.py", line 238, in __repr__
value = getattr(self, param.name)
AttributeError: 'LogisticRegressionLearner' object has no attribute 'penalty'

# Fixed code
def __repr__(self):
    # In addition to saving values onto self, SklLearners save into params
    with patch.dict(self.__dict__, self.params):
        return super().__repr__()
# Buggy code
def unique(x, return_counts=True):
    """Equivalent of np.unique that supports sparse or dense matrices."""
    if not sp.issparse(x):
        return np.unique(x, return_counts=return_counts)

    implicit_zeros = np.prod(x.shape) - x.nnz
    explicit_zeros = not np.all(x.data)
    r = np.unique(x.data, return_counts=return_counts)
    if not implicit_zeros:
        return r
    if return_counts:
        if explicit_zeros:
            r[1][r[0] == 0.0] += implicit_zeros
            return r
        return np.insert(r[0], 0, 0), np.insert(r[1], 0, implicit_zeros)
    else:
        if explicit_zeros:
            return r
        return np.insert(r, 0, 0)


# Traceback (AttributeError)
Traceback (most recent call last):
File "/Users/Niko/Projects/orange3/Orange/widgets/data/owfile.py", line 269, in browse_file
self.load_data()
File "/Users/Niko/Projects/orange3/Orange/widgets/data/owfile.py", line 322, in load_data
self.apply_domain_edit()  # sends data
File "/Users/Niko/Projects/orange3/Orange/widgets/data/owfile.py", line 404, in apply_domain_edit
domain, cols = self.domain_editor.get_domain(self.data.domain, self.data)
File "/Users/Niko/Projects/orange3/Orange/widgets/utils/domaineditor.py", line 231, in get_domain
col_data = col_data.ravel()
File "/Users/Niko/anaconda/envs/temporary/lib/python3.6/site-packages/scipy/sparse/base.py", line 576, in __getattr__
raise AttributeError(attr + " not found")
AttributeError: ravel not found

# Fixed code
def unique(x, return_counts=False):
    """Equivalent of np.unique that supports sparse or dense matrices."""
    if not sp.issparse(x):
        return np.unique(x, return_counts=return_counts)

    implicit_zeros = np.prod(x.shape) - x.nnz
    explicit_zeros = not np.all(x.data)
    r = np.unique(x.data, return_counts=return_counts)
    if not implicit_zeros:
        return r
    if return_counts:
        if explicit_zeros:
            r[1][r[0] == 0.0] += implicit_zeros
            return r
        return np.insert(r[0], 0, 0), np.insert(r[1], 0, implicit_zeros)
    else:
        if explicit_zeros:
            return r
        return np.insert(r, 0, 0)
# Buggy code
def apply_domain_edit(self):
    if self.data is not None:
        domain, cols = self.domain_editor.get_domain(self.data.domain, self.data)
        X, y, m = cols
        X = np.array(X).T if len(X) else np.empty((len(self.data), 0))
        y = np.array(y).T if len(y) else None
        dtpe = (
            object
            if any(isinstance(m, StringVariable) for m in domain.metas)
            else float
        )
        m = np.array(m, dtype=dtpe).T if len(m) else None
        table = Table.from_numpy(domain, X, y, m, self.data.W)
        table.name = self.data.name
        table.ids = np.array(self.data.ids)
        table.attributes = getattr(self.data, "attributes", {})
    else:
        table = self.data

    self.send("Data", table)
    self.apply_button.setEnabled(False)


# Traceback (AttributeError)
Traceback (most recent call last):
File "/Users/Niko/Projects/orange3/Orange/widgets/data/owfile.py", line 269, in browse_file
self.load_data()
File "/Users/Niko/Projects/orange3/Orange/widgets/data/owfile.py", line 322, in load_data
self.apply_domain_edit()  # sends data
File "/Users/Niko/Projects/orange3/Orange/widgets/data/owfile.py", line 404, in apply_domain_edit
domain, cols = self.domain_editor.get_domain(self.data.domain, self.data)
File "/Users/Niko/Projects/orange3/Orange/widgets/utils/domaineditor.py", line 231, in get_domain
col_data = col_data.ravel()
File "/Users/Niko/anaconda/envs/temporary/lib/python3.6/site-packages/scipy/sparse/base.py", line 576, in __getattr__
raise AttributeError(attr + " not found")
AttributeError: ravel not found

# Fixed code
def apply_domain_edit(self):
    if self.data is not None:
        domain, cols = self.domain_editor.get_domain(self.data.domain, self.data)
        X, y, m = cols
        table = Table.from_numpy(domain, X, y, m, self.data.W)
        table.name = self.data.name
        table.ids = np.array(self.data.ids)
        table.attributes = getattr(self.data, "attributes", {})
    else:
        table = self.data

    self.send("Data", table)
    self.apply_button.setEnabled(False)
# Buggy code
def get_puppet(self, session):
    """
    Get an object puppeted by this session through this account. This is
    the main method for retrieving the puppeted object from the
    account's end.

    Args:
        session (Session): Find puppeted object based on this session

    Returns:
        puppet (Object): The matching puppeted object, if any.

    """
    return session.puppet


# Traceback (AttributeError)
Traceback (most recent call last):
File "/home/kevin/Source/muddev/evennia/evennia/commands/cmdhandler.py", line 640, in _run_command
yield cmd.parse()
File "/home/kevin/Source/muddev/evennia/evennia/commands/default/muxcommand.py", line 201, in parse
self.character = self.caller.get_puppet(self.session)
File "/home/kevin/Source/muddev/evennia/evennia/accounts/accounts.py", line 376, in get_puppet
return session.puppet
AttributeError: 'NoneType' object has no attribute 'puppet'

# Fixed code
def get_puppet(self, session):
    """
    Get an object puppeted by this session through this account. This is
    the main method for retrieving the puppeted object from the
    account's end.

    Args:
        session (Session): Find puppeted object based on this session

    Returns:
        puppet (Object): The matching puppeted object, if any.

    """
    return session.puppet if session else None
# Buggy code
def __str__(self):
    "This handles what is shown when e.g. printing the message"
    senders = ",".join(obj.key for obj in self.senders)
    receivers = ",".join(
        ["[%s]" % obj.key for obj in self.channels]
        + [obj.key for obj in self.receivers]
    )
    return "%s->%s: %s" % (senders, receivers, crop(self.message, width=40))


# Traceback (AttributeError)
Traceback (most recent call last):
File "/home/ubuntu/workspace/demogame/world/objects/tests.py", line 13, in test_render_external_sender
print(msg)
File "/home/ubuntu/workspace/evennia2/evennia/comms/models.py", line 403, in __str__
senders = ",".join(obj.key for obj in self.senders)
File "/home/ubuntu/workspace/evennia2/evennia/comms/models.py", line 403, in <genexpr>
senders = ",".join(obj.key for obj in self.senders)
AttributeError: 'str' object has no attribute 'key'

# Fixed code
def __str__(self):
    "This handles what is shown when e.g. printing the message"
    senders = ",".join(getattr(obj, "key", str(obj)) for obj in self.senders)

    receivers = ",".join(
        ["[%s]" % getattr(obj, "key", str(obj)) for obj in self.channels]
        + [getattr(obj, "key", str(obj)) for obj in self.receivers]
    )
    return "%s->%s: %s" % (senders, receivers, crop(self.message, width=40))
# Buggy code
def __init__(self):
    self.key = None
    self.value = default
    self.category = None
    self.strvalue = str(default) if default is not None else None


# Traceback (AttributeError)
======================================================================
ERROR: test_get_all_when_unset (typeclasses.tests.AttributesTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/ubuntu/workspace/demogame/typeclasses/tests.py", line 7, in test_get_all_when_unset
result = self.char2.attributes.get(accessing_obj=self.char1, return_list=True)
File "/home/ubuntu/workspace/evennia/evennia/typeclasses/attributes.py", line 458, in get
ret = [attr for attr in ret if attr.access(accessing_obj,
File "/home/ubuntu/workspace/evennia/evennia/typeclasses/attributes.py", line 458, in <listcomp>
ret = [attr for attr in ret if attr.access(accessing_obj,
AttributeError: 'RetDefault' object has no attribute 'access'

----------------------------------------------------------------------

# Fixed code
def __init__(self, obj):
    """Initialize handler."""
    self.obj = obj
    self._objid = obj.id
    self._model = to_str(obj.__dbclass__.__name__.lower())
    self._cache = {}
    # store category names fully cached
    self._catcache = {}
    # full cache was run on all attributes
    self._cache_complete = False
# Buggy code
def do_unpickle(data):
    """Retrieve pickle from pickled string"""
    return loads(data)


# Traceback (builtins.AttributeError)
19-01-17 08:50:28+01 Unhandled Error
Traceback (most recent call last):
File "d:\pyenv3\Lib\site-packages\twisted\internet\defer.py", line 151, in maybeDeferred
result = f(*args, **kw)
File "d:\evennia\evennia\server\amp_client.py", line 240, in server_receive_adminportal2server
server_sessionhandler.server.shutdown(mode='shutdown')
File "d:\pyenv3\Lib\site-packages\twisted\internet\defer.py", line 1613, in unwindGenerator
return _cancellableInlineCallbacks(gen)
File "d:\pyenv3\Lib\site-packages\twisted\internet\defer.py", line 1529, in _cancellableInlineCallbacks
_inlineCallbacks(None, g, status)
--- <exception caught here> ---
File "d:\pyenv3\Lib\site-packages\twisted\internet\defer.py", line 1418, in _inlineCallbacks
result = g.send(result)
File "d:\evennia\evennia\server\server.py", line 377, in shutdown
for p in AccountDB.get_all_cached_instances()]
File "d:\evennia\evennia\server\server.py", line 377, in <listcomp>
for p in AccountDB.get_all_cached_instances()]
File "d:\evennia\evennia\accounts\accounts.py", line 336, in unpuppet_all
self.unpuppet_object(self.sessions.all())
File "d:\evennia\evennia\accounts\accounts.py", line 322, in unpuppet_object
obj.at_pre_unpuppet()
File "d:\evennia\evennia\contrib\ingame_python\typeclasses.py", line 391, in at_pre_unpuppet
self.callbacks.call("unpuppeted", self)
builtins.AttributeError: 'Character' object has no attribute 'callbacks'

# Fixed code
def do_unpickle(data):
    """Retrieve pickle from pickled string"""
    return loads(to_bytes(data))
# Buggy code
def fromBox(self, name, strings, objects, proto):
    """
    Converts from box representation to python. We
    group very long data into batches.
    """
    value = StringIO()
    value.write(strings.get(name))
    for counter in count(2):
        # count from 2 upwards
        chunk = strings.get("%s.%d" % (name, counter))
        if chunk is None:
            break
        value.write(chunk)
    objects[name] = value.getvalue()


# Traceback (ValueError)
Traceback (most recent call last):
File "/usr/src/evennia/evennia/commands/cmdhandler.py", line 591, in _run_command
ret = cmd.func()
File "/usr/src/evennia/evennia/commands/default/system.py", line 769, in func
rmem = float(os.popen('ps -p %d -o %s | tail -1' % (pid, "rss")).read()) / 1000.0  # resident
memory
ValueError: could not convert string to float:

An untrapped error occurred.
(Traceback was logged 2018-07-17 01:10:38-0000).

# Fixed code
def fromBox(self, name, strings, objects, proto):
    """
    Converts from box string representation to python. We read back too-long batched data and
    put it back together here.

    """
    value = StringIO()
    value.write(self.fromStringProto(strings.get(name), proto))
    for counter in count(2):
        # count from 2 upwards
        chunk = strings.get("%s.%d" % (name, counter))
        if chunk is None:
            break
        value.write(self.fromStringProto(chunk, proto))
    objects[name] = value.getvalue()