# Buggy code
def tile(cls, op):
    y_true, y_pred = op.y_true, op.y_pred
    for y in (op.y_true, op.y_pred):
        if isinstance(y, (Base, Entity)):
            if np.isnan(y.size):  # pragma: no cover
                raise TilesError("input has unknown shape")

    check_consistent_length(y_true, y_pred)

    ctx = get_context()
    try:
        type_true, type_pred = ctx.get_chunk_results(
            [op.type_true.chunks[0].key, op.type_pred.chunks[0].key]
        )
    except KeyError:
        raise TilesError("type_true and type_pred needs to be executed first")

    y_type = {type_true, type_pred}
    if y_type == {"binary", "multiclass"}:
        y_type = {"multiclass"}

    if len(y_type) > 1:
        raise ValueError(
            f"Classification metrics can't handle a mix of {type_true} "
            f"and {type_pred} targets"
        )

    # We can't have more than one value on y_type => The set is no more needed
    y_type = y_type.pop()

    # No metrics support "multiclass-multioutput" format
    if y_type not in ["binary", "multiclass", "multilabel-indicator"]:
        raise ValueError(f"{y_type} is not supported")

    if y_type in ["binary", "multiclass"]:
        y_true = column_or_1d(y_true)
        y_pred = column_or_1d(y_pred)
        if y_type == "binary":
            unique_values = mt.union1d(y_true, y_pred)
            y_type = mt.where(mt.count_nonzero(unique_values) > 2, "multiclass", y_type)
    elif y_type.startswith("multilabel"):
        y_true = mt.tensor(y_true).tosparse()
        y_pred = mt.tensor(y_pred).tosparse()
        y_type = "multilabel-indicator"

    if not isinstance(y_true, (Base, Entity)):
        y_true = mt.tensor(y_true)
    if not isinstance(y_pred, (Base, Entity)):
        y_pred = mt.tensor(y_pred)

    if not isinstance(y_type, TENSOR_TYPE):
        y_type = mt.tensor(y_type, dtype=object)

    y_type = recursive_tile(y_type)
    y_true = recursive_tile(y_true)
    y_pred = recursive_tile(y_pred)

    kws = [out.params for out in op.outputs]
    kws[0].update(dict(nsplits=(), chunks=[y_type.chunks[0]]))
    kws[1].update(
        dict(
            nsplits=y_true.nsplits,
            chunks=y_true.chunks,
            shape=tuple(sum(sp) for sp in y_true.nsplits),
        )
    )
    kws[2].update(
        dict(
            nsplits=y_pred.nsplits,
            chunks=y_pred.chunks,
            shape=tuple(sum(sp) for sp in y_pred.nsplits),
        )
    )
    new_op = op.copy()
    return new_op.new_tileables(op.inputs, kws=kws)


# Traceback (ValueError)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-52-f2912f2e33a0> in <module>
1 from mars.learn.metrics import accuracy_score
----> 2 accuracy_score(y_test,y_pred).execute()

/home/tops/lib/python3.6/site-packages/mars/learn/metrics/_classification.py in accuracy_score(y_true, y_pred, normalize, sample_weight, session, run_kwargs)
178     op = AccuracyScore(y_true=y_true, y_pred=y_pred, normalize=normalize,
179                        sample_weight=sample_weight)
--> 180     score = op(y_true, y_pred)
181     return score.execute(session=session, **(run_kwargs or dict()))

/home/tops/lib/python3.6/site-packages/mars/utils.py in _inner(*args, **kwargs)
455         def _inner(*args, **kwargs):
456             with self:
--> 457                 return func(*args, **kwargs)
458
459         return _inner

/home/tops/lib/python3.6/site-packages/mars/learn/metrics/_classification.py in __call__(self, y_true, y_pred)
76
77     def __call__(self, y_true, y_pred):
---> 78         type_true, y_true, y_pred = _check_targets(y_true, y_pred)
79         self._type_true = type_true
80         inputs = [y_true, y_pred, type_true]

