gurudesh/pytracebugs huggingface dataset:
# Buggy code
def execute(cls, ctx, op):
    chunk = op.outputs[0]
    ctx[chunk.key] = pd.DataFrame.from_records(
        ctx[op.inputs[0].key],
        index=chunk.index_value.to_pandas(),
        columns=chunk.columns.to_pandas(),
        exclude=op.exclude,
        coerce_float=op.coerce_float,
        nrows=op.nrows,
    )


# Traceback (Exception)
In [28]: df = md.DataFrame(np.random.rand(10, 2))

In [29]: df + np.random.rand(10, 2)
---------------------------------------------------------------------------
Exception                                 Traceback (most recent call last)
<ipython-input-29-4a212df011a8> in <module>
----> 1 df + np.random.rand(10, 2)

~/Documents/mars_dev/mars/mars/dataframe/utils.py in wrapper(*args, **kwargs)
613     def wrapper(*args, **kwargs):
614         try:
--> 615             return func(*args, **kwargs)
616         except NotImplementedError:
617             return NotImplemented

~/Documents/mars_dev/mars/mars/dataframe/arithmetic/add.py in add(df, other, axis, level, fill_value)
33
34 def add(df, other, axis='columns', level=None, fill_value=None):
---> 35     other = wrap_sequence(other)
36     op = DataFrameAdd(axis=axis, level=level, fill_value=fill_value, lhs=df, rhs=other)
37     return op(df, other)

~/Documents/mars_dev/mars/mars/dataframe/utils.py in wrap_sequence(seq)
606
607     if isinstance(seq, (list, tuple, np.ndarray, TENSOR_TYPE)):
--> 608         seq = Series(seq)
609     return seq
610

~/Documents/mars_dev/mars/mars/dataframe/initializer.py in __init__(self, data, index, dtype, name, copy, chunk_size, gpu, sparse)
46             series = data
47         else:
---> 48             pd_series = pd.Series(data, index=index, dtype=dtype, name=name, copy=copy)
49             series = from_pandas_series(pd_series, chunk_size=chunk_size, gpu=gpu, sparse=sparse)
50         super(Series, self).__init__(series.data)

~/miniconda3/lib/python3.7/site-packages/pandas/core/series.py in __init__(self, data, index, dtype, name, copy, fastpath)
312                     data = data.copy()
313             else:
--> 314                 data = sanitize_array(data, index, dtype, copy, raise_cast_failure=True)
315
316                 data = SingleBlockManager(data, index, fastpath=True)

~/miniconda3/lib/python3.7/site-packages/pandas/core/internals/construction.py in sanitize_array(data, index, dtype, copy, raise_cast_failure)
727     elif subarr.ndim > 1:
728         if isinstance(data, np.ndarray):
--> 729             raise Exception("Data must be 1-dimensional")
730         else:
731             subarr = com.asarray_tuplesafe(data, dtype=dtype)

Exception: Data must be 1-dimensional

# Fixed code
def execute(cls, ctx, op):
    chunk = op.outputs[0]
    ctx[chunk.key] = pd.DataFrame.from_records(
        ctx[op.inputs[0].key],
        index=chunk.index_value.to_pandas(),
        columns=chunk.columns_value.to_pandas(),
        exclude=op.exclude,
        coerce_float=op.coerce_float,
        nrows=op.nrows,
    )
# Buggy code
def execute(cls, ctx, op):
    chunk = op.outputs[0]
    tensor_data = ctx[op.inputs[0].key]
    ctx[chunk.key] = pd.DataFrame(
        tensor_data,
        index=chunk.index_value.to_pandas(),
        columns=chunk.columns.to_pandas(),
    )


# Traceback (Exception)
In [28]: df = md.DataFrame(np.random.rand(10, 2))

In [29]: df + np.random.rand(10, 2)
---------------------------------------------------------------------------
Exception                                 Traceback (most recent call last)
<ipython-input-29-4a212df011a8> in <module>
----> 1 df + np.random.rand(10, 2)

~/Documents/mars_dev/mars/mars/dataframe/utils.py in wrapper(*args, **kwargs)
613     def wrapper(*args, **kwargs):
614         try:
--> 615             return func(*args, **kwargs)
616         except NotImplementedError:
617             return NotImplemented

~/Documents/mars_dev/mars/mars/dataframe/arithmetic/add.py in add(df, other, axis, level, fill_value)
33
34 def add(df, other, axis='columns', level=None, fill_value=None):
---> 35     other = wrap_sequence(other)
36     op = DataFrameAdd(axis=axis, level=level, fill_value=fill_value, lhs=df, rhs=other)
37     return op(df, other)

~/Documents/mars_dev/mars/mars/dataframe/utils.py in wrap_sequence(seq)
606
607     if isinstance(seq, (list, tuple, np.ndarray, TENSOR_TYPE)):
--> 608         seq = Series(seq)
609     return seq
610

~/Documents/mars_dev/mars/mars/dataframe/initializer.py in __init__(self, data, index, dtype, name, copy, chunk_size, gpu, sparse)
46             series = data
47         else:
---> 48             pd_series = pd.Series(data, index=index, dtype=dtype, name=name, copy=copy)
49             series = from_pandas_series(pd_series, chunk_size=chunk_size, gpu=gpu, sparse=sparse)
50         super(Series, self).__init__(series.data)

~/miniconda3/lib/python3.7/site-packages/pandas/core/series.py in __init__(self, data, index, dtype, name, copy, fastpath)
312                     data = data.copy()
313             else:
--> 314                 data = sanitize_array(data, index, dtype, copy, raise_cast_failure=True)
315
316                 data = SingleBlockManager(data, index, fastpath=True)

~/miniconda3/lib/python3.7/site-packages/pandas/core/internals/construction.py in sanitize_array(data, index, dtype, copy, raise_cast_failure)
727     elif subarr.ndim > 1:
728         if isinstance(data, np.ndarray):
--> 729             raise Exception("Data must be 1-dimensional")
730         else:
731             subarr = com.asarray_tuplesafe(data, dtype=dtype)

Exception: Data must be 1-dimensional

# Fixed code
def execute(cls, ctx, op):
    chunk = op.outputs[0]
    tensor_data = ctx[op.inputs[0].key]
    ctx[chunk.key] = pd.DataFrame(
        tensor_data,
        index=chunk.index_value.to_pandas(),
        columns=chunk.columns_value.to_pandas(),
    )
# Buggy code
def __call__(self, df):
    if isinstance(self.indexes[0], TENSOR_TYPE) or isinstance(
        self.indexes[1], TENSOR_TYPE
    ):
        raise NotImplementedError("The index value cannot be unexecuted mars tensor")
    return self.new_dataframe(
        [df],
        shape=df.shape,
        dtypes=df.dtypes,
        index_value=df.index_value,
        columns_value=df.columns,
    )


