gurudesh/pytracebugs huggingface dataset:
# Buggy code
def create_new_var(self, name: str, typ: Instance) -> Var:
    # type=: type of the variable itself
    var = Var(name=name, type=typ)
    # var.info: type of the object variable is bound to
    var.info = self.model_classdef.info
    var._fullname = self.model_classdef.info.fullname() + "." + name
    var.is_initialized_in_class = True
    var.is_inferred = True
    return var


# Traceback (AttributeError)
Traceback (most recent call last):
File "/usr/local/bin/mypy", line 10, in <module>
sys.exit(console_entry())
File "/usr/local/lib/python3.6/site-packages/mypy/__main__.py", line 8, in console_entry
main(None, sys.stdout, sys.stderr)
File "/usr/local/lib/python3.6/site-packages/mypy/main.py", line 83, in main
res = build.build(sources, options, None, flush_errors, fscache, stdout, stderr)
File "/usr/local/lib/python3.6/site-packages/mypy/build.py", line 164, in build
result = _build(sources, options, alt_lib_path, flush_errors, fscache, stdout, stderr)
File "/usr/local/lib/python3.6/site-packages/mypy/build.py", line 224, in _build
graph = dispatch(sources, manager, stdout)
File "/usr/local/lib/python3.6/site-packages/mypy/build.py", line 2526, in dispatch
graph = load_graph(sources, manager)
File "/usr/local/lib/python3.6/site-packages/mypy/build.py", line 2748, in load_graph
caller_state=st, caller_line=st.dep_line_map.get(dep, 1))
File "/usr/local/lib/python3.6/site-packages/mypy/build.py", line 1772, in __init__
self.compute_dependencies()
File "/usr/local/lib/python3.6/site-packages/mypy/build.py", line 2059, in compute_dependencies
self.manager.plugin.get_additional_deps(self.tree))
File "/usr/local/lib/python3.6/site-packages/mypy/plugin.py", line 743, in get_additional_deps
deps.extend(plugin.get_additional_deps(file))
File "/usr/local/lib/python3.6/site-packages/mypy_django_plugin/main.py", line 152, in get_additional_deps
related_model_module = related_model_cls.__module__
AttributeError: 'NoneType' object has no attribute '__module__'

# Fixed code
def create_new_var(self, name: str, typ: MypyType) -> Var:
    # type=: type of the variable itself
    var = Var(name=name, type=typ)
    # var.info: type of the object variable is bound to
    var.info = self.model_classdef.info
    var._fullname = self.model_classdef.info.fullname() + "." + name
    var.is_initialized_in_class = True
    var.is_inferred = True
    return var
# Buggy code
def add_new_node_to_model_class(self, name: str, typ: Instance) -> None:
    var = self.create_new_var(name, typ)
    self.model_classdef.info.names[name] = SymbolTableNode(
        MDEF, var, plugin_generated=True
    )


# Traceback (AttributeError)
Traceback (most recent call last):
File "/usr/local/bin/mypy", line 10, in <module>
sys.exit(console_entry())
File "/usr/local/lib/python3.6/site-packages/mypy/__main__.py", line 8, in console_entry
main(None, sys.stdout, sys.stderr)
File "/usr/local/lib/python3.6/site-packages/mypy/main.py", line 83, in main
res = build.build(sources, options, None, flush_errors, fscache, stdout, stderr)
File "/usr/local/lib/python3.6/site-packages/mypy/build.py", line 164, in build
result = _build(sources, options, alt_lib_path, flush_errors, fscache, stdout, stderr)
File "/usr/local/lib/python3.6/site-packages/mypy/build.py", line 224, in _build
graph = dispatch(sources, manager, stdout)
File "/usr/local/lib/python3.6/site-packages/mypy/build.py", line 2526, in dispatch
graph = load_graph(sources, manager)
File "/usr/local/lib/python3.6/site-packages/mypy/build.py", line 2748, in load_graph
caller_state=st, caller_line=st.dep_line_map.get(dep, 1))
File "/usr/local/lib/python3.6/site-packages/mypy/build.py", line 1772, in __init__
self.compute_dependencies()
File "/usr/local/lib/python3.6/site-packages/mypy/build.py", line 2059, in compute_dependencies
self.manager.plugin.get_additional_deps(self.tree))
File "/usr/local/lib/python3.6/site-packages/mypy/plugin.py", line 743, in get_additional_deps
deps.extend(plugin.get_additional_deps(file))
File "/usr/local/lib/python3.6/site-packages/mypy_django_plugin/main.py", line 152, in get_additional_deps
related_model_module = related_model_cls.__module__
AttributeError: 'NoneType' object has no attribute '__module__'

# Fixed code
def add_new_node_to_model_class(self, name: str, typ: MypyType) -> None:
    var = self.create_new_var(name, typ)
    self.model_classdef.info.names[name] = SymbolTableNode(
        MDEF, var, plugin_generated=True
    )
# Buggy code
def __init__(self, *, alpha=1.0, fit_prior=True, class_prior=None):
    self.alpha = alpha
    self.fit_prior = fit_prior
    self.class_prior = class_prior


# Traceback (IndexError)
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-3-551bb8080923> in <module>
10 model = CategoricalNB().fit(X_train, y_train)
11
---> 12 model.predict(X_test)

~/Documents/MachineLearning/onnx_projects/skl_env/lib/python3.6/site-packages/sklearn/naive_bayes.py in predict(self, X)
75         check_is_fitted(self)
76         X = self._check_X(X)
---> 77         jll = self._joint_log_likelihood(X)
78         return self.classes_[np.argmax(jll, axis=1)]
79

~/Documents/MachineLearning/onnx_projects/skl_env/lib/python3.6/site-packages/sklearn/naive_bayes.py in _joint_log_likelihood(self, X)
1217         for i in range(self.n_features_):
1218             indices = X[:, i]
-> 1219             jll += self.feature_log_prob_[i][:, indices].T
1220         total_ll = jll + self.class_log_prior_
1221         return total_ll

