gurudesh/pytracebugs huggingface dataset:
# Buggy code
def swapaxes(a, axis1, axis2):
    """
    Interchange two axes of a tensor.

    Parameters
    ----------
    a : array_like
        Input tensor.
    axis1 : int
        First axis.
    axis2 : int
        Second axis.

    Returns
    -------
    a_swapped : Tensor
        If `a` is a Tensor, then a view of `a` is
        returned; otherwise a new tensor is created.

    Examples
    --------
    >>> import mars.tensor as mt

    >>> x = mt.array([[1,2,3]])
    >>> mt.swapaxes(x,0,1).execute()
    array([[1],
           [2],
           [3]])

    >>> x = mt.array([[[0,1],[2,3]],[[4,5],[6,7]]])
    >>> x.execute()
    array([[[0, 1],
            [2, 3]],
           [[4, 5],
            [6, 7]]])

    >>> mt.swapaxes(x,0,2).execute()
    array([[[0, 4],
            [2, 6]],
           [[1, 5],
            [3, 7]]])

    """
    axis1 = validate_axis(a.ndim, axis1)
    axis2 = validate_axis(a.ndim, axis2)

    if axis1 == axis2:
        return a

    op = TensorSwapAxes(axis1, axis2, dtype=a.dtype, sparse=a.issparse())
    return op(a)


# Traceback (AttributeError)
In [35]: p = np.random.rand(3,4,5)

In [36]: mt.swapaxes(p, 0, -1)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-36-016cb9916fdb> in <module>
----> 1 mt.swapaxes(p, 0, -1)

~/anaconda3/envs/pymars0.6/lib/python3.7/site-packages/mars/tensor/base/swapaxes.py in swapaxes(a, axis1, axis2)
150         return a
151
--> 152     op = TensorSwapAxes(axis1, axis2, dtype=a.dtype, sparse=a.issparse())
153     return op(a)

AttributeError: 'numpy.ndarray' object has no attribute 'issparse'

# Fixed code
def swapaxes(a, axis1, axis2):
    """
    Interchange two axes of a tensor.

    Parameters
    ----------
    a : array_like
        Input tensor.
    axis1 : int
        First axis.
    axis2 : int
        Second axis.

    Returns
    -------
    a_swapped : Tensor
        If `a` is a Tensor, then a view of `a` is
        returned; otherwise a new tensor is created.

    Examples
    --------
    >>> import mars.tensor as mt

    >>> x = mt.array([[1,2,3]])
    >>> mt.swapaxes(x,0,1).execute()
    array([[1],
           [2],
           [3]])

    >>> x = mt.array([[[0,1],[2,3]],[[4,5],[6,7]]])
    >>> x.execute()
    array([[[0, 1],
            [2, 3]],
           [[4, 5],
            [6, 7]]])

    >>> mt.swapaxes(x,0,2).execute()
    array([[[0, 4],
            [2, 6]],
           [[1, 5],
            [3, 7]]])

    """
    a = astensor(a)
    axis1 = validate_axis(a.ndim, axis1)
    axis2 = validate_axis(a.ndim, axis2)

    if axis1 == axis2:
        return a

    op = TensorSwapAxes(axis1, axis2, dtype=a.dtype, sparse=a.issparse())
    return op(a)
# Buggy code
def parse_args(self, parser, argv, environ=None):
    environ = environ or os.environ
    args = parser.parse_args(argv)

    args.advertise = args.advertise or environ.get("MARS_CONTAINER_IP")
    load_modules = []
    for mods in tuple(args.load_modules or ()) + (environ.get("MARS_LOAD_MODULES"),):
        load_modules.extend(mods.split(",") if mods else [])
    load_modules.extend(["mars.executor", "mars.serialize.protos"])
    args.load_modules = tuple(load_modules)

    if "MARS_TASK_DETAIL" in environ:
        task_detail = json.loads(environ["MARS_TASK_DETAIL"])
        task_type, task_index = (
            task_detail["task"]["type"],
            task_detail["task"]["index"],
        )

        args.advertise = args.advertise or task_detail["cluster"][task_type][task_index]
        args.schedulers = args.schedulers or ",".join(
            task_detail["cluster"]["scheduler"]
        )
    return args


# Traceback (ModuleNotFoundError)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/wenjun.swj/Code/mars/mars/core.py", line 129, in __repr__
return self._data.__repr__()
File "/Users/wenjun.swj/Code/mars/mars/dataframe/core.py", line 1083, in __repr__
return self._to_str(representation=True)
File "/Users/wenjun.swj/Code/mars/mars/dataframe/core.py", line 1053, in _to_str
self, session=self._executed_sessions[-1])
File "/Users/wenjun.swj/Code/mars/mars/dataframe/utils.py", line 773, in fetch_corner_data
return df_or_series.fetch(session=session)
File "/Users/wenjun.swj/Code/mars/mars/core.py", line 376, in fetch
return session.fetch(self, **kw)
File "/Users/wenjun.swj/Code/mars/mars/session.py", line 491, in fetch
result = self._sess.fetch(*tileables, **kw)
File "/Users/wenjun.swj/Code/mars/mars/web/session.py", line 265, in fetch
result_data = dataserializer.loads(resp.content)
File "/Users/wenjun.swj/Code/mars/mars/serialize/dataserializer.py", line 259, in loads
return pickle.loads(data)
ModuleNotFoundError: No module named 'pyarrow'

# Fixed code
def parse_args(self, parser, argv, environ=None):
    environ = environ or os.environ
    args = parser.parse_args(argv)

    args.host = args.host or environ.get("MARS_BIND_HOST")
    args.port = args.port or environ.get("MARS_BIND_PORT")
    args.endpoint = args.endpoint or environ.get("MARS_BIND_ENDPOINT")
    args.advertise = args.advertise or environ.get("MARS_CONTAINER_IP")
    load_modules = []
    for mods in tuple(args.load_modules or ()) + (environ.get("MARS_LOAD_MODULES"),):
        load_modules.extend(mods.split(",") if mods else [])
    load_modules.extend(["mars.executor", "mars.serialize.protos"])
    args.load_modules = tuple(load_modules)

    if "MARS_TASK_DETAIL" in environ:
        task_detail = json.loads(environ["MARS_TASK_DETAIL"])
        task_type, task_index = (
            task_detail["task"]["type"],
            task_detail["task"]["index"],
        )

        args.advertise = args.advertise or task_detail["cluster"][task_type][task_index]
        args.schedulers = args.schedulers or ",".join(
            task_detail["cluster"]["scheduler"]
        )
    return args