# Traceback (Exception)
In [28]: df = md.DataFrame(np.random.rand(10, 2))

In [29]: df + np.random.rand(10, 2)
---------------------------------------------------------------------------
Exception                                 Traceback (most recent call last)
<ipython-input-29-4a212df011a8> in <module>
----> 1 df + np.random.rand(10, 2)

~/Documents/mars_dev/mars/mars/dataframe/utils.py in wrapper(*args, **kwargs)
613     def wrapper(*args, **kwargs):
614         try:
--> 615             return func(*args, **kwargs)
616         except NotImplementedError:
617             return NotImplemented

~/Documents/mars_dev/mars/mars/dataframe/arithmetic/add.py in add(df, other, axis, level, fill_value)
33
34 def add(df, other, axis='columns', level=None, fill_value=None):
---> 35     other = wrap_sequence(other)
36     op = DataFrameAdd(axis=axis, level=level, fill_value=fill_value, lhs=df, rhs=other)
37     return op(df, other)

~/Documents/mars_dev/mars/mars/dataframe/utils.py in wrap_sequence(seq)
606
607     if isinstance(seq, (list, tuple, np.ndarray, TENSOR_TYPE)):
--> 608         seq = Series(seq)
609     return seq
610

~/Documents/mars_dev/mars/mars/dataframe/initializer.py in __init__(self, data, index, dtype, name, copy, chunk_size, gpu, sparse)
46             series = data
47         else:
---> 48             pd_series = pd.Series(data, index=index, dtype=dtype, name=name, copy=copy)
49             series = from_pandas_series(pd_series, chunk_size=chunk_size, gpu=gpu, sparse=sparse)
50         super(Series, self).__init__(series.data)

~/miniconda3/lib/python3.7/site-packages/pandas/core/series.py in __init__(self, data, index, dtype, name, copy, fastpath)
312                     data = data.copy()
313             else:
--> 314                 data = sanitize_array(data, index, dtype, copy, raise_cast_failure=True)
315
316                 data = SingleBlockManager(data, index, fastpath=True)

~/miniconda3/lib/python3.7/site-packages/pandas/core/internals/construction.py in sanitize_array(data, index, dtype, copy, raise_cast_failure)
727     elif subarr.ndim > 1:
728         if isinstance(data, np.ndarray):
--> 729             raise Exception("Data must be 1-dimensional")
730         else:
731             subarr = com.asarray_tuplesafe(data, dtype=dtype)

Exception: Data must be 1-dimensional

# Fixed code
def __call__(self, df):
    if isinstance(self.indexes[0], TENSOR_TYPE) or isinstance(
        self.indexes[1], TENSOR_TYPE
    ):
        raise NotImplementedError("The index value cannot be unexecuted mars tensor")
    return self.new_dataframe(
        [df],
        shape=df.shape,
        dtypes=df.dtypes,
        index_value=df.index_value,
        columns_value=df.columns_value,
    )
# Buggy code
def _get_kw(obj):
    if isinstance(obj, TENSOR_TYPE + TENSOR_CHUNK_TYPE):
        return {"shape": obj.shape, "dtype": obj.dtype, "order": obj.order}
    else:
        return {
            "shape": obj.shape,
            "dtypes": obj.dtypes,
            "index_value": obj.index_value,
            "columns_value": obj.columns,
        }


# Traceback (Exception)
In [28]: df = md.DataFrame(np.random.rand(10, 2))

In [29]: df + np.random.rand(10, 2)
---------------------------------------------------------------------------
Exception                                 Traceback (most recent call last)
<ipython-input-29-4a212df011a8> in <module>
----> 1 df + np.random.rand(10, 2)

~/Documents/mars_dev/mars/mars/dataframe/utils.py in wrapper(*args, **kwargs)
613     def wrapper(*args, **kwargs):
614         try:
--> 615             return func(*args, **kwargs)
616         except NotImplementedError:
617             return NotImplemented

~/Documents/mars_dev/mars/mars/dataframe/arithmetic/add.py in add(df, other, axis, level, fill_value)
33
34 def add(df, other, axis='columns', level=None, fill_value=None):
---> 35     other = wrap_sequence(other)
36     op = DataFrameAdd(axis=axis, level=level, fill_value=fill_value, lhs=df, rhs=other)
37     return op(df, other)

~/Documents/mars_dev/mars/mars/dataframe/utils.py in wrap_sequence(seq)
606
607     if isinstance(seq, (list, tuple, np.ndarray, TENSOR_TYPE)):
--> 608         seq = Series(seq)
609     return seq
610

~/Documents/mars_dev/mars/mars/dataframe/initializer.py in __init__(self, data, index, dtype, name, copy, chunk_size, gpu, sparse)
46             series = data
47         else:
---> 48             pd_series = pd.Series(data, index=index, dtype=dtype, name=name, copy=copy)
49             series = from_pandas_series(pd_series, chunk_size=chunk_size, gpu=gpu, sparse=sparse)
50         super(Series, self).__init__(series.data)

~/miniconda3/lib/python3.7/site-packages/pandas/core/series.py in __init__(self, data, index, dtype, name, copy, fastpath)
312                     data = data.copy()
313             else:
--> 314                 data = sanitize_array(data, index, dtype, copy, raise_cast_failure=True)
315
316                 data = SingleBlockManager(data, index, fastpath=True)

~/miniconda3/lib/python3.7/site-packages/pandas/core/internals/construction.py in sanitize_array(data, index, dtype, copy, raise_cast_failure)
727     elif subarr.ndim > 1:
728         if isinstance(data, np.ndarray):
--> 729             raise Exception("Data must be 1-dimensional")
730         else:
731             subarr = com.asarray_tuplesafe(data, dtype=dtype)

Exception: Data must be 1-dimensional

# Fixed code
def _get_kw(obj):
    if isinstance(obj, TENSOR_TYPE + TENSOR_CHUNK_TYPE):
        return {"shape": obj.shape, "dtype": obj.dtype, "order": obj.order}
    else:
        return {
            "shape": obj.shape,
            "dtypes": obj.dtypes,
            "index_value": obj.index_value,
            "columns_value": obj.columns_value,
        }
# Buggy code
def has_value(self):
    if isinstance(self._index_value, self.RangeIndex):
        return True
    elif getattr(self, "_data", None) is not None:
        return True
    return False


# Traceback (TypeError)
In [1]: import mars.dataframe as md

In [2]: import mars.tensor as mt

