gurudesh/pytracebugs huggingface dataset:
# Buggy code
def validate_axis(axis, tileable=None):
    if axis == "index":
        axis = 0
    elif axis == "columns":
        axis = 1

    illegal = False
    try:
        axis = operator.index(axis)
        if axis < 0 or (tileable and axis >= tileable.ndim):
            illegal = True
    except TypeError:
        illegal = True

    if illegal:
        raise ValueError(
            "No axis named {} for object type {}".format(axis, type(tileable))
        )
    return axis


# Traceback (ValueError)
import mars.dataframe as md
df = md.read_csv('/home/xuye.qin/ml-20m/ratings.csv')
df.sort_values(by='rating')
Traceback (most recent call last):
File "/home/xuye.qin/miniconda3/lib/python3.7/site-packages/IPython/core/interactiveshell.py", line 3296, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-4-d04621974535>", line 1, in <module>
df.sort_values(by='rating')
File "/tmp/pycharm_project_852/mars/dataframe/sort/sort_values.py", line 181, in dataframe_sort_values
axis = validate_axis(axis, df)
File "/tmp/pycharm_project_852/mars/dataframe/utils.py", line 623, in validate_axis
'object type {}'.format(axis, type(tileable)))
ValueError: No axis named 0 for object type <class 'mars.dataframe.core.DataFrame'>

# Fixed code
def validate_axis(axis, tileable=None):
    if axis == "index":
        axis = 0
    elif axis == "columns":
        axis = 1

    illegal = False
    try:
        axis = operator.index(axis)
        if axis < 0 or (tileable is not None and axis >= tileable.ndim):
            illegal = True
    except TypeError:
        illegal = True

    if illegal:
        raise ValueError(
            "No axis named {} for object type {}".format(axis, type(tileable))
        )
    return axis
# Buggy code
def execute(cls, ctx, op):
    inputs, device_id, xp = as_same_device(
        [ctx[c.key] for c in op.inputs], device=op.device, ret_extra=True
    )

    with device(device_id):
        a = xp.concatenate(inputs, axis=op.axis)
        p = len(inputs)
        assert a.shape[op.axis] == p**2

        if op.kind is not None:
            # sort
            _sort(a, op, xp, inplace=True)
        else:
            # prepare for sampling via `partition`
            kth = xp.arange(p - 1, (p - 1) ** 2 + 1, p - 1)
            a.partition(kth, axis=op.axis)

        select = slice(p - 1, (p - 1) ** 2 + 1, p - 1)
        slc = (slice(None),) * op.axis + (select,)
        ctx[op.outputs[0].key] = a[slc]


# Traceback (ValueError)
import mars.dataframe as md
df = md.read_csv('/home/xuye.qin/ml-20m/ratings.csv')
df.sort_values(by='rating')
Traceback (most recent call last):
File "/home/xuye.qin/miniconda3/lib/python3.7/site-packages/IPython/core/interactiveshell.py", line 3296, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-4-d04621974535>", line 1, in <module>
df.sort_values(by='rating')
File "/tmp/pycharm_project_852/mars/dataframe/sort/sort_values.py", line 181, in dataframe_sort_values
axis = validate_axis(axis, df)
File "/tmp/pycharm_project_852/mars/dataframe/utils.py", line 623, in validate_axis
'object type {}'.format(axis, type(tileable)))
ValueError: No axis named 0 for object type <class 'mars.dataframe.core.DataFrame'>

# Fixed code
def execute(cls, ctx, op):
    inputs, device_id, xp = as_same_device(
        [ctx[c.key] for c in op.inputs], device=op.device, ret_extra=True
    )

    with device(device_id):
        a = xp.concatenate(inputs, axis=op.axis)
        p = len(inputs)
        assert a.shape[op.axis] == p**2

        if op.kind is not None:
            # sort
            _sort(a, op, xp, inplace=True)
        else:
            # prepare for sampling via `partition`
            kth = xp.arange(p - 1, (p - 1) ** 2 + 1, p - 1)
            a.partition(kth, axis=op.axis)

        select = slice(p, p**2 + 1, p)
        slc = (slice(None),) * op.axis + (select,)
        ctx[op.outputs[0].key] = result = a[slc]
        assert result.shape[op.axis] == p - 1