IndexError: index 5 is out of bounds for axis 1 with size 5

# Fixed code
def __init__(self, *, alpha=1.0, fit_prior=True, class_prior=None, min_categories=None):
    self.alpha = alpha
    self.fit_prior = fit_prior
    self.class_prior = class_prior
    self.min_categories = min_categories
# Buggy code
def __init__(
    self,
    n_clusters=2,
    *,
    affinity="euclidean",
    memory=None,
    connectivity=None,
    compute_full_tree="auto",
    linkage="ward",
    distance_threshold=None,
):
    self.n_clusters = n_clusters
    self.distance_threshold = distance_threshold
    self.memory = memory
    self.connectivity = connectivity
    self.compute_full_tree = compute_full_tree
    self.linkage = linkage
    self.affinity = affinity


# Traceback (AttributeError)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-20-6255925aaa42> in <module>
21
22 # plot the top three levels of the dendrogram
---> 23 plot_dendrogram(cluster, truncate_mode='level', p=3)
24 plt.xlabel("Number of points in node (or index of point if no parenthesis).")
25 plt.show()

<ipython-input-20-6255925aaa42> in plot_dendrogram(model, **kwargs)
14         counts[i] = current_count
15
---> 16     linkage_matrix = np.column_stack([model.children_, model.distances_,
17                                       counts]).astype(float)
18

AttributeError: 'AgglomerativeClustering' object has no attribute 'distances_'

# Fixed code
def __init__(
    self,
    n_clusters=2,
    *,
    affinity="euclidean",
    memory=None,
    connectivity=None,
    compute_full_tree="auto",
    linkage="ward",
    distance_threshold=None,
    compute_distances=False,
):
    self.n_clusters = n_clusters
    self.distance_threshold = distance_threshold
    self.memory = memory
    self.connectivity = connectivity
    self.compute_full_tree = compute_full_tree
    self.linkage = linkage
    self.affinity = affinity
    self.compute_distances = compute_distances
# Buggy code
def __init__(
    self,
    n_clusters=2,
    *,
    affinity="euclidean",
    memory=None,
    connectivity=None,
    compute_full_tree="auto",
    linkage="ward",
    pooling_func=np.mean,
    distance_threshold=None,
):
    super().__init__(
        n_clusters=n_clusters,
        memory=memory,
        connectivity=connectivity,
        compute_full_tree=compute_full_tree,
        linkage=linkage,
        affinity=affinity,
        distance_threshold=distance_threshold,
    )
    self.pooling_func = pooling_func


# Traceback (AttributeError)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-20-6255925aaa42> in <module>
21
22 # plot the top three levels of the dendrogram
---> 23 plot_dendrogram(cluster, truncate_mode='level', p=3)
24 plt.xlabel("Number of points in node (or index of point if no parenthesis).")
25 plt.show()

<ipython-input-20-6255925aaa42> in plot_dendrogram(model, **kwargs)
14         counts[i] = current_count
15
---> 16     linkage_matrix = np.column_stack([model.children_, model.distances_,
17                                       counts]).astype(float)
18

AttributeError: 'AgglomerativeClustering' object has no attribute 'distances_'

# Fixed code
def __init__(
    self,
    n_clusters=2,
    *,
    affinity="euclidean",
    memory=None,
    connectivity=None,
    compute_full_tree="auto",
    linkage="ward",
    pooling_func=np.mean,
    distance_threshold=None,
    compute_distances=False,
):
    super().__init__(
        n_clusters=n_clusters,
        memory=memory,
        connectivity=connectivity,
        compute_full_tree=compute_full_tree,
        linkage=linkage,
        affinity=affinity,
        distance_threshold=distance_threshold,
        compute_distances=compute_distances,
    )
    self.pooling_func = pooling_func
# Buggy code
def _special_sparse_dot(W, H, X):
    """Computes np.dot(W, H), only where X is non zero."""
    if sp.issparse(X):
        ii, jj = X.nonzero()
        dot_vals = np.multiply(W[ii, :], H.T[jj, :]).sum(axis=1)
        WH = sp.coo_matrix((dot_vals, (ii, jj)), shape=X.shape)
        return WH.tocsr()
    else:
        return np.dot(W, H)


# Traceback (numpy.core._exceptions.MemoryError)
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "C:\Program Files\JetBrains\PyCharm 2019.1.3\helpers\pydev\_pydev_bundle\pydev_umd.py", line 197, in runfile
pydev_imports.execfile(filename, global_vars, local_vars)  # execute the script
File "C:\Program Files\JetBrains\PyCharm 2019.1.3\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "C:/Users/<user>/.PyCharm2019.1/config/scratches/scratch.py", line 9, in <module>
fit = nmf.fit_transform(matrix)
File "C:\Workdir\programs\miniconda\envs\monty\lib\site-packages\sklearn\decomposition\nmf.py", line 1289, in fit_transform
shuffle=self.shuffle)
File "C:\Workdir\programs\miniconda\envs\monty\lib\site-packages\sklearn\decomposition\nmf.py", line 1077, in non_negative_factorization
verbose)
File "C:\Workdir\programs\miniconda\envs\monty\lib\site-packages\sklearn\decomposition\nmf.py", line 800, in _fit_multiplicative_update
error_at_init = _beta_divergence(X, W, H, beta_loss, square_root=True)
File "C:\Workdir\programs\miniconda\envs\monty\lib\site-packages\sklearn\decomposition\nmf.py", line 119, in _beta_divergence
WH_data = _special_sparse_dot(W, H, X).data
File "C:\Workdir\programs\miniconda\envs\monty\lib\site-packages\sklearn\decomposition\nmf.py", line 187, in _special_sparse_dot
dot_vals = np.multiply(W[ii, :], H.T[jj, :]).sum(axis=1)
numpy.core._exceptions.MemoryError: Unable to allocate array with shape (75000000, 300) and data type float64