In [3]: df = md.DataFrame(mt.random.rand(10, 3), columns=list('abc'))
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-3-8015891094de> in <module>
----> 1 df = md.DataFrame(mt.random.rand(10, 3), columns=list('abc'))

~/Workspace/mars/mars/dataframe/initializer.py in __init__(self, data, index, columns, dtype, copy, chunk_size, gpu, sparse)
29                  chunk_size=None, gpu=None, sparse=None):
30         if isinstance(data, TENSOR_TYPE):
---> 31             df = from_tensor(data, index=index, columns=columns, gpu=gpu, sparse=sparse)
32         elif isinstance(data, DATAFRAME_TYPE):
33             df = data

~/Workspace/mars/mars/dataframe/datasource/from_tensor.py in from_tensor(tensor, index, columns, gpu, sparse)
135     gpu = tensor.op.gpu if gpu is None else gpu
136     op = DataFrameFromTensor(dtypes=pd.Series([tensor.dtype] * col_num), gpu=gpu, sparse=sparse)
--> 137     return op(tensor, index, columns)

~/Workspace/mars/mars/dataframe/datasource/from_tensor.py in __call__(self, input_tensor, index, columns)
51     def __call__(self, input_tensor, index, columns):
52         if index is not None or columns is not None:
---> 53             if input_tensor.shape != (len(index), len(columns)):
54                 raise ValueError(
55                     '({0},{1}) should have the same shape with tensor: {2}'.format(index, columns, input_tensor.shape))

TypeError: object of type 'NoneType' has no len()

# Fixed code
def has_value(self):
    if isinstance(self._index_value, self.RangeIndex):
        return True
    elif getattr(self._index_value, "_data", None) is not None:
        return True
    return False
# Buggy code
def submit_graph(self, session_id, serialized_graph, graph_key, target, compose=True):
    session_uid = SessionActor.gen_uid(session_id)
    session_ref = self.get_actor_ref(session_uid)
    session_ref.submit_tileable_graph(
        serialized_graph, graph_key, target, compose=compose, _tell=True
    )


# Traceback (ValueError)
500 GET /worker?endpoint
Traceback (most recent call last):
File "/opt/conda/lib/python3.6/site-packages/tornado/web.py", line 1592, in _execute
result = yield result
File "/opt/conda/lib/python3.6/site-packages/tornado/gen.py", line 1133, in run
value = future.result()
File "/opt/conda/lib/python3.6/site-packages/tornado/gen.py", line 1147, in run
yielded = self.gen.send(value)
File "/opt/conda/lib/python3.6/site-packages/bokeh/server/views/doc_handler.py", line 27, in get
template_variables=session.document.template_variables)
File "/opt/conda/lib/python3.6/site-packages/bokeh/embed/server.py", line 230, in server_html_page_for_session
template=template, template_variables=template_variables)
File "/opt/conda/lib/python3.6/site-packages/bokeh/embed/elements.py", line 133, in html_page_for_render_items
html = template.render(context)
File "/opt/conda/lib/python3.6/site-packages/jinja2/asyncsupport.py", line 76, in render
return original_render(self, *args, **kwargs)
File "/opt/conda/lib/python3.6/site-packages/jinja2/environment.py", line 1008, in render
return self.environment.handle_exception(exc_info, True)
File "/opt/conda/lib/python3.6/site-packages/jinja2/environment.py", line 780, in handle_exception
reraise(exc_type, exc_value, tb)
File "/opt/conda/lib/python3.6/site-packages/jinja2/_compat.py", line 37, in reraise
raise value.with_traceback(tb)
File "/home/admin/work/public-mars-0.2.0b1-cupid.zip/mars/web/templates/worker_detail.html", line 1, in top-level template code
{% extends "base.html" %}
File "/home/admin/work/public-mars-0.2.0b1-cupid.zip/mars/web/templates/base.html", line 65, in top-level template code
{% block body %}{% endblock %}
File "/home/admin/work/public-mars-0.2.0b1-cupid.zip/mars/web/templates/worker_detail.html", line 252, in block "body"
<td>{{ stats['min_est_finish_time'] | format_ts }}</td>
File "/home/admin/work/public-mars-0.2.0b1-cupid.zip/mars/web/server.py", line 49, in format_ts
return datetime.fromtimestamp(value).strftime('%Y-%m-%d %H:%M:%S')
ValueError: Invalid value NaN (not a number)
500 GET /worker?endpoint=10.101.216.148:53630 (10.101.202.142) 137.45ms

# Fixed code
def submit_graph(
    self, session_id, serialized_graph, graph_key, target, compose=True, wait=True
):
    session_uid = SessionActor.gen_uid(session_id)
    session_ref = self.get_actor_ref(session_uid)
    session_ref.submit_tileable_graph(
        serialized_graph, graph_key, target, compose=compose, _tell=not wait
    )
# Buggy code
def get_graph_state(self, session_id, graph_key):
    from .scheduler import GraphState

    graph_meta_ref = self.get_graph_meta_ref(session_id, graph_key)
    if self.actor_client.has_actor(graph_meta_ref):
        state_obj = graph_meta_ref.get_state()
        state = state_obj.value if state_obj else "preparing"
    else:
        state = "preparing"
    state = GraphState(state.lower())
    return state


# Traceback (ValueError)
500 GET /worker?endpoint
Traceback (most recent call last):
File "/opt/conda/lib/python3.6/site-packages/tornado/web.py", line 1592, in _execute
result = yield result
File "/opt/conda/lib/python3.6/site-packages/tornado/gen.py", line 1133, in run
value = future.result()
File "/opt/conda/lib/python3.6/site-packages/tornado/gen.py", line 1147, in run
yielded = self.gen.send(value)
File "/opt/conda/lib/python3.6/site-packages/bokeh/server/views/doc_handler.py", line 27, in get
template_variables=session.document.template_variables)
File "/opt/conda/lib/python3.6/site-packages/bokeh/embed/server.py", line 230, in server_html_page_for_session
template=template, template_variables=template_variables)
File "/opt/conda/lib/python3.6/site-packages/bokeh/embed/elements.py", line 133, in html_page_for_render_items
html = template.render(context)
File "/opt/conda/lib/python3.6/site-packages/jinja2/asyncsupport.py", line 76, in render
return original_render(self, *args, **kwargs)
File "/opt/conda/lib/python3.6/site-packages/jinja2/environment.py", line 1008, in render
return self.environment.handle_exception(exc_info, True)
File "/opt/conda/lib/python3.6/site-packages/jinja2/environment.py", line 780, in handle_exception
reraise(exc_type, exc_value, tb)
File "/opt/conda/lib/python3.6/site-packages/jinja2/_compat.py", line 37, in reraise
raise value.with_traceback(tb)
File "/home/admin/work/public-mars-0.2.0b1-cupid.zip/mars/web/templates/worker_detail.html", line 1, in top-level template code
{% extends "base.html" %}
File "/home/admin/work/public-mars-0.2.0b1-cupid.zip/mars/web/templates/base.html", line 65, in top-level template code
{% block body %}{% endblock %}
File "/home/admin/work/public-mars-0.2.0b1-cupid.zip/mars/web/templates/worker_detail.html", line 252, in block "body"
<td>{{ stats['min_est_finish_time'] | format_ts }}</td>
File "/home/admin/work/public-mars-0.2.0b1-cupid.zip/mars/web/server.py", line 49, in format_ts
return datetime.fromtimestamp(value).strftime('%Y-%m-%d %H:%M:%S')
ValueError: Invalid value NaN (not a number)
500 GET /worker?endpoint=10.101.216.148:53630 (10.101.202.142) 137.45ms