# Buggy code
def set_operand_state(self, op_key, state):
    if (
        op_key not in self._operand_infos
        and self._chunk_graph_builder.iterative_chunk_graphs
        and state == OperandState.FREED
    ):
        # if iterative tiling is entered,
        # the `_operand_infos` will be a completely new one,
        # in this case, we don't actually care about if the op is freed
        return

    op_info = self._operand_infos[op_key]
    op_info["state"] = state
    self._graph_meta_ref.update_op_state(
        op_key, op_info["op_name"], state, _tell=True, _wait=False
    )
    try:
        del op_info["failover_state"]
    except KeyError:
        pass


# Traceback (AttributeError)
Traceback (most recent call last):
File "mars/serialize/pbserializer.pyx", line 527, in mars.serialize.pbserializer.ProtobufSerializeProvider.serialize_field
field_obj = getattr(obj, tag)
AttributeError: index_value

# Fixed code
def set_operand_state(self, op_key, state):
    if (
        op_key not in self._operand_infos
        and self._chunk_graph_builder.iterative_chunk_graphs
        and state == OperandState.FREED
    ):
        # if iterative tiling is entered,
        # the `_operand_infos` will be a completely new one,
        # in this case, we don't actually care about if the op is freed
        return
    if op_key not in self._operand_infos and self.state in GraphState.TERMINATED_STATES:
        # if operand has been cleared in iterative tiling and execute again in another
        # graph, just ignore it.
        return
    op_info = self._operand_infos[op_key]
    op_info["state"] = state
    self._graph_meta_ref.update_op_state(
        op_key, op_info["op_name"], state, _tell=True, _wait=False
    )
    try:
        del op_info["failover_state"]
    except KeyError:
        pass
# Buggy code
def set_operand_worker(self, op_key, worker):
    op_info = self._operand_infos[op_key]
    if worker:
        op_info["worker"] = worker
    else:
        try:
            del op_info["worker"]
        except KeyError:
            pass
    self._graph_meta_ref.update_op_worker(
        op_key, op_info["op_name"], worker, _tell=True, _wait=False
    )


# Traceback (AttributeError)
Traceback (most recent call last):
File "mars/serialize/pbserializer.pyx", line 527, in mars.serialize.pbserializer.ProtobufSerializeProvider.serialize_field
field_obj = getattr(obj, tag)
AttributeError: index_value

# Fixed code
def set_operand_worker(self, op_key, worker):
    if op_key not in self._operand_infos and self.state in GraphState.TERMINATED_STATES:
        # if operand has been cleared in iterative tiling and execute again in another
        # graph, just ignore it.
        return
    op_info = self._operand_infos[op_key]
    if worker:
        op_info["worker"] = worker
    else:
        try:
            del op_info["worker"]
        except KeyError:
            pass
    self._graph_meta_ref.update_op_worker(
        op_key, op_info["op_name"], worker, _tell=True, _wait=False
    )
# Buggy code
def append_graph(self, graph_key, op_info):
    from ..graph import GraphActor

    if not self._is_terminal:
        self._is_terminal = op_info.get("is_terminal")
    graph_ref = self.get_actor_ref(GraphActor.gen_uid(self._session_id, graph_key))
    self._graph_refs.append(graph_ref)
    self._pred_keys.update(op_info["io_meta"]["predecessors"])
    self._succ_keys.update(op_info["io_meta"]["successors"])
    if (
        self._state not in OperandState.STORED_STATES
        and self._state != OperandState.RUNNING
    ):
        self._state = op_info["state"]


# Traceback (AttributeError)
Traceback (most recent call last):
File "mars/serialize/pbserializer.pyx", line 527, in mars.serialize.pbserializer.ProtobufSerializeProvider.serialize_field
field_obj = getattr(obj, tag)
AttributeError: index_value

