# Buggy code
def fetch(self, *tileables, **kw):
    ret_list = False
    if len(tileables) == 1 and isinstance(tileables[0], (tuple, list)):
        ret_list = True
        tileables = tileables[0]
    elif len(tileables) > 1:
        ret_list = True

    result = self._sess.fetch(*tileables, **kw)

    ret = []
    for r, t in zip(result, tileables):
        if hasattr(t, "isscalar") and t.isscalar() and hasattr(r, "item"):
            ret.append(r.item())
        else:
            ret.append(r)
    if ret_list:
        return ret
    return ret[0]


# Traceback (ValueError)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
~/.local/lib/python3.6/site-packages/IPython/core/formatters.py in __call__(self, obj)
700                 type_pprinters=self.type_printers,
701                 deferred_pprinters=self.deferred_printers)
--> 702             printer.pretty(obj)
703             printer.flush()
704             return stream.getvalue()

~/.local/lib/python3.6/site-packages/IPython/lib/pretty.py in pretty(self, obj)
392                         if cls is not object \
393                                 and callable(cls.__dict__.get('__repr__')):
--> 394                             return _repr_pprint(obj, self, cycle)
395
396             return _default_pprint(obj, self, cycle)

~/.local/lib/python3.6/site-packages/IPython/lib/pretty.py in _repr_pprint(obj, p, cycle)
682     """A pprint that just redirects to the normal repr function."""
683     # Find newlines and replace them with p.break_()
--> 684     output = repr(obj)
685     lines = output.splitlines()
686     with p.group():

~/.local/lib/python3.6/site-packages/mars/core.py in __repr__(self)
127
128     def __repr__(self):
--> 129         return self._data.__repr__()
130
131     def _check_data(self, data):

~/.local/lib/python3.6/site-packages/mars/tensor/core.py in __repr__(self)
177
178     def __repr__(self):
--> 179         return self._to_str(representation=True)
180
181     @property

~/.local/lib/python3.6/site-packages/mars/tensor/core.py in _to_str(self, representation)
165             threshold = print_options['threshold']
166
--> 167             corner_data = fetch_corner_data(self, session=self._executed_sessions[-1])
168             # if less than default threshold, just set it as default,
169             # if not, set to corner_data.size - 1 make sure ... exists in repr

~/.local/lib/python3.6/site-packages/mars/tensor/utils.py in fetch_corner_data(tensor, session)
824         return np.block(corners.tolist())
825     else:
--> 826         return tensor.fetch(session=session)

~/.local/lib/python3.6/site-packages/mars/core.py in fetch(self, session, **kw)
373         if session is None:
374             session = Session.default_or_local()
--> 375         return session.fetch(self, **kw)
376
377     def _attach_session(self, session):

~/.local/lib/python3.6/site-packages/mars/session.py in fetch(self, *tileables, **kw)
494         for r, t in zip(result, tileables):
495             if hasattr(t, 'isscalar') and t.isscalar() and hasattr(r, 'item'):
--> 496                 ret.append(r.item())
497             else:
498                 ret.append(r)

ValueError: can only convert an array of size 1 to a Python scalar

# Fixed code
def fetch(self, *tileables, **kw):
    ret_list = False
    if len(tileables) == 1 and isinstance(tileables[0], (tuple, list)):
        ret_list = True
        tileables = tileables[0]
    elif len(tileables) > 1:
        ret_list = True

    result = self._sess.fetch(*tileables, **kw)

    ret = []
    for r, t in zip(result, tileables):
        if hasattr(t, "isscalar") and t.isscalar() and getattr(r, "size", None) == 1:
            ret.append(r.item())
        else:
            ret.append(r)
    if ret_list:
        return ret
    return ret[0]