# Fixed code
def get_graph_state(self, session_id, graph_key):
    from .scheduler import GraphState

    graph_meta_ref = self.get_graph_meta_ref(session_id, graph_key)
    if self.actor_client.has_actor(graph_meta_ref):
        state_obj = graph_meta_ref.get_state()
        state = state_obj.value if state_obj else "preparing"
    else:
        raise GraphNotExists
    state = GraphState(state.lower())
    return state
# Buggy code
def format_ts(value):
    if value is None:
        return None
    return datetime.fromtimestamp(value).strftime("%Y-%m-%d %H:%M:%S")


# Traceback (ValueError)
500 GET /worker?endpoint
Traceback (most recent call last):
File "/opt/conda/lib/python3.6/site-packages/tornado/web.py", line 1592, in _execute
result = yield result
File "/opt/conda/lib/python3.6/site-packages/tornado/gen.py", line 1133, in run
value = future.result()
File "/opt/conda/lib/python3.6/site-packages/tornado/gen.py", line 1147, in run
yielded = self.gen.send(value)
File "/opt/conda/lib/python3.6/site-packages/bokeh/server/views/doc_handler.py", line 27, in get
template_variables=session.document.template_variables)
File "/opt/conda/lib/python3.6/site-packages/bokeh/embed/server.py", line 230, in server_html_page_for_session
template=template, template_variables=template_variables)
File "/opt/conda/lib/python3.6/site-packages/bokeh/embed/elements.py", line 133, in html_page_for_render_items
html = template.render(context)
File "/opt/conda/lib/python3.6/site-packages/jinja2/asyncsupport.py", line 76, in render
return original_render(self, *args, **kwargs)
File "/opt/conda/lib/python3.6/site-packages/jinja2/environment.py", line 1008, in render
return self.environment.handle_exception(exc_info, True)
File "/opt/conda/lib/python3.6/site-packages/jinja2/environment.py", line 780, in handle_exception
reraise(exc_type, exc_value, tb)
File "/opt/conda/lib/python3.6/site-packages/jinja2/_compat.py", line 37, in reraise
raise value.with_traceback(tb)
File "/home/admin/work/public-mars-0.2.0b1-cupid.zip/mars/web/templates/worker_detail.html", line 1, in top-level template code
{% extends "base.html" %}
File "/home/admin/work/public-mars-0.2.0b1-cupid.zip/mars/web/templates/base.html", line 65, in top-level template code
{% block body %}{% endblock %}
File "/home/admin/work/public-mars-0.2.0b1-cupid.zip/mars/web/templates/worker_detail.html", line 252, in block "body"
<td>{{ stats['min_est_finish_time'] | format_ts }}</td>
File "/home/admin/work/public-mars-0.2.0b1-cupid.zip/mars/web/server.py", line 49, in format_ts
return datetime.fromtimestamp(value).strftime('%Y-%m-%d %H:%M:%S')
ValueError: Invalid value NaN (not a number)
500 GET /worker?endpoint=10.101.216.148:53630 (10.101.202.142) 137.45ms

# Fixed code
def format_ts(value):
    if value is None or np.isnan(value):
        return None
    return datetime.fromtimestamp(value).strftime("%Y-%m-%d %H:%M:%S")
# Buggy code
def _handle_success(*_):
    self._notify_successors(session_id, graph_key)
    self._invoke_finish_callbacks(session_id, graph_key)


# Traceback (ValueError)
500 GET /worker?endpoint
Traceback (most recent call last):
File "/opt/conda/lib/python3.6/site-packages/tornado/web.py", line 1592, in _execute
result = yield result
File "/opt/conda/lib/python3.6/site-packages/tornado/gen.py", line 1133, in run
value = future.result()
File "/opt/conda/lib/python3.6/site-packages/tornado/gen.py", line 1147, in run
yielded = self.gen.send(value)
File "/opt/conda/lib/python3.6/site-packages/bokeh/server/views/doc_handler.py", line 27, in get
template_variables=session.document.template_variables)
File "/opt/conda/lib/python3.6/site-packages/bokeh/embed/server.py", line 230, in server_html_page_for_session
template=template, template_variables=template_variables)
File "/opt/conda/lib/python3.6/site-packages/bokeh/embed/elements.py", line 133, in html_page_for_render_items
html = template.render(context)
File "/opt/conda/lib/python3.6/site-packages/jinja2/asyncsupport.py", line 76, in render
return original_render(self, *args, **kwargs)
File "/opt/conda/lib/python3.6/site-packages/jinja2/environment.py", line 1008, in render
return self.environment.handle_exception(exc_info, True)
File "/opt/conda/lib/python3.6/site-packages/jinja2/environment.py", line 780, in handle_exception
reraise(exc_type, exc_value, tb)
File "/opt/conda/lib/python3.6/site-packages/jinja2/_compat.py", line 37, in reraise
raise value.with_traceback(tb)
File "/home/admin/work/public-mars-0.2.0b1-cupid.zip/mars/web/templates/worker_detail.html", line 1, in top-level template code
{% extends "base.html" %}
File "/home/admin/work/public-mars-0.2.0b1-cupid.zip/mars/web/templates/base.html", line 65, in top-level template code
{% block body %}{% endblock %}
File "/home/admin/work/public-mars-0.2.0b1-cupid.zip/mars/web/templates/worker_detail.html", line 252, in block "body"
<td>{{ stats['min_est_finish_time'] | format_ts }}</td>
File "/home/admin/work/public-mars-0.2.0b1-cupid.zip/mars/web/server.py", line 49, in format_ts
return datetime.fromtimestamp(value).strftime('%Y-%m-%d %H:%M:%S')
ValueError: Invalid value NaN (not a number)
500 GET /worker?endpoint=10.101.216.148:53630 (10.101.202.142) 137.45ms