# Buggy code
def _get_ready_pod_count(self, label_selector):
    query = self._core_api.list_namespaced_pod(
        namespace=self._namespace, label_selector=label_selector
    ).to_dict()
    cnt = 0
    for el in query["items"]:
        if el["status"]["phase"] in ("Error", "Failed"):
            raise SystemError(el["status"]["message"])
        if "status" not in el or "conditions" not in el["status"]:
            cnt += 1
        if any(
            cond["type"] == "Ready" and cond["status"] == "True"
            for cond in el["status"].get("conditions") or ()
        ):
            cnt += 1
    return cnt


# Traceback (ModuleNotFoundError)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/wenjun.swj/Code/mars/mars/core.py", line 129, in __repr__
return self._data.__repr__()
File "/Users/wenjun.swj/Code/mars/mars/dataframe/core.py", line 1083, in __repr__
return self._to_str(representation=True)
File "/Users/wenjun.swj/Code/mars/mars/dataframe/core.py", line 1053, in _to_str
self, session=self._executed_sessions[-1])
File "/Users/wenjun.swj/Code/mars/mars/dataframe/utils.py", line 773, in fetch_corner_data
return df_or_series.fetch(session=session)
File "/Users/wenjun.swj/Code/mars/mars/core.py", line 376, in fetch
return session.fetch(self, **kw)
File "/Users/wenjun.swj/Code/mars/mars/session.py", line 491, in fetch
result = self._sess.fetch(*tileables, **kw)
File "/Users/wenjun.swj/Code/mars/mars/web/session.py", line 265, in fetch
result_data = dataserializer.loads(resp.content)
File "/Users/wenjun.swj/Code/mars/mars/serialize/dataserializer.py", line 259, in loads
return pickle.loads(data)
ModuleNotFoundError: No module named 'pyarrow'

# Fixed code
def _get_ready_pod_count(self, label_selector):
    query = self._core_api.list_namespaced_pod(
        namespace=self._namespace, label_selector=label_selector
    ).to_dict()
    cnt = 0
    for el in query["items"]:
        if el["status"]["phase"] in ("Error", "Failed"):
            logger.warning(
                "Error in starting pod, message: %s", el["status"]["message"]
            )
            continue
        if "status" not in el or "conditions" not in el["status"]:
            cnt += 1
        elif any(
            cond["type"] == "Ready" and cond["status"] == "True"
            for cond in el["status"].get("conditions") or ()
        ):
            cnt += 1
    return cnt
# Buggy code
def config_args(self, parser):
    super().config_args(parser)
    parser.add_argument("--nproc", help="number of processes")


# Traceback (ModuleNotFoundError)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/wenjun.swj/Code/mars/mars/core.py", line 129, in __repr__
return self._data.__repr__()
File "/Users/wenjun.swj/Code/mars/mars/dataframe/core.py", line 1083, in __repr__
return self._to_str(representation=True)
File "/Users/wenjun.swj/Code/mars/mars/dataframe/core.py", line 1053, in _to_str
self, session=self._executed_sessions[-1])
File "/Users/wenjun.swj/Code/mars/mars/dataframe/utils.py", line 773, in fetch_corner_data
return df_or_series.fetch(session=session)
File "/Users/wenjun.swj/Code/mars/mars/core.py", line 376, in fetch
return session.fetch(self, **kw)
File "/Users/wenjun.swj/Code/mars/mars/session.py", line 491, in fetch
result = self._sess.fetch(*tileables, **kw)
File "/Users/wenjun.swj/Code/mars/mars/web/session.py", line 265, in fetch
result_data = dataserializer.loads(resp.content)
File "/Users/wenjun.swj/Code/mars/mars/serialize/dataserializer.py", line 259, in loads
return pickle.loads(data)
ModuleNotFoundError: No module named 'pyarrow'

# Fixed code
def config_args(self, parser):
    super().config_args(parser)
    parser.add_argument("--nproc", help="number of processes")
    parser.add_argument(
        "--disable-failover", action="store_true", help="disable fail-over"
    )
# Buggy code
def create_pool(self, *args, **kwargs):
    self._service = SchedulerService()
    self.n_process = int(self.args.nproc or resource.cpu_count())
    kwargs["distributor"] = MarsDistributor(self.n_process, "s:h1:")
    return super().create_pool(*args, **kwargs)


# Traceback (ModuleNotFoundError)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/wenjun.swj/Code/mars/mars/core.py", line 129, in __repr__
return self._data.__repr__()
File "/Users/wenjun.swj/Code/mars/mars/dataframe/core.py", line 1083, in __repr__
return self._to_str(representation=True)
File "/Users/wenjun.swj/Code/mars/mars/dataframe/core.py", line 1053, in _to_str
self, session=self._executed_sessions[-1])
File "/Users/wenjun.swj/Code/mars/mars/dataframe/utils.py", line 773, in fetch_corner_data
return df_or_series.fetch(session=session)
File "/Users/wenjun.swj/Code/mars/mars/core.py", line 376, in fetch
return session.fetch(self, **kw)
File "/Users/wenjun.swj/Code/mars/mars/session.py", line 491, in fetch
result = self._sess.fetch(*tileables, **kw)
File "/Users/wenjun.swj/Code/mars/mars/web/session.py", line 265, in fetch
result_data = dataserializer.loads(resp.content)
File "/Users/wenjun.swj/Code/mars/mars/serialize/dataserializer.py", line 259, in loads
return pickle.loads(data)
ModuleNotFoundError: No module named 'pyarrow'

# Fixed code
def create_pool(self, *args, **kwargs):
    self._service = SchedulerService(disable_failover=self.args.disable_failover)
    self.n_process = int(self.args.nproc or resource.cpu_count())
    kwargs["distributor"] = MarsDistributor(self.n_process, "s:h1:")
    return super().create_pool(*args, **kwargs)
# Buggy code
def __init__(self):
    self._cluster_info_ref = None
    self._session_manager_ref = None
    self._assigner_ref = None
    self._resource_ref = None
    self._chunk_meta_ref = None
    self._kv_store_ref = None
    self._node_info_ref = None
    self._result_receiver_ref = None