# Fixed code
def _special_sparse_dot(W, H, X):
    """Computes np.dot(W, H), only where X is non zero."""
    if sp.issparse(X):
        ii, jj = X.nonzero()
        n_vals = ii.shape[0]
        dot_vals = np.empty(n_vals)
        n_components = W.shape[1]

        batch_size = max(n_components, n_vals // n_components)
        for start in range(0, n_vals, batch_size):
            batch = slice(start, start + batch_size)
            dot_vals[batch] = np.multiply(W[ii[batch], :], H.T[jj[batch], :]).sum(
                axis=1
            )

        WH = sp.coo_matrix((dot_vals, (ii, jj)), shape=X.shape)
        return WH.tocsr()
    else:
        return np.dot(W, H)
# Buggy code
def distance_metrics():
    """Valid metrics for pairwise_distances.

    This function simply returns the valid pairwise distance metrics.
    It exists to allow for a description of the mapping for
    each of the valid strings.

    The valid distance metrics, and the function they map to, are:

    ============     ====================================
    metric           Function
    ============     ====================================
    'cityblock'      metrics.pairwise.manhattan_distances
    'cosine'         metrics.pairwise.cosine_distances
    'euclidean'      metrics.pairwise.euclidean_distances
    'l1'             metrics.pairwise.manhattan_distances
    'l2'             metrics.pairwise.euclidean_distances
    'manhattan'      metrics.pairwise.manhattan_distances
    ============     ====================================

    Read more in the :ref:`User Guide <metrics>`.

    """
    return PAIRWISE_DISTANCE_FUNCTIONS


# Traceback (ValueError)
nn = NearestNeighbors(metric="haversine")
nn.fit([[48.8322, 2.3561], [45.7679, 4.8506]])
NearestNeighbors(algorithm='auto', leaf_size=30, metric='haversine',
metric_params=None, n_jobs=None, n_neighbors=5, p=2, radius=1.0)
nn.kneighbors([[48.8322, 2.3561]], 2)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/rth/src/scikit-learn/sklearn/neighbors/base.py", line 449, in kneighbors
dist, neigh_ind = zip(*result)
File "/home/rth/src/scikit-learn/sklearn/metrics/pairwise.py", line 1282, in pairwise_distances_chunked
n_jobs=n_jobs, **kwds)
File "/home/rth/src/scikit-learn/sklearn/metrics/pairwise.py", line 1380, in pairwise_distances
"callable" % (metric, _VALID_METRICS))
ValueError: Unknown metric haversine. Valid metrics are ['euclidean', 'l2', 'l1', 'manhattan', 'cityblock', 'braycurtis', 'canberra', 'chebyshev', 'correlation', 'cosine', 'dice', 'hamming', 'jaccard', 'kulsinski', 'mahalanobis', 'matching', 'minkowski', 'rogerstanimoto', 'russellrao', 'seuclidean', 'sokalmichener', 'sokalsneath', 'sqeuclidean', 'yule', 'wminkowski'], or 'precomputed', or a callable

# Fixed code
def distance_metrics():
    """Valid metrics for pairwise_distances.

    This function simply returns the valid pairwise distance metrics.
    It exists to allow for a description of the mapping for
    each of the valid strings.

    The valid distance metrics, and the function they map to, are:

    ============     ====================================
    metric           Function
    ============     ====================================
    'cityblock'      metrics.pairwise.manhattan_distances
    'cosine'         metrics.pairwise.cosine_distances
    'euclidean'      metrics.pairwise.euclidean_distances
    'haversine'      metrics.pairwise.haversine_distances
    'l1'             metrics.pairwise.manhattan_distances
    'l2'             metrics.pairwise.euclidean_distances
    'manhattan'      metrics.pairwise.manhattan_distances
    ============     ====================================

    Read more in the :ref:`User Guide <metrics>`.

    """
    return PAIRWISE_DISTANCE_FUNCTIONS
# Buggy code
def __init__(self, linear_sum=None):
    if linear_sum is None:
        self.n_samples_ = 0
        self.squared_sum_ = 0.0
        self.linear_sum_ = 0
    else:
        self.n_samples_ = 1
        self.centroid_ = self.linear_sum_ = linear_sum
        self.squared_sum_ = self.sq_norm_ = np.dot(self.linear_sum_, self.linear_sum_)
    self.child_ = None


# Traceback (AttributeError)
Traceback (most recent call last):
File "clusterer.py", line 27, in score
labels = self.clusterer.fit_predict(x)
File "/usr/lib/python2.7/dist-packages/sklearn/base.py", line 371, in fit_predict
self.fit(X)
File "/usr/lib/python2.7/dist-packages/sklearn/cluster/birch.py", line 424, in fit
return self._fit(X)
File "/usr/lib/python2.7/dist-packages/sklearn/cluster/birch.py", line 458, in _fit
split = self.root_.insert_cf_subcluster(subcluster)
File "/usr/lib/python2.7/dist-packages/sklearn/cluster/birch.py", line 193, in insert_cf_subcluster
subcluster)
File "/usr/lib/python2.7/dist-packages/sklearn/cluster/birch.py", line 212, in insert_cf_subcluster
closest_subcluster, new_subcluster1, new_subcluster2)
File "/usr/lib/python2.7/dist-packages/sklearn/cluster/birch.py", line 170, in update_split_subclusters
self.init_centroids_[ind] = new_subcluster1.centroid_
AttributeError: '_CFSubcluster' object has no attribute 'centroid_'

# Fixed code
def __init__(self, linear_sum=None):
    if linear_sum is None:
        self.n_samples_ = 0
        self.squared_sum_ = 0.0
        self.centroid_ = self.linear_sum_ = 0
    else:
        self.n_samples_ = 1
        self.centroid_ = self.linear_sum_ = linear_sum
        self.squared_sum_ = self.sq_norm_ = np.dot(self.linear_sum_, self.linear_sum_)
    self.child_ = None