# Fixed code
def _handle_success(*_):
    self._invoke_finish_callbacks(session_id, graph_key)
# Buggy code
def _cache_result(*_):
    self._result_cache[(session_id, graph_key)] = GraphResultRecord(save_sizes)


# Traceback (ValueError)
500 GET /worker?endpoint
Traceback (most recent call last):
File "/opt/conda/lib/python3.6/site-packages/tornado/web.py", line 1592, in _execute
result = yield result
File "/opt/conda/lib/python3.6/site-packages/tornado/gen.py", line 1133, in run
value = future.result()
File "/opt/conda/lib/python3.6/site-packages/tornado/gen.py", line 1147, in run
yielded = self.gen.send(value)
File "/opt/conda/lib/python3.6/site-packages/bokeh/server/views/doc_handler.py", line 27, in get
template_variables=session.document.template_variables)
File "/opt/conda/lib/python3.6/site-packages/bokeh/embed/server.py", line 230, in server_html_page_for_session
template=template, template_variables=template_variables)
File "/opt/conda/lib/python3.6/site-packages/bokeh/embed/elements.py", line 133, in html_page_for_render_items
html = template.render(context)
File "/opt/conda/lib/python3.6/site-packages/jinja2/asyncsupport.py", line 76, in render
return original_render(self, *args, **kwargs)
File "/opt/conda/lib/python3.6/site-packages/jinja2/environment.py", line 1008, in render
return self.environment.handle_exception(exc_info, True)
File "/opt/conda/lib/python3.6/site-packages/jinja2/environment.py", line 780, in handle_exception
reraise(exc_type, exc_value, tb)
File "/opt/conda/lib/python3.6/site-packages/jinja2/_compat.py", line 37, in reraise
raise value.with_traceback(tb)
File "/home/admin/work/public-mars-0.2.0b1-cupid.zip/mars/web/templates/worker_detail.html", line 1, in top-level template code
{% extends "base.html" %}
File "/home/admin/work/public-mars-0.2.0b1-cupid.zip/mars/web/templates/base.html", line 65, in top-level template code
{% block body %}{% endblock %}
File "/home/admin/work/public-mars-0.2.0b1-cupid.zip/mars/web/templates/worker_detail.html", line 252, in block "body"
<td>{{ stats['min_est_finish_time'] | format_ts }}</td>
File "/home/admin/work/public-mars-0.2.0b1-cupid.zip/mars/web/server.py", line 49, in format_ts
return datetime.fromtimestamp(value).strftime('%Y-%m-%d %H:%M:%S')
ValueError: Invalid value NaN (not a number)
500 GET /worker?endpoint=10.101.216.148:53630 (10.101.202.142) 137.45ms

# Fixed code
def _cache_result(result_sizes):
    save_sizes.update(result_sizes)
    self._result_cache[(session_id, graph_key)] = GraphResultRecord(save_sizes)
# Buggy code
def hash_index(index, size):
    def func(x, size):
        return mmh_hash(bytes(x)) % size

    f = functools.partial(func, size=size)
    grouped = sorted(index.groupby(index.map(f)).items(), key=operator.itemgetter(0))
    return [g[1] for g in grouped]


# Traceback (KeyError)
Traceback (most recent call last):
File "/Users/hetao/mars/mars/tiles.py", line 111, in _dispatch
handler = self._handlers[op_cls]
KeyError: <class 'mars.dataframe.expressions.arithmetic.add.DataFrameAdd'>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/hetao/mars/mars/core.py", line 554, in execute
return session.run(self, **kw)
File "/Users/hetao/mars/mars/session.py", line 115, in run
result = self._sess.run(*tileables, **kw)
File "/Users/hetao/mars/mars/session.py", line 56, in run
res = self._executor.execute_tileables(tileables, **kw)
File "/Users/hetao/mars/mars/utils.py", line 364, in _wrapped
return func(*args, **kwargs)
File "/Users/hetao/mars/mars/executor.py", line 499, in execute_tileables
tileable.tiles()
File "/Users/hetao/mars/mars/core.py", line 474, in tiles
return handler.tiles(self)
File "/Users/hetao/mars/mars/tiles.py", line 174, in tiles
tiled = self._dispatch(node.op)
File "/Users/hetao/mars/mars/utils.py", line 364, in _wrapped
return func(*args, **kwargs)
File "/Users/hetao/mars/mars/tiles.py", line 116, in _dispatch
return op_cls.tile(op)
File "/Users/hetao/mars/mars/dataframe/expressions/arithmetic/core.py", line 527, in tile
return cls._tile_both_dataframes(op)
File "/Users/hetao/mars/mars/dataframe/expressions/arithmetic/core.py", line 516, in _tile_both_dataframes
out_chunks = cls._gen_out_chunks_with_all_shuffle(op, out_shape, left, right)
File "/Users/hetao/mars/mars/dataframe/expressions/arithmetic/core.py", line 461, in _gen_out_chunks_with_all_shuffle
reduce_op.new_chunk([proxy_chunk], shape=(np.nan, np.nan), index=out_idx))
File "/Users/hetao/mars/mars/core.py", line 650, in new_chunk
return self.new_chunks(inputs, kws=kws, **kw)[0]
File "/Users/hetao/mars/mars/core.py", line 644, in new_chunks
return self._new_chunks(inputs, kws=kws, **kwargs)
File "/Users/hetao/mars/mars/core.py", line 618, in _new_chunks
chunk = self._create_chunk(j, index, **create_chunk_kw)
File "/Users/hetao/mars/mars/dataframe/expressions/arithmetic/core.py", line 188, in _create_chunk
all_dtypes = [c.op.column_shuffle_segments[index[1]] for c in index_align_map_chunks
File "/Users/hetao/mars/mars/dataframe/expressions/arithmetic/core.py", line 189, in <listcomp>
if c.index[0] == index_align_map_chunks[0].index[0]]
IndexError: list index out of range


# Fixed code
def hash_index(index, size):
    def func(x, size):
        return mmh_hash(bytes(x)) % size

    f = functools.partial(func, size=size)
    idx_to_grouped = dict(index.groupby(index.map(f)).items())
    return [idx_to_grouped.get(i, list()) for i in range(size)]
# Buggy code
def mars_serialize_context():
    global _serialize_context
    if _serialize_context is None:
        ctx = pyarrow.default_serialization_context()
        ctx.register_type(
            SparseNDArray,
            "mars.SparseNDArray",
            custom_serializer=_serialize_sparse_csr_list,
            custom_deserializer=_deserialize_sparse_csr_list,
        )
        ctx.register_type(
            DataTuple,
            "mars.DataTuple",
            custom_serializer=_serialize_data_tuple,
            custom_deserializer=_deserialize_data_tuple,
        )
        _serialize_context = ctx
    return _serialize_context