# Traceback (ModuleNotFoundError)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/wenjun.swj/Code/mars/mars/core.py", line 129, in __repr__
return self._data.__repr__()
File "/Users/wenjun.swj/Code/mars/mars/dataframe/core.py", line 1083, in __repr__
return self._to_str(representation=True)
File "/Users/wenjun.swj/Code/mars/mars/dataframe/core.py", line 1053, in _to_str
self, session=self._executed_sessions[-1])
File "/Users/wenjun.swj/Code/mars/mars/dataframe/utils.py", line 773, in fetch_corner_data
return df_or_series.fetch(session=session)
File "/Users/wenjun.swj/Code/mars/mars/core.py", line 376, in fetch
return session.fetch(self, **kw)
File "/Users/wenjun.swj/Code/mars/mars/session.py", line 491, in fetch
result = self._sess.fetch(*tileables, **kw)
File "/Users/wenjun.swj/Code/mars/mars/web/session.py", line 265, in fetch
result_data = dataserializer.loads(resp.content)
File "/Users/wenjun.swj/Code/mars/mars/serialize/dataserializer.py", line 259, in loads
return pickle.loads(data)
ModuleNotFoundError: No module named 'pyarrow'

# Fixed code
def __init__(self, **kwargs):
    self._cluster_info_ref = None
    self._session_manager_ref = None
    self._assigner_ref = None
    self._resource_ref = None
    self._chunk_meta_ref = None
    self._kv_store_ref = None
    self._node_info_ref = None
    self._result_receiver_ref = None

    options.scheduler.enable_failover = not (
        kwargs.pop("disable_failover", None) or False
    )

    if kwargs:  # pragma: no cover
        raise TypeError(
            "Keyword arguments %r cannot be recognized." % ", ".join(kwargs)
        )
# Buggy code
def parse_args(self, parser, argv, environ=None):
    args = super().parse_args(parser, argv)
    args.plasma_dir = args.plasma_dir or os.environ.get("MARS_PLASMA_DIRS")
    args.spill_dir = args.spill_dir or os.environ.get("MARS_SPILL_DIRS")
    args.cache_mem = args.cache_mem or os.environ.get("MARS_CACHE_MEM_SIZE")
    args.lock_free_fileio = args.lock_free_fileio or bool(
        int(os.environ.get("MARS_LOCK_FREE_FILEIO", "0"))
    )
    return args


# Traceback (ModuleNotFoundError)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/wenjun.swj/Code/mars/mars/core.py", line 129, in __repr__
return self._data.__repr__()
File "/Users/wenjun.swj/Code/mars/mars/dataframe/core.py", line 1083, in __repr__
return self._to_str(representation=True)
File "/Users/wenjun.swj/Code/mars/mars/dataframe/core.py", line 1053, in _to_str
self, session=self._executed_sessions[-1])
File "/Users/wenjun.swj/Code/mars/mars/dataframe/utils.py", line 773, in fetch_corner_data
return df_or_series.fetch(session=session)
File "/Users/wenjun.swj/Code/mars/mars/core.py", line 376, in fetch
return session.fetch(self, **kw)
File "/Users/wenjun.swj/Code/mars/mars/session.py", line 491, in fetch
result = self._sess.fetch(*tileables, **kw)
File "/Users/wenjun.swj/Code/mars/mars/web/session.py", line 265, in fetch
result_data = dataserializer.loads(resp.content)
File "/Users/wenjun.swj/Code/mars/mars/serialize/dataserializer.py", line 259, in loads
return pickle.loads(data)
ModuleNotFoundError: No module named 'pyarrow'

# Fixed code
def parse_args(self, parser, argv, environ=None):
    args = super().parse_args(parser, argv)
    environ = environ or os.environ

    args.plasma_dir = args.plasma_dir or environ.get("MARS_PLASMA_DIRS")
    args.spill_dir = args.spill_dir or environ.get("MARS_SPILL_DIRS")
    args.cache_mem = args.cache_mem or environ.get("MARS_CACHE_MEM_SIZE")
    args.disable_proc_recover = args.disable_proc_recover or bool(
        int(environ.get("MARS_DISABLE_PROC_RECOVER", "0"))
    )
    args.io_parallel_num = args.io_parallel_num or int(
        environ.get("MARS_IO_PARALLEL_NUM", "1")
    )
    if args.io_parallel_num == 1 and bool(
        int(environ.get("MARS_LOCK_FREE_FILEIO", "0"))
    ):
        args.io_parallel_num = 2**16
    return args
# Buggy code
def __init__(self, lock_free=False, dispatched=True):
    super().__init__()
    self._work_items = deque()
    self._max_work_item_id = 0
    self._cur_work_items = dict()

    self._lock_free = lock_free or options.worker.lock_free_fileio
    self._lock_work_items = dict()

    self._dispatched = dispatched


# Traceback (ModuleNotFoundError)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/wenjun.swj/Code/mars/mars/core.py", line 129, in __repr__
return self._data.__repr__()
File "/Users/wenjun.swj/Code/mars/mars/dataframe/core.py", line 1083, in __repr__
return self._to_str(representation=True)
File "/Users/wenjun.swj/Code/mars/mars/dataframe/core.py", line 1053, in _to_str
self, session=self._executed_sessions[-1])
File "/Users/wenjun.swj/Code/mars/mars/dataframe/utils.py", line 773, in fetch_corner_data
return df_or_series.fetch(session=session)
File "/Users/wenjun.swj/Code/mars/mars/core.py", line 376, in fetch
return session.fetch(self, **kw)
File "/Users/wenjun.swj/Code/mars/mars/session.py", line 491, in fetch
result = self._sess.fetch(*tileables, **kw)
File "/Users/wenjun.swj/Code/mars/mars/web/session.py", line 265, in fetch
result_data = dataserializer.loads(resp.content)
File "/Users/wenjun.swj/Code/mars/mars/serialize/dataserializer.py", line 259, in loads
return pickle.loads(data)
ModuleNotFoundError: No module named 'pyarrow'

# Fixed code
def __init__(self, io_parallel_num=None, dispatched=True):
    super().__init__()
    self._work_items = deque()
    self._max_work_item_id = 0
    self._cur_work_items = dict()

    self._io_parallel_num = io_parallel_num or options.worker.io_parallel_num
    self._lock_work_items = dict()

    self._dispatched = dispatched
# Buggy code
def load_from(self, dest_device, session_id, data_keys, src_device, callback):
    logger.debug(
        "Copying %r from %s into %s submitted in %s",
        data_keys,
        src_device,
        dest_device,
        self.uid,
    )
    self._work_items.append(
        (dest_device, session_id, data_keys, src_device, False, callback)
    )
    if self._lock_free or not self._cur_work_items:
        self._submit_next()