# Buggy code
def transform(self, X):
    """Transform X separately by each transformer, concatenate results.

    Parameters
    ----------
    X : array-like or DataFrame of shape [n_samples, n_features]
        The data to be transformed by subset.

    Returns
    -------
    X_t : array-like or sparse matrix, shape (n_samples, sum_n_components)
        hstack of results of transformers. sum_n_components is the
        sum of n_components (output dimension) over transformers. If
        any result is a sparse matrix, everything will be converted to
        sparse matrices.

    """
    check_is_fitted(self, "transformers_")

    Xs = self._fit_transform(X, None, _transform_one, fitted=True)
    self._validate_output(Xs)

    if not Xs:
        # All transformers are None
        return np.zeros((X.shape[0], 0))

    return self._hstack(list(Xs))


# Traceback (AttributeError)
from sklearn.preprocessing import StandardScaler
from sklearn.compose import ColumnTransformer
ColumnTransformer([('foobar', StandardScaler(), [0, 1, 2])]).fit([[1, 2, 3]])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/joel/repos/scikit-learn/sklearn/compose/_column_transformer.py", line 398, in fit
self.fit_transform(X, y=y)
File "/Users/joel/repos/scikit-learn/sklearn/compose/_column_transformer.py", line 422, in fit_transform
self._validate_remainder(X)
File "/Users/joel/repos/scikit-learn/sklearn/compose/_column_transformer.py", line 275, in _validate_remainder
n_columns = X.shape[1]
AttributeError: 'list' object has no attribute 'shape'

# Fixed code
def transform(self, X):
    """Transform X separately by each transformer, concatenate results.

    Parameters
    ----------
    X : array-like or DataFrame of shape [n_samples, n_features]
        The data to be transformed by subset.

    Returns
    -------
    X_t : array-like or sparse matrix, shape (n_samples, sum_n_components)
        hstack of results of transformers. sum_n_components is the
        sum of n_components (output dimension) over transformers. If
        any result is a sparse matrix, everything will be converted to
        sparse matrices.

    """
    check_is_fitted(self, "transformers_")

    X = _check_X(X)
    Xs = self._fit_transform(X, None, _transform_one, fitted=True)
    self._validate_output(Xs)

    if not Xs:
        # All transformers are None
        return np.zeros((X.shape[0], 0))

    return self._hstack(list(Xs))
# Buggy code
def _set_params(self, attr, **params):
    # Ensure strict ordering of parameter setting:
    # 1. All steps
    if attr in params:
        setattr(self, attr, params.pop(attr))
    # 2. Step replacement
    names, _ = zip(*getattr(self, attr))
    for name in list(six.iterkeys(params)):
        if "__" not in name and name in names:
            self._replace_estimator(attr, name, params.pop(name))
    # 3. Step parameters and other initialisation arguments
    super(_BaseComposition, self).set_params(**params)
    return self


# Traceback (ValueError)
from sklearn.compose import ColumnTransformer
ColumnTransformer([]).set_params(n_jobs=2)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/joel/repos/scikit-learn/sklearn/compose/_column_transformer.py", line 181, in set_params
self._set_params('_transformers', **kwargs)
File "/Users/joel/repos/scikit-learn/sklearn/utils/metaestimators.py", line 44, in _set_params
names, _ = zip(*getattr(self, attr))
ValueError: not enough values to unpack (expected 2, got 0)

# Fixed code
def _set_params(self, attr, **params):
    # Ensure strict ordering of parameter setting:
    # 1. All steps
    if attr in params:
        setattr(self, attr, params.pop(attr))
    # 2. Step replacement
    items = getattr(self, attr)
    names = []
    if items:
        names, _ = zip(*items)
    for name in list(six.iterkeys(params)):
        if "__" not in name and name in names:
            self._replace_estimator(attr, name, params.pop(name))
    # 3. Step parameters and other initialisation arguments
    super(_BaseComposition, self).set_params(**params)
    return self
# Buggy code
def fit(self, X, y=None):
    """Estimate model parameters with the EM algorithm.

    The method fits the model `n_init` times and set the parameters with
    which the model has the largest likelihood or lower bound. Within each
    trial, the method iterates between E-step and M-step for `max_iter`
    times until the change of likelihood or lower bound is less than
    `tol`, otherwise, a `ConvergenceWarning` is raised.

    Parameters
    ----------
    X : array-like, shape (n_samples, n_features)
        List of n_features-dimensional data points. Each row
        corresponds to a single data point.

    Returns
    -------
    self
    """
    self.fit_predict(X, y)
    return self


# Traceback (AssertionError)
Traceback (most recent call last):
File "<stdin>", line 4, in <module>
AssertionError: 4

# Fixed code
def fit(self, X, y=None):
    """Estimate model parameters with the EM algorithm.

    The method fits the model ``n_init`` times and sets the parameters with
    which the model has the largest likelihood or lower bound. Within each
    trial, the method iterates between E-step and M-step for ``max_iter``
    times until the change of likelihood or lower bound is less than
    ``tol``, otherwise, a ``ConvergenceWarning`` is raised.
    If ``warm_start`` is ``True``, then ``n_init`` is ignored and a single
    initialization is performed upon the first call. Upon consecutive
    calls, training starts where it left off.

    Parameters
    ----------
    X : array-like, shape (n_samples, n_features)
        List of n_features-dimensional data points. Each row
        corresponds to a single data point.

    Returns
    -------
    self
    """
    self.fit_predict(X, y)
    return self
# Buggy code
def inverse_transform(self, y):
    """Transform labels back to original encoding.

    Parameters
    ----------
    y : numpy array of shape [n_samples]
        Target values.

    Returns
    -------
    y : numpy array of shape [n_samples]
    """
    check_is_fitted(self, "classes_")

    diff = np.setdiff1d(y, np.arange(len(self.classes_)))
    if len(diff):
        raise ValueError("y contains previously unseen labels: %s" % str(diff))
    y = np.asarray(y)
    return self.classes_[y]