# Traceback (TypeError)
Traceback (most recent call last):
File "/home/admin/work/_public-mars-0.1.1.zip/mars/scheduler/operand.py", line 461, in _rejecter
six.reraise(*exc)
File "/home/admin/work/_public-mars-0.1.1.zip/mars/lib/six.py", line 702, in reraise
raise value.with_traceback(tb)
File "/home/admin/work/_public-mars-0.1.1.zip/mars/promise.py", line 92, in _wrapped
result = func(*args, **kwargs)
File "/home/admin/work/_public-mars-0.1.1.zip/mars/utils.py", line 288, in _wrapped
return func(*args, **kwargs)
File "/home/admin/work/_public-mars-0.1.1.zip/mars/worker/calc.py", line 72, in _try_put_chunk
ref = self._chunk_store.put(session_id, chunk_key, _calc_result_cache[chunk_key][1])
File "/home/admin/work/_public-mars-0.1.1.zip/mars/worker/chunkstore.py", line 184, in put
value = DataTuple(*value)
TypeError: tuple() takes at most 1 argument (2 given)

# Fixed code
def mars_serialize_context():
    global _serialize_context
    if _serialize_context is None:
        ctx = pyarrow.default_serialization_context()
        ctx.register_type(
            SparseNDArray,
            "mars.SparseNDArray",
            custom_serializer=_serialize_sparse_csr_list,
            custom_deserializer=_deserialize_sparse_csr_list,
        )
        _serialize_context = ctx
    return _serialize_context
# Buggy code
def create(self, session_id, chunk_key, size):
    from pyarrow.lib import PlasmaStoreFull

    obj_id = self._new_object_id(session_id, chunk_key)

    try:
        buffer = self._plasma_client.create(obj_id, size)
        return buffer
    except PlasmaStoreFull:
        exc_type = PlasmaStoreFull
        logger.warning(
            "Chunk %s(%d) failed to store to plasma due to StoreFullError",
            chunk_key,
            size,
        )

    if exc_type is PlasmaStoreFull:
        raise StoreFull


# Traceback (TypeError)
Traceback (most recent call last):
File "/home/admin/work/_public-mars-0.1.1.zip/mars/scheduler/operand.py", line 461, in _rejecter
six.reraise(*exc)
File "/home/admin/work/_public-mars-0.1.1.zip/mars/lib/six.py", line 702, in reraise
raise value.with_traceback(tb)
File "/home/admin/work/_public-mars-0.1.1.zip/mars/promise.py", line 92, in _wrapped
result = func(*args, **kwargs)
File "/home/admin/work/_public-mars-0.1.1.zip/mars/utils.py", line 288, in _wrapped
return func(*args, **kwargs)
File "/home/admin/work/_public-mars-0.1.1.zip/mars/worker/calc.py", line 72, in _try_put_chunk
ref = self._chunk_store.put(session_id, chunk_key, _calc_result_cache[chunk_key][1])
File "/home/admin/work/_public-mars-0.1.1.zip/mars/worker/chunkstore.py", line 184, in put
value = DataTuple(*value)
TypeError: tuple() takes at most 1 argument (2 given)

# Fixed code
def create(self, session_id, chunk_key, size):
    from pyarrow.lib import PlasmaStoreFull

    obj_id = self._new_object_id(session_id, chunk_key)

    try:
        self._plasma_client.evict(size)
        buffer = self._plasma_client.create(obj_id, size)
        return buffer
    except PlasmaStoreFull:
        exc_type = PlasmaStoreFull
        self._mapper_ref.delete(session_id, chunk_key)
        logger.warning(
            "Chunk %s(%d) failed to store to plasma due to StoreFullError",
            chunk_key,
            size,
        )
    except:  # noqa: E722  # pragma: no cover
        self._mapper_ref.delete(session_id, chunk_key)
        raise

    if exc_type is PlasmaStoreFull:
        raise StoreFull
# Buggy code
def seal(self, session_id, chunk_key):
    from pyarrow.lib import PlasmaObjectNonexistent

    obj_id = self._get_object_id(session_id, chunk_key)
    try:
        self._plasma_client.seal(obj_id)
    except PlasmaObjectNonexistent:
        raise KeyError("(%r, %r)" % (session_id, chunk_key))


# Traceback (TypeError)
Traceback (most recent call last):
File "/home/admin/work/_public-mars-0.1.1.zip/mars/scheduler/operand.py", line 461, in _rejecter
six.reraise(*exc)
File "/home/admin/work/_public-mars-0.1.1.zip/mars/lib/six.py", line 702, in reraise
raise value.with_traceback(tb)
File "/home/admin/work/_public-mars-0.1.1.zip/mars/promise.py", line 92, in _wrapped
result = func(*args, **kwargs)
File "/home/admin/work/_public-mars-0.1.1.zip/mars/utils.py", line 288, in _wrapped
return func(*args, **kwargs)
File "/home/admin/work/_public-mars-0.1.1.zip/mars/worker/calc.py", line 72, in _try_put_chunk
ref = self._chunk_store.put(session_id, chunk_key, _calc_result_cache[chunk_key][1])
File "/home/admin/work/_public-mars-0.1.1.zip/mars/worker/chunkstore.py", line 184, in put
value = DataTuple(*value)
TypeError: tuple() takes at most 1 argument (2 given)

# Fixed code
def seal(self, session_id, chunk_key):
    from pyarrow.lib import PlasmaObjectNonexistent

    obj_id = self._get_object_id(session_id, chunk_key)
    try:
        self._plasma_client.seal(obj_id)
    except PlasmaObjectNonexistent:
        raise KeyError((session_id, chunk_key))
# Buggy code
def get(self, session_id, chunk_key):
    """
    Get deserialized Mars object from plasma store
    """
    from pyarrow.plasma import ObjectNotAvailable

    obj_id = self._get_object_id(session_id, chunk_key)
    obj = self._plasma_client.get(
        obj_id, serialization_context=self._serialize_context, timeout_ms=10
    )
    if obj is ObjectNotAvailable:
        raise KeyError("(%r, %r)" % (session_id, chunk_key))
    return obj