/home/tops/lib/python3.6/site-packages/mars/learn/metrics/_check_targets.py in _check_targets(y_true, y_pred)
193     """
194     op = CheckTargets(y_true=y_true, y_pred=y_pred)
--> 195     return op(y_true, y_pred)

/home/tops/lib/python3.6/site-packages/mars/utils.py in _inner(*args, **kwargs)
455         def _inner(*args, **kwargs):
456             with self:
--> 457                 return func(*args, **kwargs)
458
459         return _inner

/home/tops/lib/python3.6/site-packages/mars/learn/metrics/_check_targets.py in __call__(self, y_true, y_pred)
82         if isinstance(y_pred, (Base, Entity)):
83             inputs.append(y_pred)
---> 84         self._type_true = type_of_target(y_true)
85         self._type_pred = type_of_target(y_pred)
86         inputs.extend([self._type_true, self._type_pred])

/home/tops/lib/python3.6/site-packages/mars/learn/utils/multiclass.py in type_of_target(y)
403
404     if not valid:
--> 405         raise ValueError(f'Expected array-like (array or non-string sequence), got {y}')
406
407     sparse_pandas = (y.__class__.__name__ in ['SparseSeries', 'SparseArray'])

ValueError: Expected array-like (array or non-string sequence), got 159615    0
134010    0
199100    0
137756    0
200050    0
..
219880    0
82326     0
184439    0
198518    0
109959    0
Name: label_bigint, Length: 1146788, dtype: int64

# Fixed code
def tile(cls, op):
    y_true, y_pred = op.y_true, op.y_pred
    for y in (op.y_true, op.y_pred):
        if isinstance(y, (Base, Entity)):
            if np.isnan(y.size):  # pragma: no cover
                raise TilesError("input has unknown shape")

    check_consistent_length(y_true, y_pred)

    ctx = get_context()
    try:
        type_true, type_pred = ctx.get_chunk_results(
            [op.type_true.chunks[0].key, op.type_pred.chunks[0].key]
        )
    except (KeyError, AttributeError):
        raise TilesError("type_true and type_pred needs to be executed first")

    y_type = {type_true, type_pred}
    if y_type == {"binary", "multiclass"}:
        y_type = {"multiclass"}

    if len(y_type) > 1:
        raise ValueError(
            f"Classification metrics can't handle a mix of {type_true} "
            f"and {type_pred} targets"
        )

    # We can't have more than one value on y_type => The set is no more needed
    y_type = y_type.pop()

    # No metrics support "multiclass-multioutput" format
    if y_type not in ["binary", "multiclass", "multilabel-indicator"]:
        raise ValueError(f"{y_type} is not supported")

    if y_type in ["binary", "multiclass"]:
        y_true = column_or_1d(y_true)
        y_pred = column_or_1d(y_pred)
        if y_type == "binary":
            unique_values = mt.union1d(y_true, y_pred)
            y_type = mt.where(mt.count_nonzero(unique_values) > 2, "multiclass", y_type)
    elif y_type.startswith("multilabel"):
        y_true = mt.tensor(y_true).tosparse()
        y_pred = mt.tensor(y_pred).tosparse()
        y_type = "multilabel-indicator"

    if not isinstance(y_true, (Base, Entity)):
        y_true = mt.tensor(y_true)
    if not isinstance(y_pred, (Base, Entity)):
        y_pred = mt.tensor(y_pred)

    if not isinstance(y_type, TENSOR_TYPE):
        y_type = mt.tensor(y_type, dtype=object)

    y_type = recursive_tile(y_type)
    y_true = recursive_tile(y_true)
    y_pred = recursive_tile(y_pred)

    kws = [out.params for out in op.outputs]
    kws[0].update(dict(nsplits=(), chunks=[y_type.chunks[0]]))
    kws[1].update(
        dict(
            nsplits=y_true.nsplits,
            chunks=y_true.chunks,
            shape=tuple(sum(sp) for sp in y_true.nsplits),
        )
    )
    kws[2].update(
        dict(
            nsplits=y_pred.nsplits,
            chunks=y_pred.chunks,
            shape=tuple(sum(sp) for sp in y_pred.nsplits),
        )
    )
    new_op = op.copy()
    return new_op.new_tileables(op.inputs, kws=kws)