# Fixed code
def append_graph(self, graph_key, op_info):
    from ..graph import GraphActor

    if not self._is_terminal:
        self._is_terminal = op_info.get("is_terminal")
    graph_ref = self.get_actor_ref(GraphActor.gen_uid(self._session_id, graph_key))
    self._graph_refs.append(graph_ref)
    self._pred_keys.update(op_info["io_meta"]["predecessors"])
    self._succ_keys.update(op_info["io_meta"]["successors"])
    if (
        self._state not in OperandState.STORED_STATES
        and self._state != OperandState.RUNNING
    ):
        self._state = op_info["state"]
    if self._state not in OperandState.TERMINATED_STATES:
        self.start_operand()
# Buggy code
def _add_finished_terminal(self, final_state=None, exc=None):
    futures = []
    for graph_ref in self._graph_refs:
        futures.append(
            graph_ref.add_finished_terminal(
                self._op_key, final_state=final_state, exc=exc, _tell=True, _wait=False
            )
        )

    return futures


# Traceback (AttributeError)
Traceback (most recent call last):
File "mars/serialize/pbserializer.pyx", line 527, in mars.serialize.pbserializer.ProtobufSerializeProvider.serialize_field
field_obj = getattr(obj, tag)
AttributeError: index_value

# Fixed code
def _add_finished_terminal(self, final_state=None, exc=None):
    futures = []
    for graph_ref in self._graph_refs:
        if graph_ref.reload_state() in (GraphState.RUNNING, GraphState.CANCELLING):
            futures.append(
                graph_ref.add_finished_terminal(
                    self._op_key,
                    final_state=final_state,
                    exc=exc,
                    _tell=True,
                    _wait=False,
                )
            )

    return futures
# Buggy code
def add(df, other, axis="columns", level=None, fill_value=None):
    other = wrap_sequence(other)
    op = DataFrameAdd(axis=axis, level=level, fill_value=fill_value, lhs=df, rhs=other)
    return op(df, other)


# 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 add(df, other, axis="columns", level=None, fill_value=None):
    op = DataFrameAdd(axis=axis, level=level, fill_value=fill_value, lhs=df, rhs=other)
    return op(df, other)
# Buggy code
def radd(df, other, axis="columns", level=None, fill_value=None):
    other = wrap_sequence(other)
    op = DataFrameAdd(axis=axis, level=level, fill_value=fill_value, lhs=other, rhs=df)
    return op.rcall(df, other)


# 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 radd(df, other, axis="columns", level=None, fill_value=None):
    op = DataFrameAdd(axis=axis, level=level, fill_value=fill_value, lhs=other, rhs=df)
    return op.rcall(df, other)
# Buggy code
def __call__(self, x1, x2):
    if isinstance(x1, SERIES_TYPE) and isinstance(x2, DATAFRAME_TYPE):
        # reject invokeing series's op on dataframe
        raise NotImplementedError
    return self._call(x1, x2)


# 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, x1, x2):
    x1 = self._process_input(x1)
    x2 = self._process_input(x2)
    if isinstance(x1, SERIES_TYPE) and isinstance(x2, DATAFRAME_TYPE):
        # reject invoking series's op on dataframe
        raise NotImplementedError
    return self._call(x1, x2)
# Buggy code
def rcall(self, x1, x2):
    if isinstance(x1, SERIES_TYPE) and isinstance(x2, DATAFRAME_TYPE):
        # reject invokeing series's op on dataframe
        raise NotImplementedError
    return self._call(x2, x1)


# 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 rcall(self, x1, x2):
    x1 = self._process_input(x1)
    x2 = self._process_input(x2)
    if isinstance(x1, SERIES_TYPE) and isinstance(x2, DATAFRAME_TYPE):
        # reject invoking series's op on dataframe
        raise NotImplementedError
    return self._call(x2, x1)
# Buggy code
def __call__(self, df):
    return self.new_dataframe(
        [df],
        df.shape,
        dtypes=df.dtypes,
        columns_value=df.columns,
        index_value=df.index_value,
    )


# 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):
    return self.new_dataframe(
        [df],
        df.shape,
        dtypes=df.dtypes,
        columns_value=df.columns_value,
        index_value=df.index_value,
    )