# Traceback (TypeError)
from sklearn.preprocessing import LabelEncoder
le = LabelEncoder()
le.fit([1,2])
LabelEncoder()
le.transform([])
array([], dtype=int64)
le.fit(["a","b"])
LabelEncoder()
le.transform([])
Traceback (most recent call last):
File "[...]\Python36\lib\site-packages\numpy\core\fromnumeric.py", line 57, in _wrapfunc
return getattr(obj, method)(*args, **kwds)
TypeError: Cannot cast array data from dtype('float64') to dtype('<U32') according to the rule 'safe'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "[...]\Python36\lib\site-packages\sklearn\preprocessing\label.py", line 134, in transform
return np.searchsorted(self.classes_, y)
File "[...]\Python36\lib\site-packages\numpy\core\fromnumeric.py", line 1075, in searchsorted
return _wrapfunc(a, 'searchsorted', v, side=side, sorter=sorter)
File "[...]\Python36\lib\site-packages\numpy\core\fromnumeric.py", line 67, in _wrapfunc
return _wrapit(obj, method, *args, **kwds)
File "[...]\Python36\lib\site-packages\numpy\core\fromnumeric.py", line 47, in _wrapit
result = getattr(asarray(obj), method)(*args, **kwds)
TypeError: Cannot cast array data from dtype('float64') to dtype('<U32') according to the rule 'safe'

# Fixed code
def inverse_transform(self, y):
    """Transform labels back to original encoding.

    Parameters
    ----------
    y : numpy array of shape [n_samples]
        Target values.

    Returns
    -------
    y : numpy array of shape [n_samples]
    """
    check_is_fitted(self, "classes_")
    y = column_or_1d(y, warn=True)
    # inverse transform of empty array is empty array
    if _num_samples(y) == 0:
        return np.array([])

    diff = np.setdiff1d(y, np.arange(len(self.classes_)))
    if len(diff):
        raise ValueError("y contains previously unseen labels: %s" % str(diff))
    y = np.asarray(y)
    return self.classes_[y]
# Buggy code
def predict(self, X):
    """Predict the closest cluster each sample in X belongs to.

    Parameters
    ----------
    X : {array-like, sparse matrix}, shape (n_samples, n_features)
        New data to predict.

    Returns
    -------
    labels : array, shape (n_samples,)
        Index of the cluster each sample belongs to.
    """
    check_is_fitted(self, "cluster_centers_indices_")
    if not hasattr(self, "cluster_centers_"):
        raise ValueError("Predict method is not supported when affinity='precomputed'.")

    return pairwise_distances_argmin(X, self.cluster_centers_)


# Traceback (ValueError)
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "/Users/jsamoocha/.virtualenvs/coach/lib/python2.7/site-packages/sklearn/cluster/affinity_propagation_.py", line 324, in predict
return pairwise_distances_argmin(X, self.cluster_centers_)
File "/Users/jsamoocha/.virtualenvs/coach/lib/python2.7/site-packages/sklearn/metrics/pairwise.py", line 464, in pairwise_distances_argmin
metric_kwargs)[0]
File "/Users/jsamoocha/.virtualenvs/coach/lib/python2.7/site-packages/sklearn/metrics/pairwise.py", line 339, in pairwise_distances_argmin_min
X, Y = check_pairwise_arrays(X, Y)
File "/Users/jsamoocha/.virtualenvs/coach/lib/python2.7/site-packages/sklearn/metrics/pairwise.py", line 111, in check_pairwise_arrays
warn_on_dtype=warn_on_dtype, estimator=estimator)
File "/Users/jsamoocha/.virtualenvs/coach/lib/python2.7/site-packages/sklearn/utils/validation.py", line 405, in check_array
% (array.ndim, estimator_name))
ValueError: Found array with dim 3. check_pairwise_arrays expected <= 2.

# Fixed code
def predict(self, X):
    """Predict the closest cluster each sample in X belongs to.

    Parameters
    ----------
    X : {array-like, sparse matrix}, shape (n_samples, n_features)
        New data to predict.

    Returns
    -------
    labels : array, shape (n_samples,)
        Index of the cluster each sample belongs to.
    """
    check_is_fitted(self, "cluster_centers_indices_")
    if not hasattr(self, "cluster_centers_"):
        raise ValueError("Predict method is not supported when affinity='precomputed'.")

    if self.cluster_centers_.size > 0:
        return pairwise_distances_argmin(X, self.cluster_centers_)
    else:
        warnings.warn(
            "This model does not have any cluster centers "
            "because affinity propagation did not converge. "
            "Labeling every sample as '-1'."
        )
        return np.array([-1] * X.shape[0])
# Buggy code
def _num_samples(x):
    """Return number of samples in array-like x."""
    if hasattr(x, "fit"):
        # Don't get num_samples from an ensembles length!
        raise TypeError("Expected sequence or array-like, got estimator %s" % x)
    if not hasattr(x, "__len__") and not hasattr(x, "shape"):
        if hasattr(x, "__array__"):
            x = np.asarray(x)
        else:
            raise TypeError("Expected sequence or array-like, got %s" % type(x))
    if hasattr(x, "shape"):
        if len(x.shape) == 0:
            raise TypeError(
                "Singleton array %r cannot be considered a valid collection." % x
            )
        return x.shape[0]
    else:
        return len(x)


# Traceback (TypeError)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-20-4e085b2f516b> in <module>()
13 gkf = GroupKFold(n_splits=10)
14
---> 15 for train, test in gkf.split(X, Y, groups=X['petal width (cm)']):
16         pass

AppData\Local\Continuum\Anaconda2\lib\site-packages\sklearn\model_selection\_split.pyc in split(self, X, y, groups)
312             The testing set indices for that split.
313         """
--> 314         X, y, groups = indexable(X, y, groups)
315         n_samples = _num_samples(X)
316         if self.n_splits > n_samples:

AppData\Local\Continuum\Anaconda2\lib\site-packages\sklearn\utils\validation.pyc in indexable(*iterables)
204         else:
205             result.append(np.array(X))
--> 206     check_consistent_length(*result)
207     return result
208

AppData\Local\Continuum\Anaconda2\lib\site-packages\sklearn\utils\validation.pyc in check_consistent_length(*arrays)
175     """
176
--> 177     lengths = [_num_samples(X) for X in arrays if X is not None]
178     uniques = np.unique(lengths)
179     if len(uniques) > 1:

