# Buggy code
def _tile_with_tensor(cls, op):
    rhs_is_tensor = isinstance(op.rhs, TENSOR_TYPE)
    tensor, other = (op.rhs, op.lhs) if rhs_is_tensor else (op.lhs, op.rhs)
    if tensor.shape == other.shape:
        tensor = tensor.rechunk(other.nsplits)._inplace_tile()
    else:
        # shape differs only when dataframe add 1-d tensor, we need rechunk on columns axis.
        rechunk_size = (
            other.nsplits[1]
            if op.axis == "columns" or op.axis == 1
            else other.nsplits[0]
        )
        if tensor.ndim > 0:
            tensor = tensor.rechunk((rechunk_size,))._inplace_tile()

    out_chunks = []
    for out_index in itertools.product(*(map(range, other.chunk_shape))):
        tensor_chunk = tensor.cix[out_index[: tensor.ndim]]
        other_chunk = other.cix[out_index]
        out_op = op.copy().reset_key()
        inputs = (
            [other_chunk, tensor_chunk]
            if rhs_is_tensor
            else [tensor_chunk, other_chunk]
        )
        if isinstance(other_chunk, DATAFRAME_CHUNK_TYPE):
            out_chunk = out_op.new_chunk(
                inputs,
                shape=other_chunk.shape,
                index=other_chunk.index,
                dtypes=other_chunk.dtypes,
                index_value=other_chunk.index_value,
                columns_value=other.columns_value,
            )
        else:
            out_chunk = out_op.new_chunk(
                inputs,
                shape=other_chunk.shape,
                index=other_chunk.index,
                dtype=other_chunk.dtype,
                index_value=other_chunk.index_value,
                name=other_chunk.name,
            )
        out_chunks.append(out_chunk)

    new_op = op.copy()
    out = op.outputs[0]
    if isinstance(other, SERIES_TYPE):
        return new_op.new_seriess(
            op.inputs,
            other.shape,
            nsplits=other.nsplits,
            dtype=out.dtype,
            index_value=other.index_value,
            chunks=out_chunks,
        )
    else:
        return new_op.new_dataframes(
            op.inputs,
            other.shape,
            nsplits=other.nsplits,
            dtypes=out.dtypes,
            index_value=other.index_value,
            columns_value=other.columns_value,
            chunks=out_chunks,
        )


# Traceback (IndexError)
In [9]: df = md.DataFrame({'a': [1, 2, 3], 'b': [1.1, 2.2, 3.3],
...:                                     'c': [datetime(2020, 1, 1), datetime.now(), datetime(2000, 3, 3, 11, 22, 23)]})
In[10]: df[(df['c'] > md.to_datetime('2020-08-01')) &amp; (df['c'] < md.to_datetime('2020-11-01'))].head().execute()
Traceback (most recent call last):
File "/Users/qinxuye/miniconda3/lib/python3.7/site-packages/IPython/core/interactiveshell.py", line 3331, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-10-d9c9c3710287>", line 1, in <module>
df[(df['c'] > md.to_datetime('2020-08-01')) &amp; (df['c'] < md.to_datetime('2020-11-01'))].head().execute()
File "/Users/qinxuye/Workspace/mars/mars/core.py", line 640, in execute
return run()
File "/Users/qinxuye/Workspace/mars/mars/core.py", line 636, in run
self.data.execute(session, **kw)
File "/Users/qinxuye/Workspace/mars/mars/core.py", line 376, in execute
return run()
File "/Users/qinxuye/Workspace/mars/mars/core.py", line 371, in run
session.run(self, **kw)
File "/Users/qinxuye/Workspace/mars/mars/session.py", line 500, in run
result = self._sess.run(*tileables, **kw)
File "/Users/qinxuye/Workspace/mars/mars/session.py", line 108, in run
res = self._executor.execute_tileables(tileables, **kw)
File "/Users/qinxuye/Workspace/mars/mars/utils.py", line 439, in _inner
return func(*args, **kwargs)
File "/Users/qinxuye/Workspace/mars/mars/executor.py", line 861, in execute_tileables
tileables, tileable_graph=tileable_graph)
File "/Users/qinxuye/Workspace/mars/mars/utils.py", line 439, in _inner
return func(*args, **kwargs)
File "/Users/qinxuye/Workspace/mars/mars/tiles.py", line 348, in build
tileables, tileable_graph=tileable_graph)
File "/Users/qinxuye/Workspace/mars/mars/utils.py", line 439, in _inner
return func(*args, **kwargs)
File "/Users/qinxuye/Workspace/mars/mars/tiles.py", line 262, in build
self._on_tile_failure(tileable_data.op, exc_info)
File "/Users/qinxuye/Workspace/mars/mars/tiles.py", line 301, in inner
raise exc_info[1].with_traceback(exc_info[2]) from None
File "/Users/qinxuye/Workspace/mars/mars/tiles.py", line 242, in build
tiled = self._tile(tileable_data, tileable_graph)
File "/Users/qinxuye/Workspace/mars/mars/tiles.py", line 337, in _tile
return super()._tile(tileable_data, tileable_graph)
File "/Users/qinxuye/Workspace/mars/mars/tiles.py", line 201, in _tile
tds[0]._inplace_tile()
File "/Users/qinxuye/Workspace/mars/mars/core.py", line 165, in _inplace_tile
return handler.inplace_tile(self)
File "/Users/qinxuye/Workspace/mars/mars/tiles.py", line 136, in inplace_tile
dispatched = self.dispatch(to_tile.op)
File "/Users/qinxuye/Workspace/mars/mars/utils.py", line 439, in _inner
return func(*args, **kwargs)
File "/Users/qinxuye/Workspace/mars/mars/tiles.py", line 119, in dispatch
tiled = op_cls.tile(op)
File "/Users/qinxuye/Workspace/mars/mars/dataframe/arithmetic/core.py", line 261, in tile
return cls._tile_with_tensor(op)
File "/Users/qinxuye/Workspace/mars/mars/dataframe/arithmetic/core.py", line 216, in _tile_with_tensor
rechunk_size = other.nsplits[1] if op.axis == 'columns' or op.axis == 1 else other.nsplits[0]
IndexError: tuple index out of range