# Buggy code
def floordiv(df, other, axis="columns", level=None, fill_value=None):
    other = wrap_sequence(other)
    op = DataFrameFloorDiv(
        axis=axis, level=level, fill_value=fill_value, lhs=df, rhs=other
    )
    return op(df, other)


# 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 floordiv(df, other, axis="columns", level=None, fill_value=None):
    op = DataFrameFloorDiv(
        axis=axis, level=level, fill_value=fill_value, lhs=df, rhs=other
    )
    return op(df, other)
# Buggy code
def rfloordiv(df, other, axis="columns", level=None, fill_value=None):
    other = wrap_sequence(other)
    op = DataFrameFloorDiv(
        axis=axis, level=level, fill_value=fill_value, lhs=other, rhs=df
    )
    return op.rcall(df, other)


# 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 rfloordiv(df, other, axis="columns", level=None, fill_value=None):
    op = DataFrameFloorDiv(
        axis=axis, level=level, fill_value=fill_value, lhs=other, rhs=df
    )
    return op.rcall(df, other)
# Buggy code
def subtract(df, other, axis="columns", level=None, fill_value=None):
    other = wrap_sequence(other)
    op = DataFrameSubtract(
        axis=axis, level=level, fill_value=fill_value, lhs=df, rhs=other
    )
    return op(df, other)


# 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 subtract(df, other, axis="columns", level=None, fill_value=None):
    op = DataFrameSubtract(
        axis=axis, level=level, fill_value=fill_value, lhs=df, rhs=other
    )
    return op(df, other)
# Buggy code
def rsubtract(df, other, axis="columns", level=None, fill_value=None):
    other = wrap_sequence(other)
    op = DataFrameSubtract(
        axis=axis, level=level, fill_value=fill_value, lhs=other, rhs=df
    )
    return op.rcall(df, other)


# 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 rsubtract(df, other, axis="columns", level=None, fill_value=None):
    op = DataFrameSubtract(
        axis=axis, level=level, fill_value=fill_value, lhs=other, rhs=df
    )
    return op.rcall(df, other)
# Buggy code
def truediv(df, other, axis="columns", level=None, fill_value=None):
    other = wrap_sequence(other)
    op = DataFrameTrueDiv(
        axis=axis, level=level, fill_value=fill_value, lhs=df, rhs=other
    )
    return op(df, other)


# 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 truediv(df, other, axis="columns", level=None, fill_value=None):
    op = DataFrameTrueDiv(
        axis=axis, level=level, fill_value=fill_value, lhs=df, rhs=other
    )
    return op(df, other)
# Buggy code
def rtruediv(df, other, axis="columns", level=None, fill_value=None):
    other = wrap_sequence(other)
    op = DataFrameTrueDiv(
        axis=axis, level=level, fill_value=fill_value, lhs=other, rhs=df
    )
    return op.rcall(df, other)


# 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 rtruediv(df, other, axis="columns", level=None, fill_value=None):
    op = DataFrameTrueDiv(
        axis=axis, level=level, fill_value=fill_value, lhs=other, rhs=df
    )
    return op.rcall(df, other)
# Buggy code
def params(self):
    # params return the properties which useful to rebuild a new chunk
    return {
        "shape": self.shape,
        "dtypes": self.dtypes,
        "index": self.index,
        "index_value": self.index_value,
        "columns_value": self.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 params(self):
    # params return the properties which useful to rebuild a new chunk
    return {
        "shape": self.shape,
        "dtypes": self.dtypes,
        "index": self.index,
        "index_value": self.index_value,
        "columns_value": self.columns_value,
    }
# Buggy code
def params(self):
    # params return the properties which useful to rebuild a new tileable object
    return {
        "shape": self.shape,
        "dtypes": self.dtypes,
        "index_value": self.index_value,
        "columns_value": self.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 params(self):
    # params return the properties which useful to rebuild a new tileable object
    return {
        "shape": self.shape,
        "dtypes": self.dtypes,
        "index_value": self.index_value,
        "columns_value": self.columns_value,
    }