# Traceback (ModuleNotFoundError)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/wenjun.swj/Code/mars/mars/core.py", line 129, in __repr__
return self._data.__repr__()
File "/Users/wenjun.swj/Code/mars/mars/dataframe/core.py", line 1083, in __repr__
return self._to_str(representation=True)
File "/Users/wenjun.swj/Code/mars/mars/dataframe/core.py", line 1053, in _to_str
self, session=self._executed_sessions[-1])
File "/Users/wenjun.swj/Code/mars/mars/dataframe/utils.py", line 773, in fetch_corner_data
return df_or_series.fetch(session=session)
File "/Users/wenjun.swj/Code/mars/mars/core.py", line 376, in fetch
return session.fetch(self, **kw)
File "/Users/wenjun.swj/Code/mars/mars/session.py", line 491, in fetch
result = self._sess.fetch(*tileables, **kw)
File "/Users/wenjun.swj/Code/mars/mars/web/session.py", line 265, in fetch
result_data = dataserializer.loads(resp.content)
File "/Users/wenjun.swj/Code/mars/mars/serialize/dataserializer.py", line 259, in loads
return pickle.loads(data)
ModuleNotFoundError: No module named 'pyarrow'

# Fixed code
def load_from(self, dest_device, session_id, data_keys, src_device, callback):
    logger.debug(
        "Copying %r from %s into %s submitted in %s",
        data_keys,
        src_device,
        dest_device,
        self.uid,
    )
    self._work_items.append(
        (dest_device, session_id, data_keys, src_device, False, callback)
    )
    if len(self._cur_work_items) < self._io_parallel_num:
        self._submit_next()
# Buggy code
def lock(self, session_id, data_keys, callback):
    logger.debug("Requesting lock for %r on %s", data_keys, self.uid)
    self._work_items.append((None, session_id, data_keys, None, True, callback))
    if self._lock_free or not self._cur_work_items:
        self._submit_next()


# Traceback (ModuleNotFoundError)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/wenjun.swj/Code/mars/mars/core.py", line 129, in __repr__
return self._data.__repr__()
File "/Users/wenjun.swj/Code/mars/mars/dataframe/core.py", line 1083, in __repr__
return self._to_str(representation=True)
File "/Users/wenjun.swj/Code/mars/mars/dataframe/core.py", line 1053, in _to_str
self, session=self._executed_sessions[-1])
File "/Users/wenjun.swj/Code/mars/mars/dataframe/utils.py", line 773, in fetch_corner_data
return df_or_series.fetch(session=session)
File "/Users/wenjun.swj/Code/mars/mars/core.py", line 376, in fetch
return session.fetch(self, **kw)
File "/Users/wenjun.swj/Code/mars/mars/session.py", line 491, in fetch
result = self._sess.fetch(*tileables, **kw)
File "/Users/wenjun.swj/Code/mars/mars/web/session.py", line 265, in fetch
result_data = dataserializer.loads(resp.content)
File "/Users/wenjun.swj/Code/mars/mars/serialize/dataserializer.py", line 259, in loads
return pickle.loads(data)
ModuleNotFoundError: No module named 'pyarrow'

# Fixed code
def lock(self, session_id, data_keys, callback):
    logger.debug("Requesting lock for %r on %s", data_keys, self.uid)
    self._work_items.append((None, session_id, data_keys, None, True, callback))
    if len(self._cur_work_items) < self._io_parallel_num:
        self._submit_next()
# Buggy code
def build_empty_df(dtypes, index=None):
    columns = dtypes.index
    df = pd.DataFrame(columns=columns, index=index)
    for c, d in zip(columns, dtypes):
        df[c] = pd.Series(dtype=d, index=index)
    return df


# Traceback (KeyError)
KeyError
Traceback (most recent call last)
<ipython-input-73-3d10a0dadb7d> in <module>
5 data = pd.merge(data,data.groupby(['c']).size().reset_index(),on = ['c'],how='left')
6 data = pd.merge(data,data.groupby(['d']).size().reset_index(),on = ['d'],how='left')
----> 7 data = pd.merge(data,data.groupby(['e']).size().reset_index(),on = ['3'],how='left')
8 print(data.columns.execute())

D:\kinggsoft\anaconda\lib\site-packages\mars\dataframe\merge\merge.py in merge(df, right, how, on, left_on, right_on, left_index, right_index, sort, suffixes, copy, indicator, strategy, validate)
357         left_index=left_index, right_index=right_index, sort=sort, suffixes=suffixes,
358         copy=copy, indicator=indicator, validate=validate, object_type=ObjectType.dataframe)
--> 359     return op(df, right)
360
361