# Fixed code
def _tile_with_tensor(cls, op):
    out = op.outputs[0]
    axis = op.axis

    rhs_is_tensor = isinstance(op.rhs, TENSOR_TYPE)
    tensor, other = (op.rhs, op.lhs) if rhs_is_tensor else (op.lhs, op.rhs)
    if tensor.shape == other.shape:
        tensor = tensor.rechunk(other.nsplits)._inplace_tile()
    else:
        # shape differs only when dataframe add 1-d tensor, we need rechunk on columns axis.
        if op.axis in ["columns", 1] and other.ndim == 1:
            # force axis == 0 if it's Series other than DataFrame
            axis = 0
        rechunk_size = (
            other.nsplits[1] if axis == "columns" or axis == 1 else other.nsplits[0]
        )
        if tensor.ndim > 0:
            tensor = tensor.rechunk((rechunk_size,))._inplace_tile()

    cum_splits = [0] + np.cumsum(other.nsplits[axis]).tolist()
    out_chunks = []
    for out_index in itertools.product(*(map(range, other.chunk_shape))):
        tensor_chunk = tensor.cix[out_index[: tensor.ndim]]
        other_chunk = other.cix[out_index]
        out_op = op.copy().reset_key()
        inputs = (
            [other_chunk, tensor_chunk]
            if rhs_is_tensor
            else [tensor_chunk, other_chunk]
        )
        if isinstance(other_chunk, DATAFRAME_CHUNK_TYPE):
            start = cum_splits[out_index[axis]]
            end = cum_splits[out_index[axis] + 1]
            chunk_dtypes = out.dtypes.iloc[start:end]
            out_chunk = out_op.new_chunk(
                inputs,
                shape=other_chunk.shape,
                index=other_chunk.index,
                dtypes=chunk_dtypes,
                index_value=other_chunk.index_value,
                columns_value=other.columns_value,
            )
        else:
            out_chunk = out_op.new_chunk(
                inputs,
                shape=other_chunk.shape,
                index=other_chunk.index,
                dtype=out.dtype,
                index_value=other_chunk.index_value,
                name=other_chunk.name,
            )
        out_chunks.append(out_chunk)

    new_op = op.copy()
    if isinstance(other, SERIES_TYPE):
        return new_op.new_seriess(
            op.inputs,
            other.shape,
            nsplits=other.nsplits,
            dtype=out.dtype,
            index_value=other.index_value,
            chunks=out_chunks,
        )
    else:
        return new_op.new_dataframes(
            op.inputs,
            other.shape,
            nsplits=other.nsplits,
            dtypes=out.dtypes,
            index_value=other.index_value,
            columns_value=other.columns_value,
            chunks=out_chunks,
        )