# Buggy code
def execute(cls, ctx, op):
    chunk = op.outputs[0]

    if isinstance(op.input, dict):
        d = OrderedDict()
        for k, v in op.input.items():
            if hasattr(v, "key"):
                d[k] = ctx[v.key]
            else:
                d[k] = v
        if op.index is not None:
            index_data = ctx[op.index.key]
        else:
            index_data = chunk.index_value.to_pandas()
        ctx[chunk.key] = pd.DataFrame(
            d, index=index_data, columns=chunk.columns_value.to_pandas()
        )
    else:
        tensor_data = ctx[op.inputs[0].key]
        if isinstance(tensor_data, pd.Series):
            ctx[chunk.key] = tensor_data.to_frame(name=chunk.dtypes.index[0])
        else:
            if op.index is not None:
                # index is a tensor
                index_data = ctx[op.inputs[1].key]
            else:
                index_data = chunk.index_value.to_pandas()
            ctx[chunk.key] = pd.DataFrame(
                tensor_data, index=index_data, columns=chunk.columns_value.to_pandas()
            )


# Traceback (ValueError)
Traceback (most recent call last):
File "/home/smartguo/lib/anaconda3/envs/mars/lib/python3.7/site-packages/pandas/core/dtypes/common.py", line 171, in ensure_python_int
new_value = int(value)
ValueError: cannot convert float NaN to integer

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "tensor_loop.py", line 14, in <module>
df_res = md.DataFrame(score, columns=["probability"])
File "/home/smartguo/lib/anaconda3/envs/mars/lib/python3.7/site-packages/mars/dataframe/initializer.py", line 47, in __init__
df = dataframe_from_tensor(data, index=index, columns=columns, gpu=gpu, sparse=sparse)
File "/home/smartguo/lib/anaconda3/envs/mars/lib/python3.7/site-packages/mars/dataframe/datasource/from_tensor.py", line 357, in dataframe_from_tensor
return op(tensor, index, columns)
File "/home/smartguo/lib/anaconda3/envs/mars/lib/python3.7/site-packages/mars/utils.py", line 451, in _inner
return func(*args, **kwargs)
File "/home/smartguo/lib/anaconda3/envs/mars/lib/python3.7/site-packages/mars/dataframe/datasource/from_tensor.py", line 83, in __call__
return self._call_input_tensor(input_tensor, index, columns)
File "/home/smartguo/lib/anaconda3/envs/mars/lib/python3.7/site-packages/mars/dataframe/datasource/from_tensor.py", line 156, in _call_input_tensor
index_value = parse_index(pd.RangeIndex(start=0, stop=input_tensor.shape[0]))
File "/home/smartguo/lib/anaconda3/envs/mars/lib/python3.7/site-packages/pandas/core/indexes/range.py", line 107, in __new__
stop = ensure_python_int(stop)
File "/home/smartguo/lib/anaconda3/envs/mars/lib/python3.7/site-packages/pandas/core/dtypes/common.py", line 174, in ensure_python_int
raise TypeError(f"Wrong type {type(value)} for value {value}") from err
TypeError: Wrong type <class 'float'> for value nan

# Fixed code
def execute(cls, ctx, op):
    chunk = op.outputs[0]

    if isinstance(op.input, dict):
        d = OrderedDict()
        for k, v in op.input.items():
            if hasattr(v, "key"):
                d[k] = ctx[v.key]
            else:
                d[k] = v
        if op.index is not None:
            index_data = ctx[op.index.key]
        else:
            index_data = chunk.index_value.to_pandas()
        ctx[chunk.key] = pd.DataFrame(
            d, index=index_data, columns=chunk.columns_value.to_pandas()
        )
    else:
        tensor_data = ctx[op.inputs[0].key]
        if isinstance(tensor_data, pd.Series):
            ctx[chunk.key] = tensor_data.to_frame(name=chunk.dtypes.index[0])
        else:
            if op.index is not None:
                # index is a tensor
                index_data = ctx[op.inputs[1].key]
            else:
                index_data = chunk.index_value.to_pandas()
                if isinstance(index_data, pd.RangeIndex) and len(index_data) == 0:
                    index_data = None
            ctx[chunk.key] = pd.DataFrame(
                tensor_data, index=index_data, columns=chunk.columns_value.to_pandas()
            )