AppData\Local\Continuum\Anaconda2\lib\site-packages\sklearn\utils\validation.pyc in _num_samples(x)
114         # Don't get num_samples from an ensembles length!
115         raise TypeError('Expected sequence or array-like, got '
--> 116                         'estimator %s' % x)
117     if not hasattr(x, '__len__') and not hasattr(x, 'shape'):
118         if hasattr(x, '__array__'):

TypeError: Expected sequence or array-like, got estimator      sepal length (cm)  sepal width (cm)  petal length (cm)  petal width (cm)  \

# Fixed code
def _num_samples(x):
    """Return number of samples in array-like x."""
    if hasattr(x, "fit") and callable(x.fit):
        # Don't get num_samples from an ensembles length!
        raise TypeError("Expected sequence or array-like, got estimator %s" % x)
    if not hasattr(x, "__len__") and not hasattr(x, "shape"):
        if hasattr(x, "__array__"):
            x = np.asarray(x)
        else:
            raise TypeError("Expected sequence or array-like, got %s" % type(x))
    if hasattr(x, "shape"):
        if len(x.shape) == 0:
            raise TypeError(
                "Singleton array %r cannot be considered a valid collection." % x
            )
        return x.shape[0]
    else:
        return len(x)
# Buggy code
def predict_proba(self, X):
    """Probability estimates.
    Returns prediction probabilites for each class of each output.

    Parameters
    ----------
    X : array-like, shape (n_samples, n_features)
        Data

    Returns
    -------
    T : (sparse) array-like, shape = (n_samples, n_classes, n_outputs)
        The class probabilities of the samples for each of the outputs
    """
    check_is_fitted(self, "estimators_")
    if not hasattr(self.estimator, "predict_proba"):
        raise ValueError("The base estimator should implementpredict_proba method")

    results = np.dstack([estimator.predict_proba(X) for estimator in self.estimators_])
    return results


# Traceback (ValueError)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-40-84c34a558c92> in <module>()
18 clf.fit(X, Y)
19
---> 20 clf.predict_proba(X)

anaconda/lib/python3.5/site-packages/sklearn/multioutput.py in predict_proba(self, X)
224
225         results = np.dstack([estimator.predict_proba(X) for estimator in
--> 226                             self.estimators_])
227         return results
228