# Traceback (TypeError)
Traceback (most recent call last):
File "/home/admin/work/_public-mars-0.1.1.zip/mars/scheduler/operand.py", line 461, in _rejecter
six.reraise(*exc)
File "/home/admin/work/_public-mars-0.1.1.zip/mars/lib/six.py", line 702, in reraise
raise value.with_traceback(tb)
File "/home/admin/work/_public-mars-0.1.1.zip/mars/promise.py", line 92, in _wrapped
result = func(*args, **kwargs)
File "/home/admin/work/_public-mars-0.1.1.zip/mars/utils.py", line 288, in _wrapped
return func(*args, **kwargs)
File "/home/admin/work/_public-mars-0.1.1.zip/mars/worker/calc.py", line 72, in _try_put_chunk
ref = self._chunk_store.put(session_id, chunk_key, _calc_result_cache[chunk_key][1])
File "/home/admin/work/_public-mars-0.1.1.zip/mars/worker/chunkstore.py", line 184, in put
value = DataTuple(*value)
TypeError: tuple() takes at most 1 argument (2 given)

# Fixed code
def get(self, session_id, chunk_key):
    """
    Get deserialized Mars object from plasma store
    """
    from pyarrow.plasma import ObjectNotAvailable

    obj_id = self._get_object_id(session_id, chunk_key)
    obj = self._plasma_client.get(
        obj_id, serialization_context=self._serialize_context, timeout_ms=10
    )
    if obj is ObjectNotAvailable:
        raise KeyError((session_id, chunk_key))
    return obj
# Buggy code
def get_buffer(self, session_id, chunk_key):
    """
    Get raw buffer from plasma store
    """
    obj_id = self._get_object_id(session_id, chunk_key)
    [buf] = self._plasma_client.get_buffers([obj_id], timeout_ms=10)
    if buf is None:
        raise KeyError("(%r, %r)" % (session_id, chunk_key))
    return buf


# Traceback (TypeError)
Traceback (most recent call last):
File "/home/admin/work/_public-mars-0.1.1.zip/mars/scheduler/operand.py", line 461, in _rejecter
six.reraise(*exc)
File "/home/admin/work/_public-mars-0.1.1.zip/mars/lib/six.py", line 702, in reraise
raise value.with_traceback(tb)
File "/home/admin/work/_public-mars-0.1.1.zip/mars/promise.py", line 92, in _wrapped
result = func(*args, **kwargs)
File "/home/admin/work/_public-mars-0.1.1.zip/mars/utils.py", line 288, in _wrapped
return func(*args, **kwargs)
File "/home/admin/work/_public-mars-0.1.1.zip/mars/worker/calc.py", line 72, in _try_put_chunk
ref = self._chunk_store.put(session_id, chunk_key, _calc_result_cache[chunk_key][1])
File "/home/admin/work/_public-mars-0.1.1.zip/mars/worker/chunkstore.py", line 184, in put
value = DataTuple(*value)
TypeError: tuple() takes at most 1 argument (2 given)

# Fixed code
def get_buffer(self, session_id, chunk_key):
    """
    Get raw buffer from plasma store
    """
    obj_id = self._get_object_id(session_id, chunk_key)
    [buf] = self._plasma_client.get_buffers([obj_id], timeout_ms=10)
    if buf is None:
        raise KeyError((session_id, chunk_key))
    return buf
# Buggy code
def get_actual_size(self, session_id, chunk_key):
    """
    Get actual size of Mars object from plasma store
    """
    buf = None
    try:
        obj_id = self._get_object_id(session_id, chunk_key)
        [buf] = self._plasma_client.get_buffers([obj_id], timeout_ms=10)
        size = buf.size
    finally:
        del buf
    return size


# Traceback (TypeError)
Traceback (most recent call last):
File "/home/admin/work/_public-mars-0.1.1.zip/mars/scheduler/operand.py", line 461, in _rejecter
six.reraise(*exc)
File "/home/admin/work/_public-mars-0.1.1.zip/mars/lib/six.py", line 702, in reraise
raise value.with_traceback(tb)
File "/home/admin/work/_public-mars-0.1.1.zip/mars/promise.py", line 92, in _wrapped
result = func(*args, **kwargs)
File "/home/admin/work/_public-mars-0.1.1.zip/mars/utils.py", line 288, in _wrapped
return func(*args, **kwargs)
File "/home/admin/work/_public-mars-0.1.1.zip/mars/worker/calc.py", line 72, in _try_put_chunk
ref = self._chunk_store.put(session_id, chunk_key, _calc_result_cache[chunk_key][1])
File "/home/admin/work/_public-mars-0.1.1.zip/mars/worker/chunkstore.py", line 184, in put
value = DataTuple(*value)
TypeError: tuple() takes at most 1 argument (2 given)

# Fixed code
def get_actual_size(self, session_id, chunk_key):
    """
    Get actual size of Mars object from plasma store
    """
    buf = None
    try:
        obj_id = self._get_object_id(session_id, chunk_key)
        [buf] = self._plasma_client.get_buffers([obj_id], timeout_ms=10)
        if buf is None:
            raise KeyError((session_id, chunk_key))
        size = buf.size
    finally:
        del buf
    return size
# Buggy code
def build_fetch_graph(self, tensor_key):
    """
    Convert single tensor to tiled fetch tensor and put into a graph which only contains one tensor
    :param tensor_key: the key of tensor
    """
    tiled_tensor = self._get_tensor_by_key(tensor_key)
    graph = DAG()

    chunks = []
    for c in tiled_tensor.chunks:
        fetch_op = TensorFetch(dtype=c.dtype)
        fetch_chunk = fetch_op.new_chunk(None, c.shape, c.index, _key=c.key)
        chunks.append(fetch_chunk)

    new_op = TensorFetch(dtype=tiled_tensor.dtype)
    new_tensor = new_op.new_tensor(
        None,
        tiled_tensor.shape,
        chunks=chunks,
        nsplits=tiled_tensor.nsplits,
        _key=tiled_tensor.key,
    )
    graph.add_node(new_tensor)
    return serialize_graph(graph)


# Traceback (mars.error)
In [1]: from mars.deploy.local import new_cluster

In [2]: cluster = new_cluster(scheduler_n_process=2, worker_n_process=3, shared_memory='20M',)

In [3]: import mars.tensor as mt

In [4]: import scipy.sparse as sps

In [5]: a = sps.csr_matrix((10000, 10000))

In [6]: b = sps.csr_matrix((10000, 1))

In [7]: t1 = mt.tensor(a)

In [8]: t2 = mt.tensor(b)


In [9]: from mars.session import new_session

In [10]: cluster.session.run(t1 * t2)