D:\kinggsoft\anaconda\lib\site-packages\mars\dataframe\merge\merge.py in __call__(self, left, right)
175
176     def __call__(self, left, right):
--> 177         empty_left, empty_right = build_df(left), build_df(right)
178         # this `merge` will check whether the combination of those arguments is valid
179         merged = empty_left.merge(empty_right, how=self.how, on=self.on,

D:\kinggsoft\anaconda\lib\site-packages\mars\dataframe\utils.py in build_df(df_obj, fill_value, size)
442     empty_df = pd.concat([empty_df] * size)
443     # make sure dtypes correct for MultiIndex
--> 444     empty_df = empty_df.astype(dtypes, copy=False)
445     return empty_df
446

D:\kinggsoft\anaconda\lib\site-packages\pandas\core\generic.py in astype(self, dtype, copy, errors, **kwargs)
5863                     results.append(
5864                         col.astype(
-> 5865                             dtype=dtype[col_name], copy=copy, errors=errors, **kwargs
5866                         )
5867                     )

D:\kinggsoft\anaconda\lib\site-packages\pandas\core\generic.py in astype(self, dtype, copy, errors, **kwargs)
5846                 if len(dtype) > 1 or self.name not in dtype:
5847                     raise KeyError(
-> 5848                         "Only the Series name can be used for "
5849                         "the key in Series dtype mappings."
5850                     )

KeyError: 'Only the Series name can be used for the key in Series dtype mappings.'

# Fixed code
def build_empty_df(dtypes, index=None):
    columns = dtypes.index
    # duplicate column may exist,
    # so use RangeIndex first
    df = pd.DataFrame(columns=pd.RangeIndex(len(columns)), index=index)
    for i, d in enumerate(dtypes):
        df[i] = pd.Series(dtype=d, index=index)
    df.columns = columns
    return df
# Buggy code
def calc_data_size(dt):
    if dt is None:
        return 0

    if isinstance(dt, tuple):
        return sum(calc_data_size(c) for c in dt)

    if hasattr(dt, "nbytes"):
        return max(sys.getsizeof(dt), dt.nbytes)
    if hasattr(dt, "shape") and len(dt.shape) == 0:
        return 0
    if hasattr(dt, "memory_usage"):
        return sys.getsizeof(dt)
    if hasattr(dt, "dtypes") and hasattr(dt, "shape"):
        return dt.shape[0] * sum(dtype.itemsize for dtype in dt.dtypes)
    if hasattr(dt, "dtype") and hasattr(dt, "shape"):
        return dt.shape[0] * dt.dtype.itemsize

    # object chunk
    return sys.getsizeof(dt)


# Traceback (AttributeError)
Attempt 1: Unexpected error AttributeError occurred in executing operand b4e4bc5f7b31094fb234d9ea949251a1 in 0.0.0.0:46150
Traceback (most recent call last):
File "/Users/wenjun.swj/Code/mars/mars/promise.py", line 100, in _wrapped
result = func(*args, **kwargs)
File "/Users/wenjun.swj/Code/mars/mars/worker/calc.py", line 271, in <lambda>
.then(lambda context_dict: _start_calc(context_dict)) \
File "/Users/wenjun.swj/Code/mars/mars/worker/calc.py", line 244, in _start_calc
return self._calc_results(session_id, graph_key, graph, context_dict, chunk_targets)
File "/Users/wenjun.swj/Code/mars/mars/worker/calc.py", line 192, in _calc_results
result_sizes.append(calc_data_size(v))
File "/Users/wenjun.swj/Code/mars/mars/utils.py", line 302, in calc_data_size
return dt.shape[0] * sum(dtype.itemsize for dtype in dt.dtypes)
File "/Users/wenjun.swj/Code/mars/mars/utils.py", line 302, in <genexpr>
return dt.shape[0] * sum(dtype.itemsize for dtype in dt.dtypes)
AttributeError: 'str' object has no attribute 'itemsize'

# Fixed code
def calc_data_size(dt):
    if dt is None:
        return 0

    if isinstance(dt, tuple):
        return sum(calc_data_size(c) for c in dt)

    if hasattr(dt, "nbytes"):
        return max(sys.getsizeof(dt), dt.nbytes)
    if hasattr(dt, "shape") and len(dt.shape) == 0:
        return 0
    if hasattr(dt, "memory_usage") or hasattr(dt, "groupby_obj"):
        return sys.getsizeof(dt)
    if hasattr(dt, "dtypes") and hasattr(dt, "shape"):
        return dt.shape[0] * sum(dtype.itemsize for dtype in dt.dtypes)
    if hasattr(dt, "dtype") and hasattr(dt, "shape"):
        return dt.shape[0] * dt.dtype.itemsize

    # object chunk
    return sys.getsizeof(dt)
# Buggy code
def _start_cluster(endpoint, event, n_process=None, shared_memory=None, **kw):
    cluster = LocalDistributedCluster(
        endpoint, n_process=n_process, shared_memory=shared_memory, **kw
    )
    cluster.start_service()
    event.set()
    try:
        cluster.serve_forever()
    finally:
        cluster.stop_service()


# Traceback (AttributeError)
Traceback (most recent call last):
File "/Users/wenjun.swj/miniconda3/lib/python3.7/multiprocessing/process.py", line 297, in _bootstrap
self.run()
File "/Users/wenjun.swj/miniconda3/lib/python3.7/multiprocessing/process.py", line 99, in run
self._target(*self._args, **self._kwargs)
File "mars/lib/gipc.pyx", line 419, in mars.lib.gipc._child
target(*args, **kwargs)
File "/Users/wenjun.swj/Code/mars/mars/deploy/local/core.py", line 211, in _start_web
web.start(event=event, block=True)
File "/Users/wenjun.swj/Code/mars/mars/web/server.py", line 234, in start
self._try_start_web_server()
File "/Users/wenjun.swj/Code/mars/mars/web/server.py", line 219, in _try_start_web_server
http_server_kwargs={'max_buffer_size': 2 ** 32},
File "/Users/wenjun.swj/miniconda3/lib/python3.7/site-packages/bokeh/server/server.py", line 400, in __init__
http_server.add_sockets(sockets)
File "/Users/wenjun.swj/miniconda3/lib/python3.7/site-packages/tornado/tcpserver.py", line 166, in add_sockets
sock, self._handle_connection
File "/Users/wenjun.swj/miniconda3/lib/python3.7/site-packages/tornado/netutil.py", line 279, in add_accept_handler
io_loop.add_handler(sock, accept_handler, IOLoop.READ)
File "/Users/wenjun.swj/miniconda3/lib/python3.7/site-packages/tornado/platform/asyncio.py", line 100, in add_handler
self.asyncio_loop.add_reader(fd, self._handle_events, fd, IOLoop.READ)
File "/Users/wenjun.swj/miniconda3/lib/python3.7/asyncio/selector_events.py", line 329, in add_reader
return self._add_reader(fd, callback, *args)
File "/Users/wenjun.swj/miniconda3/lib/python3.7/asyncio/selector_events.py", line 259, in _add_reader
(handle, None))
File "/Users/wenjun.swj/miniconda3/lib/python3.7/selectors.py", line 520, in register
kev = select.kevent(key.fd, select.KQ_FILTER_READ,
AttributeError: module 'select' has no attribute 'kevent'

# Fixed code
def _start_cluster(endpoint, event, n_process=None, shared_memory=None, **kw):
    modules = kw.pop("modules", None) or []
    for m in modules:
        __import__(m, globals(), locals(), [])

    cluster = LocalDistributedCluster(
        endpoint, n_process=n_process, shared_memory=shared_memory, **kw
    )
    cluster.start_service()
    event.set()
    try:
        cluster.serve_forever()
    finally:
        cluster.stop_service()
# Buggy code
def _start_cluster_process(endpoint, n_process, shared_memory, **kw):
    event = multiprocessing.Event()

    kw = kw.copy()
    kw["n_process"] = n_process
    kw["shared_memory"] = shared_memory or "20%"
    process = gipc.start_process(_start_cluster, args=(endpoint, event), kwargs=kw)

    while True:
        event.wait(5)
        if not event.is_set():
            # service not started yet
            continue
        if not process.is_alive():
            raise SystemError("New local cluster failed")
        else:
            break

    return process


# Traceback (AttributeError)
Traceback (most recent call last):
File "/Users/wenjun.swj/miniconda3/lib/python3.7/multiprocessing/process.py", line 297, in _bootstrap
self.run()
File "/Users/wenjun.swj/miniconda3/lib/python3.7/multiprocessing/process.py", line 99, in run
self._target(*self._args, **self._kwargs)
File "mars/lib/gipc.pyx", line 419, in mars.lib.gipc._child
target(*args, **kwargs)
File "/Users/wenjun.swj/Code/mars/mars/deploy/local/core.py", line 211, in _start_web
web.start(event=event, block=True)
File "/Users/wenjun.swj/Code/mars/mars/web/server.py", line 234, in start
self._try_start_web_server()
File "/Users/wenjun.swj/Code/mars/mars/web/server.py", line 219, in _try_start_web_server
http_server_kwargs={'max_buffer_size': 2 ** 32},
File "/Users/wenjun.swj/miniconda3/lib/python3.7/site-packages/bokeh/server/server.py", line 400, in __init__
http_server.add_sockets(sockets)
File "/Users/wenjun.swj/miniconda3/lib/python3.7/site-packages/tornado/tcpserver.py", line 166, in add_sockets
sock, self._handle_connection
File "/Users/wenjun.swj/miniconda3/lib/python3.7/site-packages/tornado/netutil.py", line 279, in add_accept_handler
io_loop.add_handler(sock, accept_handler, IOLoop.READ)
File "/Users/wenjun.swj/miniconda3/lib/python3.7/site-packages/tornado/platform/asyncio.py", line 100, in add_handler
self.asyncio_loop.add_reader(fd, self._handle_events, fd, IOLoop.READ)
File "/Users/wenjun.swj/miniconda3/lib/python3.7/asyncio/selector_events.py", line 329, in add_reader
return self._add_reader(fd, callback, *args)
File "/Users/wenjun.swj/miniconda3/lib/python3.7/asyncio/selector_events.py", line 259, in _add_reader
(handle, None))
File "/Users/wenjun.swj/miniconda3/lib/python3.7/selectors.py", line 520, in register
kev = select.kevent(key.fd, select.KQ_FILTER_READ,
AttributeError: module 'select' has no attribute 'kevent'

# Fixed code
def _start_cluster_process(endpoint, n_process, shared_memory, **kw):
    event = _mp_spawn_context.Event()

    kw = kw.copy()
    kw["n_process"] = n_process
    kw["shared_memory"] = shared_memory or "20%"
    process = _mp_spawn_context.Process(
        target=_start_cluster, args=(endpoint, event), kwargs=kw
    )
    process.start()

    while True:
        event.wait(5)
        if not event.is_set():
            # service not started yet
            continue
        if not process.is_alive():
            raise SystemError("New local cluster failed")
        else:
            break

    return process
# Buggy code
def _start_web_process(scheduler_endpoint, web_endpoint):
    web_event = multiprocessing.Event()
    ui_port = int(web_endpoint.rsplit(":", 1)[1])
    web_process = gipc.start_process(
        _start_web, args=(scheduler_endpoint, ui_port, web_event), daemon=True
    )

    while True:
        web_event.wait(5)
        if not web_event.is_set():
            # web not started yet
            continue
        if not web_process.is_alive():
            raise SystemError("New web interface failed")
        else:
            break

    return web_process


# Traceback (AttributeError)
Traceback (most recent call last):
File "/Users/wenjun.swj/miniconda3/lib/python3.7/multiprocessing/process.py", line 297, in _bootstrap
self.run()
File "/Users/wenjun.swj/miniconda3/lib/python3.7/multiprocessing/process.py", line 99, in run
self._target(*self._args, **self._kwargs)
File "mars/lib/gipc.pyx", line 419, in mars.lib.gipc._child
target(*args, **kwargs)
File "/Users/wenjun.swj/Code/mars/mars/deploy/local/core.py", line 211, in _start_web
web.start(event=event, block=True)
File "/Users/wenjun.swj/Code/mars/mars/web/server.py", line 234, in start
self._try_start_web_server()
File "/Users/wenjun.swj/Code/mars/mars/web/server.py", line 219, in _try_start_web_server
http_server_kwargs={'max_buffer_size': 2 ** 32},
File "/Users/wenjun.swj/miniconda3/lib/python3.7/site-packages/bokeh/server/server.py", line 400, in __init__
http_server.add_sockets(sockets)
File "/Users/wenjun.swj/miniconda3/lib/python3.7/site-packages/tornado/tcpserver.py", line 166, in add_sockets
sock, self._handle_connection
File "/Users/wenjun.swj/miniconda3/lib/python3.7/site-packages/tornado/netutil.py", line 279, in add_accept_handler
io_loop.add_handler(sock, accept_handler, IOLoop.READ)
File "/Users/wenjun.swj/miniconda3/lib/python3.7/site-packages/tornado/platform/asyncio.py", line 100, in add_handler
self.asyncio_loop.add_reader(fd, self._handle_events, fd, IOLoop.READ)
File "/Users/wenjun.swj/miniconda3/lib/python3.7/asyncio/selector_events.py", line 329, in add_reader
return self._add_reader(fd, callback, *args)
File "/Users/wenjun.swj/miniconda3/lib/python3.7/asyncio/selector_events.py", line 259, in _add_reader
(handle, None))
File "/Users/wenjun.swj/miniconda3/lib/python3.7/selectors.py", line 520, in register
kev = select.kevent(key.fd, select.KQ_FILTER_READ,
AttributeError: module 'select' has no attribute 'kevent'

# Fixed code
def _start_web_process(scheduler_endpoint, web_endpoint):
    ui_port = int(web_endpoint.rsplit(":", 1)[1])

    web_event = _mp_spawn_context.Event()
    web_process = _mp_spawn_context.Process(
        target=_start_web, args=(scheduler_endpoint, ui_port, web_event), daemon=True
    )
    web_process.start()

    while True:
        web_event.wait(5)
        if not web_event.is_set():
            # web not started yet
            continue
        if not web_process.is_alive():
            raise SystemError("New web interface failed")
        else:
            break

    return web_process
# Buggy code
def __init__(
    self, index=None, dtypes=None, from_1d_tensors=None, gpu=None, sparse=None, **kw
):
    super().__init__(
        _index=index,
        _dtypes=dtypes,
        _from_1d_tensors=from_1d_tensors,
        _gpu=gpu,
        _sparse=sparse,
        _object_type=ObjectType.dataframe,
        **kw,
    )


# Traceback (ValueError)
In [7]: md.DataFrame({'a': '1', 'b': md.Series([1, 2, 3])}).execute()
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-7-ec6db392e00f> in <module>
----> 1 md.DataFrame({'a': '1', 'b': md.Series([1, 2, 3])}).execute()

~/Workspace/mars/mars/dataframe/initializer.py in __init__(self, data, index, columns, dtype, copy, chunk_size, gpu, sparse)
46             df = dataframe_from_1d_tensors(
47                 tensors, index=index, columns=columns,
---> 48                 gpu=gpu, sparse=sparse)
49         else:
50             pdf = pd.DataFrame(data, index=index, columns=columns, dtype=dtype, copy=copy)

~/Workspace/mars/mars/dataframe/datasource/from_tensor.py in dataframe_from_1d_tensors(tensors, index, columns, gpu, sparse)
328     op = DataFrameFromTensor(dtypes=dtypes, from_1d_tensors=True,
329                              gpu=gpu, sparse=sparse)
--> 330     return op(tensors, index, columns)
331
332

~/Workspace/mars/mars/dataframe/datasource/from_tensor.py in __call__(self, input_tensor, index, columns)
73     def __call__(self, input_tensor, index, columns):
74         if self._from_1d_tensors:
---> 75             return self._call_input_1d_tensors(input_tensor, index, columns)
76         else:
77             return self._call_input_tensor(input_tensor, index, columns)

~/Workspace/mars/mars/dataframe/datasource/from_tensor.py in _call_input_1d_tensors(self, input_1d_tensors, index, columns)
99     def _call_input_1d_tensors(self, input_1d_tensors, index, columns):
100         if len({t.shape for t in input_1d_tensors}) != 1:
--> 101             raise ValueError('input 1-d tensors should have same shape')
102
103         inputs = list(input_1d_tensors)

ValueError: input 1-d tensors should have same shape

# Fixed code
def __init__(self, input_=None, index=None, dtypes=None, gpu=None, sparse=None, **kw):
    super().__init__(
        _input=input_,
        _index=index,
        _dtypes=dtypes,
        _gpu=gpu,
        _sparse=sparse,
        _object_type=ObjectType.dataframe,
        **kw,
    )
# Buggy code
def _set_inputs(self, inputs):
    super()._set_inputs(inputs)
    if not self._from_1d_tensors:
        self._input = inputs[0]
    if self._index is not None:
        self._index = inputs[-1]


# Traceback (ValueError)
In [7]: md.DataFrame({'a': '1', 'b': md.Series([1, 2, 3])}).execute()
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-7-ec6db392e00f> in <module>
----> 1 md.DataFrame({'a': '1', 'b': md.Series([1, 2, 3])}).execute()

~/Workspace/mars/mars/dataframe/initializer.py in __init__(self, data, index, columns, dtype, copy, chunk_size, gpu, sparse)
46             df = dataframe_from_1d_tensors(
47                 tensors, index=index, columns=columns,
---> 48                 gpu=gpu, sparse=sparse)
49         else:
50             pdf = pd.DataFrame(data, index=index, columns=columns, dtype=dtype, copy=copy)

~/Workspace/mars/mars/dataframe/datasource/from_tensor.py in dataframe_from_1d_tensors(tensors, index, columns, gpu, sparse)
328     op = DataFrameFromTensor(dtypes=dtypes, from_1d_tensors=True,
329                              gpu=gpu, sparse=sparse)
--> 330     return op(tensors, index, columns)
331
332

~/Workspace/mars/mars/dataframe/datasource/from_tensor.py in __call__(self, input_tensor, index, columns)
73     def __call__(self, input_tensor, index, columns):
74         if self._from_1d_tensors:
---> 75             return self._call_input_1d_tensors(input_tensor, index, columns)
76         else:
77             return self._call_input_tensor(input_tensor, index, columns)

~/Workspace/mars/mars/dataframe/datasource/from_tensor.py in _call_input_1d_tensors(self, input_1d_tensors, index, columns)
99     def _call_input_1d_tensors(self, input_1d_tensors, index, columns):
100         if len({t.shape for t in input_1d_tensors}) != 1:
--> 101             raise ValueError('input 1-d tensors should have same shape')
102
103         inputs = list(input_1d_tensors)

ValueError: input 1-d tensors should have same shape

# Fixed code
def _set_inputs(self, inputs):
    super()._set_inputs(inputs)
    inputs_iter = iter(self._inputs)
    if self._input is not None:
        if not isinstance(self._input, dict):
            self._input = next(inputs_iter)
        else:
            # check each value for input
            new_input = OrderedDict()
            for k, v in self._input.items():
                if isinstance(v, (Base, Entity)):
                    new_input[k] = next(inputs_iter)
                else:
                    new_input[k] = v
            self._input = new_input

    if self._index is not None:
        self._index = next(inputs_iter)
# Buggy code
def __call__(self, input_tensor, index, columns):
    if self._from_1d_tensors:
        return self._call_input_1d_tensors(input_tensor, index, columns)
    else:
        return self._call_input_tensor(input_tensor, index, columns)


# Traceback (ValueError)
In [7]: md.DataFrame({'a': '1', 'b': md.Series([1, 2, 3])}).execute()
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-7-ec6db392e00f> in <module>
----> 1 md.DataFrame({'a': '1', 'b': md.Series([1, 2, 3])}).execute()

~/Workspace/mars/mars/dataframe/initializer.py in __init__(self, data, index, columns, dtype, copy, chunk_size, gpu, sparse)
46             df = dataframe_from_1d_tensors(
47                 tensors, index=index, columns=columns,
---> 48                 gpu=gpu, sparse=sparse)
49         else:
50             pdf = pd.DataFrame(data, index=index, columns=columns, dtype=dtype, copy=copy)

~/Workspace/mars/mars/dataframe/datasource/from_tensor.py in dataframe_from_1d_tensors(tensors, index, columns, gpu, sparse)
328     op = DataFrameFromTensor(dtypes=dtypes, from_1d_tensors=True,
329                              gpu=gpu, sparse=sparse)
--> 330     return op(tensors, index, columns)
331
332

~/Workspace/mars/mars/dataframe/datasource/from_tensor.py in __call__(self, input_tensor, index, columns)
73     def __call__(self, input_tensor, index, columns):
74         if self._from_1d_tensors:
---> 75             return self._call_input_1d_tensors(input_tensor, index, columns)
76         else:
77             return self._call_input_tensor(input_tensor, index, columns)

~/Workspace/mars/mars/dataframe/datasource/from_tensor.py in _call_input_1d_tensors(self, input_1d_tensors, index, columns)
99     def _call_input_1d_tensors(self, input_1d_tensors, index, columns):
100         if len({t.shape for t in input_1d_tensors}) != 1:
--> 101             raise ValueError('input 1-d tensors should have same shape')
102
103         inputs = list(input_1d_tensors)

ValueError: input 1-d tensors should have same shape

# Fixed code
def __call__(self, input_tensor, index, columns):
    if isinstance(input_tensor, dict):
        return self._call_input_1d_tileables(input_tensor, index, columns)
    else:
        return self._call_input_tensor(input_tensor, index, columns)
# Buggy code
def tile(cls, op):
    # make sure all tensor have known chunk shapes
    check_chunks_unknown_shape(op.inputs, TilesError)

    if op.from_1d_tensors:
        return cls._tile_input_1d_tensors(op)
    else:
        return cls._tile_input_tensor(op)


# Traceback (ValueError)
In [7]: md.DataFrame({'a': '1', 'b': md.Series([1, 2, 3])}).execute()
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-7-ec6db392e00f> in <module>
----> 1 md.DataFrame({'a': '1', 'b': md.Series([1, 2, 3])}).execute()

~/Workspace/mars/mars/dataframe/initializer.py in __init__(self, data, index, columns, dtype, copy, chunk_size, gpu, sparse)
46             df = dataframe_from_1d_tensors(
47                 tensors, index=index, columns=columns,
---> 48                 gpu=gpu, sparse=sparse)
49         else:
50             pdf = pd.DataFrame(data, index=index, columns=columns, dtype=dtype, copy=copy)

~/Workspace/mars/mars/dataframe/datasource/from_tensor.py in dataframe_from_1d_tensors(tensors, index, columns, gpu, sparse)
328     op = DataFrameFromTensor(dtypes=dtypes, from_1d_tensors=True,
329                              gpu=gpu, sparse=sparse)
--> 330     return op(tensors, index, columns)
331
332

~/Workspace/mars/mars/dataframe/datasource/from_tensor.py in __call__(self, input_tensor, index, columns)
73     def __call__(self, input_tensor, index, columns):
74         if self._from_1d_tensors:
---> 75             return self._call_input_1d_tensors(input_tensor, index, columns)
76         else:
77             return self._call_input_tensor(input_tensor, index, columns)

~/Workspace/mars/mars/dataframe/datasource/from_tensor.py in _call_input_1d_tensors(self, input_1d_tensors, index, columns)
99     def _call_input_1d_tensors(self, input_1d_tensors, index, columns):
100         if len({t.shape for t in input_1d_tensors}) != 1:
--> 101             raise ValueError('input 1-d tensors should have same shape')
102
103         inputs = list(input_1d_tensors)

ValueError: input 1-d tensors should have same shape

# Fixed code
def tile(cls, op):
    # make sure all tensor have known chunk shapes
    check_chunks_unknown_shape(op.inputs, TilesError)

    if isinstance(op.input, dict):
        return cls._tile_input_1d_tileables(op)
    else:
        return cls._tile_input_tensor(op)
# Buggy code
def dataframe_from_tensor(tensor, index=None, columns=None, gpu=None, sparse=False):
    if tensor.ndim > 2 or tensor.ndim <= 0:
        raise TypeError(
            "Not support create DataFrame from {0} dims tensor", format(tensor.ndim)
        )
    try:
        col_num = tensor.shape[1]
    except IndexError:
        col_num = 1
    gpu = tensor.op.gpu if gpu is None else gpu
    op = DataFrameFromTensor(
        dtypes=pd.Series([tensor.dtype] * col_num, index=columns),
        gpu=gpu,
        sparse=sparse,
    )
    return op(tensor, index, columns)


# Traceback (ValueError)
In [7]: md.DataFrame({'a': '1', 'b': md.Series([1, 2, 3])}).execute()
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-7-ec6db392e00f> in <module>
----> 1 md.DataFrame({'a': '1', 'b': md.Series([1, 2, 3])}).execute()

~/Workspace/mars/mars/dataframe/initializer.py in __init__(self, data, index, columns, dtype, copy, chunk_size, gpu, sparse)
46             df = dataframe_from_1d_tensors(
47                 tensors, index=index, columns=columns,
---> 48                 gpu=gpu, sparse=sparse)
49         else:
50             pdf = pd.DataFrame(data, index=index, columns=columns, dtype=dtype, copy=copy)

~/Workspace/mars/mars/dataframe/datasource/from_tensor.py in dataframe_from_1d_tensors(tensors, index, columns, gpu, sparse)
328     op = DataFrameFromTensor(dtypes=dtypes, from_1d_tensors=True,
329                              gpu=gpu, sparse=sparse)
--> 330     return op(tensors, index, columns)
331
332

~/Workspace/mars/mars/dataframe/datasource/from_tensor.py in __call__(self, input_tensor, index, columns)
73     def __call__(self, input_tensor, index, columns):
74         if self._from_1d_tensors:
---> 75             return self._call_input_1d_tensors(input_tensor, index, columns)
76         else:
77             return self._call_input_tensor(input_tensor, index, columns)

~/Workspace/mars/mars/dataframe/datasource/from_tensor.py in _call_input_1d_tensors(self, input_1d_tensors, index, columns)
99     def _call_input_1d_tensors(self, input_1d_tensors, index, columns):
100         if len({t.shape for t in input_1d_tensors}) != 1:
--> 101             raise ValueError('input 1-d tensors should have same shape')
102
103         inputs = list(input_1d_tensors)

ValueError: input 1-d tensors should have same shape

# Fixed code
def dataframe_from_tensor(tensor, index=None, columns=None, gpu=None, sparse=False):
    if tensor.ndim > 2 or tensor.ndim <= 0:
        raise TypeError(
            "Not support create DataFrame from {0} dims tensor", format(tensor.ndim)
        )
    try:
        col_num = tensor.shape[1]
    except IndexError:
        col_num = 1
    gpu = tensor.op.gpu if gpu is None else gpu
    op = DataFrameFromTensor(
        input_=tensor,
        dtypes=pd.Series([tensor.dtype] * col_num, index=columns),
        gpu=gpu,
        sparse=sparse,
    )
    return op(tensor, index, columns)