anaconda/lib/python3.5/site-packages/numpy/lib/shape_base.py in dstack(tup)
366
367     """
--> 368     return _nx.concatenate([atleast_3d(_m) for _m in tup], 2)
369
370 def _replace_zero_by_x_arrays(sub_arys):

ValueError: all the input array dimensions except for the concatenation axis must match exactly

# Fixed code
def predict_proba(self, X):
    """Probability estimates.
        Returns prediction probabilites for each class of each output.

        Parameters
        ----------
        X : array-like, shape (n_samples, n_features)
            Data

        Returns
        -------
        p : array of shape = [n_samples, n_classes], or a list of n_outputs \
            such arrays if n_outputs > 1.
            The class probabilities of the input samples. The order of the
            classes corresponds to that in the attribute `classes_`.
        """
    check_is_fitted(self, "estimators_")
    if not hasattr(self.estimator, "predict_proba"):
        raise ValueError("The base estimator should implementpredict_proba method")

    results = [estimator.predict_proba(X) for estimator in self.estimators_]
    return results
# Buggy code
def split(self, X, y, groups=None):
    """Generate indices to split data into training and test set.

    Parameters
    ----------
    X : array-like, shape (n_samples, n_features)
        Training data, where n_samples is the number of samples
        and n_features is the number of features.

    y : array-like, shape (n_samples,)
        The target variable for supervised learning problems.

    groups : array-like, with shape (n_samples,), optional
        Group labels for the samples used while splitting the dataset into
        train/test set.

    Returns
    -------
    train : ndarray
        The training set indices for that split.

    test : ndarray
        The testing set indices for that split.
    """
    return super(StratifiedKFold, self).split(X, y, groups)


# Traceback (ImportError)
In [3]: from sklearn.model_selection import train_test_split
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-3-139cc3505715> in <module>()
----> 1 from sklearn.model_selection import train_test_split

/usr/local/lib/python2.7/dist-packages/sklearn/model_selection/__init__.py in <module>()
15 from ._split import check_cv
16
---> 17 from ._validation import cross_val_score
18 from ._validation import cross_val_predict
19 from ._validation import learning_curve

/usr/local/lib/python2.7/dist-packages/sklearn/model_selection/_validation.py in <module>()
25 from ..utils.fixes import astype
26 from ..utils.validation import _is_arraylike, _num_samples
---> 27 from ..utils.metaestimators import _safe_split
28 from ..externals.joblib import Parallel, delayed, logger
29 from ..metrics.scorer import check_scoring

ImportError: cannot import name _safe_split

# Fixed code
def split(self, X, y, groups=None):
    """Generate indices to split data into training and test set.

    Parameters
    ----------
    X : array-like, shape (n_samples, n_features)
        Training data, where n_samples is the number of samples
        and n_features is the number of features.

        Note that providing ``y`` is sufficient to generate the splits and
        hence ``np.zeros(n_samples)`` may be used as a placeholder for
        ``X`` instead of actual training data.

    y : array-like, shape (n_samples,)
        The target variable for supervised learning problems.
        Stratification is done based on the y labels.

    groups : object
        Always ignored, exists for compatibility.

    Returns
    -------
    train : ndarray
        The training set indices for that split.

    test : ndarray
        The testing set indices for that split.
    """
    y = check_array(y, ensure_2d=False, dtype=None)
    return super(StratifiedKFold, self).split(X, y, groups)
# Buggy code
def get_n_splits(self, X, y, groups):
    """Returns the number of splitting iterations in the cross-validator

    Parameters
    ----------
    X : object
        Always ignored, exists for compatibility.

    y : object
        Always ignored, exists for compatibility.

    groups : array-like, with shape (n_samples,), optional
        Group labels for the samples used while splitting the dataset into
        train/test set.

    Returns
    -------
    n_splits : int
        Returns the number of splitting iterations in the cross-validator.
    """
    if groups is None:
        raise ValueError("The groups parameter should not be None")
    return int(comb(len(np.unique(groups)), self.n_groups, exact=True))


# Traceback (ImportError)
In [3]: from sklearn.model_selection import train_test_split
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-3-139cc3505715> in <module>()
----> 1 from sklearn.model_selection import train_test_split

/usr/local/lib/python2.7/dist-packages/sklearn/model_selection/__init__.py in <module>()
15 from ._split import check_cv
16
---> 17 from ._validation import cross_val_score
18 from ._validation import cross_val_predict
19 from ._validation import learning_curve

/usr/local/lib/python2.7/dist-packages/sklearn/model_selection/_validation.py in <module>()
25 from ..utils.fixes import astype
26 from ..utils.validation import _is_arraylike, _num_samples
---> 27 from ..utils.metaestimators import _safe_split
28 from ..externals.joblib import Parallel, delayed, logger
29 from ..metrics.scorer import check_scoring

ImportError: cannot import name _safe_split

# Fixed code
def get_n_splits(self, X, y, groups):
    """Returns the number of splitting iterations in the cross-validator

    Parameters
    ----------
    X : object
        Always ignored, exists for compatibility.
        ``np.zeros(n_samples)`` may be used as a placeholder.

    y : object
        Always ignored, exists for compatibility.
        ``np.zeros(n_samples)`` may be used as a placeholder.

    groups : array-like, with shape (n_samples,), optional
        Group labels for the samples used while splitting the dataset into
        train/test set.

    Returns
    -------
    n_splits : int
        Returns the number of splitting iterations in the cross-validator.
    """
    if groups is None:
        raise ValueError("The groups parameter should not be None")
    groups = check_array(groups, ensure_2d=False, dtype=None)
    X, y, groups = indexable(X, y, groups)
    return int(comb(len(np.unique(groups)), self.n_groups, exact=True))
# Buggy code
def _iter_indices(self, X, y, groups):
    if groups is None:
        raise ValueError("The groups parameter should not be None")
    classes, group_indices = np.unique(groups, return_inverse=True)
    for group_train, group_test in super(GroupShuffleSplit, self)._iter_indices(
        X=classes
    ):
        # these are the indices of classes in the partition
        # invert them into data indices

        train = np.flatnonzero(np.in1d(group_indices, group_train))
        test = np.flatnonzero(np.in1d(group_indices, group_test))

        yield train, test


# Traceback (ImportError)
In [3]: from sklearn.model_selection import train_test_split
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-3-139cc3505715> in <module>()
----> 1 from sklearn.model_selection import train_test_split

/usr/local/lib/python2.7/dist-packages/sklearn/model_selection/__init__.py in <module>()
15 from ._split import check_cv
16
---> 17 from ._validation import cross_val_score
18 from ._validation import cross_val_predict
19 from ._validation import learning_curve

/usr/local/lib/python2.7/dist-packages/sklearn/model_selection/_validation.py in <module>()
25 from ..utils.fixes import astype
26 from ..utils.validation import _is_arraylike, _num_samples
---> 27 from ..utils.metaestimators import _safe_split
28 from ..externals.joblib import Parallel, delayed, logger
29 from ..metrics.scorer import check_scoring

ImportError: cannot import name _safe_split

# Fixed code
def _iter_indices(self, X, y, groups):
    if groups is None:
        raise ValueError("The groups parameter should not be None")
    groups = check_array(groups, ensure_2d=False, dtype=None)
    classes, group_indices = np.unique(groups, return_inverse=True)
    for group_train, group_test in super(GroupShuffleSplit, self)._iter_indices(
        X=classes
    ):
        # these are the indices of classes in the partition
        # invert them into data indices

        train = np.flatnonzero(np.in1d(group_indices, group_train))
        test = np.flatnonzero(np.in1d(group_indices, group_test))

        yield train, test
# Buggy code
def split(self, X, y, groups=None):
    """Generate indices to split data into training and test set.

    Parameters
    ----------
    X : array-like, shape (n_samples, n_features)
        Training data, where n_samples is the number of samples
        and n_features is the number of features.

    y : array-like, shape (n_samples,)
        The target variable for supervised learning problems.

    groups : array-like, with shape (n_samples,), optional
        Group labels for the samples used while splitting the dataset into
        train/test set.

    Returns
    -------
    train : ndarray
        The training set indices for that split.

    test : ndarray
        The testing set indices for that split.
    """
    return super(StratifiedShuffleSplit, self).split(X, y, groups)


# Traceback (ImportError)
In [3]: from sklearn.model_selection import train_test_split
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-3-139cc3505715> in <module>()
----> 1 from sklearn.model_selection import train_test_split

/usr/local/lib/python2.7/dist-packages/sklearn/model_selection/__init__.py in <module>()
15 from ._split import check_cv
16
---> 17 from ._validation import cross_val_score
18 from ._validation import cross_val_predict
19 from ._validation import learning_curve

/usr/local/lib/python2.7/dist-packages/sklearn/model_selection/_validation.py in <module>()
25 from ..utils.fixes import astype
26 from ..utils.validation import _is_arraylike, _num_samples
---> 27 from ..utils.metaestimators import _safe_split
28 from ..externals.joblib import Parallel, delayed, logger
29 from ..metrics.scorer import check_scoring

ImportError: cannot import name _safe_split

# Fixed code
def split(self, X, y, groups=None):
    """Generate indices to split data into training and test set.

    Parameters
    ----------
    X : array-like, shape (n_samples, n_features)
        Training data, where n_samples is the number of samples
        and n_features is the number of features.

        Note that providing ``y`` is sufficient to generate the splits and
        hence ``np.zeros(n_samples)`` may be used as a placeholder for
        ``X`` instead of actual training data.

    y : array-like, shape (n_samples,)
        The target variable for supervised learning problems.
        Stratification is done based on the y labels.

    groups : object
        Always ignored, exists for compatibility.

    Returns
    -------
    train : ndarray
        The training set indices for that split.

    test : ndarray
        The testing set indices for that split.
    """
    y = check_array(y, ensure_2d=False, dtype=None)
    return super(StratifiedShuffleSplit, self).split(X, y, groups)
# Buggy code
def _validate_input(self, X, y, incremental):
    X, y = check_X_y(X, y, accept_sparse=["csr", "csc", "coo"], multi_output=True)
    if y.ndim == 2 and y.shape[1] == 1:
        y = column_or_1d(y, warn=True)
    self.label_binarizer_.fit(y)

    if not hasattr(self, "classes_") or not incremental:
        self.classes_ = self.label_binarizer_.classes_
    else:
        classes = self.label_binarizer_.classes_
        if not np.all(np.in1d(classes, self.classes_)):
            raise ValueError(
                "`y` has classes not in `self.classes_`."
                " `self.classes_` has %s. 'y' has %s." % (self.classes_, classes)
            )

    y = self.label_binarizer_.transform(y)
    return X, y


# Traceback (ValueError)
Traceback (most recent call last):
File "fail.py", line 7, in <module>
clf.partial_fit([[4]],["d"])
File "/usr/local/lib/python3.4/dist-packages/sklearn/neural_network/multilayer_perceptron.py", line 989, in _partial_fit
super(MLPClassifier, self)._partial_fit(X, y)
File "/usr/local/lib/python3.4/dist-packages/sklearn/neural_network/multilayer_perceptron.py", line 640, in _partial_fit
return self._fit(X, y, incremental=True)
File "/usr/local/lib/python3.4/dist-packages/sklearn/neural_network/multilayer_perceptron.py", line 375, in _fit
intercept_grads, layer_units, incremental)
File "/usr/local/lib/python3.4/dist-packages/sklearn/neural_network/multilayer_perceptron.py", line 512, in _fit_stochastic
coef_grads, intercept_grads)
File "/usr/local/lib/python3.4/dist-packages/sklearn/neural_network/multilayer_perceptron.py", line 225, in _backprop
loss = LOSS_FUNCTIONS[self.loss](y, activations[-1])
File "/usr/local/lib/python3.4/dist-packages/sklearn/neural_network/_base.py", line 208, in log_loss
return -np.sum(y_true * np.log(y_prob)) / y_prob.shape[0]
ValueError: operands could not be broadcast together with shapes (1,2) (1,3)

# Fixed code
def _validate_input(self, X, y, incremental):
    X, y = check_X_y(X, y, accept_sparse=["csr", "csc", "coo"], multi_output=True)
    if y.ndim == 2 and y.shape[1] == 1:
        y = column_or_1d(y, warn=True)

    if not incremental:
        self._label_binarizer = LabelBinarizer()
        self._label_binarizer.fit(y)
        self.classes_ = self._label_binarizer.classes_
    else:
        classes = unique_labels(y)
        if np.setdiff1d(classes, self.classes_, assume_unique=True):
            raise ValueError(
                "`y` has classes not in `self.classes_`."
                " `self.classes_` has %s. 'y' has %s." % (self.classes_, classes)
            )

    y = self._label_binarizer.transform(y)
    return X, y
# Buggy code
def predict(self, X):
    """Predict using the multi-layer perceptron classifier

    Parameters
    ----------
    X : {array-like, sparse matrix}, shape (n_samples, n_features)
        The input data.

    Returns
    -------
    y : array-like, shape (n_samples,) or (n_samples, n_classes)
        The predicted classes.
    """
    check_is_fitted(self, "coefs_")
    y_pred = self._predict(X)

    if self.n_outputs_ == 1:
        y_pred = y_pred.ravel()

    return self.label_binarizer_.inverse_transform(y_pred)


# Traceback (ValueError)
Traceback (most recent call last):
File "fail.py", line 7, in <module>
clf.partial_fit([[4]],["d"])
File "/usr/local/lib/python3.4/dist-packages/sklearn/neural_network/multilayer_perceptron.py", line 989, in _partial_fit
super(MLPClassifier, self)._partial_fit(X, y)
File "/usr/local/lib/python3.4/dist-packages/sklearn/neural_network/multilayer_perceptron.py", line 640, in _partial_fit
return self._fit(X, y, incremental=True)
File "/usr/local/lib/python3.4/dist-packages/sklearn/neural_network/multilayer_perceptron.py", line 375, in _fit
intercept_grads, layer_units, incremental)
File "/usr/local/lib/python3.4/dist-packages/sklearn/neural_network/multilayer_perceptron.py", line 512, in _fit_stochastic
coef_grads, intercept_grads)
File "/usr/local/lib/python3.4/dist-packages/sklearn/neural_network/multilayer_perceptron.py", line 225, in _backprop
loss = LOSS_FUNCTIONS[self.loss](y, activations[-1])
File "/usr/local/lib/python3.4/dist-packages/sklearn/neural_network/_base.py", line 208, in log_loss
return -np.sum(y_true * np.log(y_prob)) / y_prob.shape[0]
ValueError: operands could not be broadcast together with shapes (1,2) (1,3)

# Fixed code
def predict(self, X):
    """Predict using the multi-layer perceptron classifier

    Parameters
    ----------
    X : {array-like, sparse matrix}, shape (n_samples, n_features)
        The input data.

    Returns
    -------
    y : array-like, shape (n_samples,) or (n_samples, n_classes)
        The predicted classes.
    """
    check_is_fitted(self, "coefs_")
    y_pred = self._predict(X)

    if self.n_outputs_ == 1:
        y_pred = y_pred.ravel()

    return self._label_binarizer.inverse_transform(y_pred)