Unexpected exception occurred in ChunkHolderActor.spill_size.
Traceback (most recent call last):
File "/Users/hekaisheng/Documents/mars_dev/mars/mars/utils.py", line 298, in _wrapped
return func(*args, **kwargs)
File "/Users/hekaisheng/Documents/mars_dev/mars/mars/worker/chunkholder.py", line 123, in spill_size
raise SpillExhausted
mars.errors.SpillExhausted
Unhandled exception in promise call
Traceback (most recent call last):
File "/Users/hekaisheng/Documents/mars_dev/mars/mars/promise.py", line 304, in _wrapped
return func(*args, **kwargs)
File "/Users/hekaisheng/Documents/mars_dev/mars/mars/utils.py", line 298, in _wrapped
return func(*args, **kwargs)
File "/Users/hekaisheng/Documents/mars_dev/mars/mars/worker/chunkholder.py", line 123, in spill_size
raise SpillExhausted
mars.errors.SpillExhausted
....

# Fixed code
def build_fetch_graph(self, tensor_key):
    """
    Convert single tensor to tiled fetch tensor and put into a graph which only contains one tensor
    :param tensor_key: the key of tensor
    """
    tiled_tensor = self._get_tensor_by_key(tensor_key)
    graph = DAG()

    chunks = []
    for c in tiled_tensor.chunks:
        fetch_op = TensorFetch(dtype=c.dtype, sparse=c.op.sparse)
        fetch_chunk = fetch_op.new_chunk(None, c.shape, c.index, _key=c.key)
        chunks.append(fetch_chunk)

    new_op = TensorFetch(dtype=tiled_tensor.dtype, sparse=tiled_tensor.op.sparse)
    new_tensor = new_op.new_tensor(
        None,
        tiled_tensor.shape,
        chunks=chunks,
        nsplits=tiled_tensor.nsplits,
        _key=tiled_tensor.key,
    )
    graph.add_node(new_tensor)
    return serialize_graph(graph)
# Buggy code
def __init__(self, dtype=None, to_fetch_key=None, **kw):
    super(TensorFetch, self).__init__(_dtype=dtype, _to_fetch_key=to_fetch_key, **kw)


# Traceback (mars.error)
In [1]: from mars.deploy.local import new_cluster

In [2]: cluster = new_cluster(scheduler_n_process=2, worker_n_process=3, shared_memory='20M',)

In [3]: import mars.tensor as mt

In [4]: import scipy.sparse as sps

In [5]: a = sps.csr_matrix((10000, 10000))

In [6]: b = sps.csr_matrix((10000, 1))

In [7]: t1 = mt.tensor(a)

In [8]: t2 = mt.tensor(b)


In [9]: from mars.session import new_session

In [10]: cluster.session.run(t1 * t2)

Unexpected exception occurred in ChunkHolderActor.spill_size.
Traceback (most recent call last):
File "/Users/hekaisheng/Documents/mars_dev/mars/mars/utils.py", line 298, in _wrapped
return func(*args, **kwargs)
File "/Users/hekaisheng/Documents/mars_dev/mars/mars/worker/chunkholder.py", line 123, in spill_size
raise SpillExhausted
mars.errors.SpillExhausted
Unhandled exception in promise call
Traceback (most recent call last):
File "/Users/hekaisheng/Documents/mars_dev/mars/mars/promise.py", line 304, in _wrapped
return func(*args, **kwargs)
File "/Users/hekaisheng/Documents/mars_dev/mars/mars/utils.py", line 298, in _wrapped
return func(*args, **kwargs)
File "/Users/hekaisheng/Documents/mars_dev/mars/mars/worker/chunkholder.py", line 123, in spill_size
raise SpillExhausted
mars.errors.SpillExhausted
....

# Fixed code
def __init__(self, dtype=None, to_fetch_key=None, sparse=False, **kw):
    super(TensorFetch, self).__init__(
        _dtype=dtype, _to_fetch_key=to_fetch_key, _sparse=sparse, **kw
    )
# Buggy code
def convert_to_fetch(entity):
    from ..core import CHUNK_TYPE, TENSOR_TYPE
    from .fetch import TensorFetch

    if isinstance(entity, CHUNK_TYPE):
        new_op = TensorFetch(dtype=entity.dtype)
        return new_op.new_chunk(
            None, entity.shape, index=entity.index, _key=entity.key, _id=entity.id
        )
    elif isinstance(entity, TENSOR_TYPE):
        new_op = TensorFetch(dtype=entity.dtype)
        return new_op.new_tensor(None, entity.shape, _key=entity.key, _id=entity.id)
    else:
        raise ValueError("Now only support tensor or chunk type.")


# Traceback (mars.error)
In [1]: from mars.deploy.local import new_cluster

In [2]: cluster = new_cluster(scheduler_n_process=2, worker_n_process=3, shared_memory='20M',)

In [3]: import mars.tensor as mt

In [4]: import scipy.sparse as sps

In [5]: a = sps.csr_matrix((10000, 10000))

In [6]: b = sps.csr_matrix((10000, 1))

In [7]: t1 = mt.tensor(a)

In [8]: t2 = mt.tensor(b)


In [9]: from mars.session import new_session

In [10]: cluster.session.run(t1 * t2)

Unexpected exception occurred in ChunkHolderActor.spill_size.
Traceback (most recent call last):
File "/Users/hekaisheng/Documents/mars_dev/mars/mars/utils.py", line 298, in _wrapped
return func(*args, **kwargs)
File "/Users/hekaisheng/Documents/mars_dev/mars/mars/worker/chunkholder.py", line 123, in spill_size
raise SpillExhausted
mars.errors.SpillExhausted
Unhandled exception in promise call
Traceback (most recent call last):
File "/Users/hekaisheng/Documents/mars_dev/mars/mars/promise.py", line 304, in _wrapped
return func(*args, **kwargs)
File "/Users/hekaisheng/Documents/mars_dev/mars/mars/utils.py", line 298, in _wrapped
return func(*args, **kwargs)
File "/Users/hekaisheng/Documents/mars_dev/mars/mars/worker/chunkholder.py", line 123, in spill_size
raise SpillExhausted
mars.errors.SpillExhausted
....

# Fixed code
def convert_to_fetch(entity):
    from ..core import CHUNK_TYPE, TENSOR_TYPE
    from .fetch import TensorFetch

    if isinstance(entity, CHUNK_TYPE):
        new_op = TensorFetch(dtype=entity.dtype, sparse=entity.op.sparse)
        return new_op.new_chunk(
            None, entity.shape, index=entity.index, _key=entity.key, _id=entity.id
        )
    elif isinstance(entity, TENSOR_TYPE):
        new_op = TensorFetch(dtype=entity.dtype, sparse=entity.op.sparse)
        return new_op.new_tensor(None, entity.shape, _key=entity.key, _id=entity.id)
    else:
        raise ValueError("Now only support tensor or chunk type.")