# Buggy code
def _calc_properties(cls, x1, x2=None, axis="columns"):
    if isinstance(x1, (DATAFRAME_TYPE, DATAFRAME_CHUNK_TYPE)) and (
        x2 is None or pd.api.types.is_scalar(x2) or isinstance(x2, TENSOR_TYPE)
    ):
        if x2 is None:
            dtypes = x1.dtypes
        elif pd.api.types.is_scalar(x2):
            dtypes = cls._operator(build_empty_df(x1.dtypes), x2).dtypes
        elif x1.dtypes is not None and isinstance(x2, TENSOR_TYPE):
            dtypes = pd.Series(
                [infer_dtype(dt, x2.dtype, cls._operator) for dt in x1.dtypes],
                index=x1.dtypes.index,
            )
        else:
            dtypes = x1.dtypes
        return {
            "shape": x1.shape,
            "dtypes": dtypes,
            "columns_value": x1.columns_value,
            "index_value": x1.index_value,
        }

    if isinstance(x1, (SERIES_TYPE, SERIES_CHUNK_TYPE)) and (
        x2 is None or pd.api.types.is_scalar(x2) or isinstance(x2, TENSOR_TYPE)
    ):
        x2_dtype = x2.dtype if hasattr(x2, "dtype") else type(x2)
        dtype = infer_dtype(x1.dtype, np.dtype(x2_dtype), cls._operator)
        return {"shape": x1.shape, "dtype": dtype, "index_value": x1.index_value}

    if isinstance(x1, (DATAFRAME_TYPE, DATAFRAME_CHUNK_TYPE)) and isinstance(
        x2, (DATAFRAME_TYPE, DATAFRAME_CHUNK_TYPE)
    ):
        index_shape, column_shape, dtypes, columns, index = (
            np.nan,
            np.nan,
            None,
            None,
            None,
        )

        if (
            x1.columns_value is not None
            and x2.columns_value is not None
            and x1.columns_value.key == x2.columns_value.key
        ):
            dtypes = pd.Series(
                [
                    infer_dtype(dt1, dt2, cls._operator)
                    for dt1, dt2 in zip(x1.dtypes, x2.dtypes)
                ],
                index=x1.dtypes.index,
            )
            columns = copy.copy(x1.columns_value)
            columns.value.should_be_monotonic = False
            column_shape = len(dtypes)
        elif x1.dtypes is not None and x2.dtypes is not None:
            dtypes = infer_dtypes(x1.dtypes, x2.dtypes, cls._operator)
            columns = parse_index(dtypes.index, store_data=True)
            columns.value.should_be_monotonic = True
            column_shape = len(dtypes)
        if x1.index_value is not None and x2.index_value is not None:
            if x1.index_value.key == x2.index_value.key:
                index = copy.copy(x1.index_value)
                index.value.should_be_monotonic = False
                index_shape = x1.shape[0]
            else:
                index = infer_index_value(x1.index_value, x2.index_value)
                index.value.should_be_monotonic = True
                if index.key == x1.index_value.key == x2.index_value.key and (
                    not np.isnan(x1.shape[0]) or not np.isnan(x2.shape[0])
                ):
                    index_shape = (
                        x1.shape[0] if not np.isnan(x1.shape[0]) else x2.shape[0]
                    )

        return {
            "shape": (index_shape, column_shape),
            "dtypes": dtypes,
            "columns_value": columns,
            "index_value": index,
        }

    if isinstance(x1, (DATAFRAME_TYPE, DATAFRAME_CHUNK_TYPE)) and isinstance(
        x2, (SERIES_TYPE, SERIES_CHUNK_TYPE)
    ):
        if axis == "columns" or axis == 1:
            index_shape = x1.shape[0]
            index = x1.index_value
            column_shape, dtypes, columns = np.nan, None, None
            if x1.columns_value is not None and x1.index_value is not None:
                if x1.columns_value.key == x2.index_value.key:
                    dtypes = pd.Series(
                        [infer_dtype(dt, x2.dtype, cls._operator) for dt in x1.dtypes],
                        index=x1.dtypes.index,
                    )
                    columns = copy.copy(x1.columns_value)
                    columns.value.should_be_monotonic = False
                    column_shape = len(dtypes)
                else:  # pragma: no cover
                    dtypes = x1.dtypes  # FIXME
                    columns = infer_index_value(x1.columns_value, x2.index_value)
                    columns.value.should_be_monotonic = True
                    column_shape = np.nan
        else:
            assert axis == "index" or axis == 0
            column_shape = x1.shape[1]
            columns = x1.columns_value
            dtypes = x1.dtypes
            index_shape, index = np.nan, None
            if x1.index_value is not None and x1.index_value is not None:
                if x1.index_value.key == x2.index_value.key:
                    dtypes = pd.Series(
                        [infer_dtype(dt, x2.dtype, cls._operator) for dt in x1.dtypes],
                        index=x1.dtypes.index,
                    )
                    index = copy.copy(x1.index_value)
                    index.value.should_be_monotonic = False
                    index_shape = x1.shape[0]
                else:
                    if x1.dtypes is not None:
                        dtypes = pd.Series(
                            [
                                infer_dtype(dt, x2.dtype, cls._operator)
                                for dt in x1.dtypes
                            ],
                            index=x1.dtypes.index,
                        )
                    index = infer_index_value(x1.index_value, x2.index_value)
                    index.value.should_be_monotonic = True
                    index_shape = np.nan
        return {
            "shape": (index_shape, column_shape),
            "dtypes": dtypes,
            "columns_value": columns,
            "index_value": index,
        }

    if isinstance(x1, (SERIES_TYPE, SERIES_CHUNK_TYPE)) and isinstance(
        x2, (SERIES_TYPE, SERIES_CHUNK_TYPE)
    ):
        index_shape, dtype, index = np.nan, None, None

        dtype = infer_dtype(x1.dtype, x2.dtype, cls._operator)
        if x1.index_value is not None and x2.index_value is not None:
            if x1.index_value.key == x2.index_value.key:
                index = copy.copy(x1.index_value)
                index.value.should_be_monotonic = False
                index_shape = x1.shape[0]
            else:
                index = infer_index_value(x1.index_value, x2.index_value)
                index.value.should_be_monotonic = True
                if index.key == x1.index_value.key == x2.index_value.key and (
                    not np.isnan(x1.shape[0]) or not np.isnan(x2.shape[0])
                ):
                    index_shape = (
                        x1.shape[0] if not np.isnan(x1.shape[0]) else x2.shape[0]
                    )

        return {"shape": (index_shape,), "dtype": dtype, "index_value": index}

    raise NotImplementedError("Unknown combination of parameters")


# 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 _calc_properties(cls, x1, x2=None, axis="columns"):
    if isinstance(x1, (DATAFRAME_TYPE, DATAFRAME_CHUNK_TYPE)) and (
        x2 is None or pd.api.types.is_scalar(x2) or isinstance(x2, TENSOR_TYPE)
    ):
        if x2 is None:
            dtypes = x1.dtypes
        elif pd.api.types.is_scalar(x2):
            dtypes = cls._operator(build_empty_df(x1.dtypes), x2).dtypes
        elif x1.dtypes is not None and isinstance(x2, TENSOR_TYPE):
            dtypes = pd.Series(
                [infer_dtype(dt, x2.dtype, cls._operator) for dt in x1.dtypes],
                index=x1.dtypes.index,
            )
        else:
            dtypes = x1.dtypes
        return {
            "shape": x1.shape,
            "dtypes": dtypes,
            "columns_value": x1.columns_value,
            "index_value": x1.index_value,
        }

    if isinstance(x1, (SERIES_TYPE, SERIES_CHUNK_TYPE)) and (
        x2 is None or pd.api.types.is_scalar(x2) or isinstance(x2, TENSOR_TYPE)
    ):
        x2_dtype = x2.dtype if hasattr(x2, "dtype") else type(x2)
        dtype = infer_dtype(x1.dtype, np.dtype(x2_dtype), cls._operator)
        ret = {"shape": x1.shape, "dtype": dtype, "index_value": x1.index_value}
        if pd.api.types.is_scalar(x2) or (hasattr(x2, "ndim") and x2.ndim == 0):
            ret["name"] = x1.name
        return ret

    if isinstance(x1, (DATAFRAME_TYPE, DATAFRAME_CHUNK_TYPE)) and isinstance(
        x2, (DATAFRAME_TYPE, DATAFRAME_CHUNK_TYPE)
    ):
        index_shape, column_shape, dtypes, columns, index = (
            np.nan,
            np.nan,
            None,
            None,
            None,
        )

        if (
            x1.columns_value is not None
            and x2.columns_value is not None
            and x1.columns_value.key == x2.columns_value.key
        ):
            dtypes = pd.Series(
                [
                    infer_dtype(dt1, dt2, cls._operator)
                    for dt1, dt2 in zip(x1.dtypes, x2.dtypes)
                ],
                index=x1.dtypes.index,
            )
            columns = copy.copy(x1.columns_value)
            columns.value.should_be_monotonic = False
            column_shape = len(dtypes)
        elif x1.dtypes is not None and x2.dtypes is not None:
            dtypes = infer_dtypes(x1.dtypes, x2.dtypes, cls._operator)
            columns = parse_index(dtypes.index, store_data=True)
            columns.value.should_be_monotonic = True
            column_shape = len(dtypes)
        if x1.index_value is not None and x2.index_value is not None:
            if x1.index_value.key == x2.index_value.key:
                index = copy.copy(x1.index_value)
                index.value.should_be_monotonic = False
                index_shape = x1.shape[0]
            else:
                index = infer_index_value(x1.index_value, x2.index_value)
                index.value.should_be_monotonic = True
                if index.key == x1.index_value.key == x2.index_value.key and (
                    not np.isnan(x1.shape[0]) or not np.isnan(x2.shape[0])
                ):
                    index_shape = (
                        x1.shape[0] if not np.isnan(x1.shape[0]) else x2.shape[0]
                    )

        return {
            "shape": (index_shape, column_shape),
            "dtypes": dtypes,
            "columns_value": columns,
            "index_value": index,
        }

    if isinstance(x1, (DATAFRAME_TYPE, DATAFRAME_CHUNK_TYPE)) and isinstance(
        x2, (SERIES_TYPE, SERIES_CHUNK_TYPE)
    ):
        if axis == "columns" or axis == 1:
            index_shape = x1.shape[0]
            index = x1.index_value
            column_shape, dtypes, columns = np.nan, None, None
            if x1.columns_value is not None and x1.index_value is not None:
                if x1.columns_value.key == x2.index_value.key:
                    dtypes = pd.Series(
                        [infer_dtype(dt, x2.dtype, cls._operator) for dt in x1.dtypes],
                        index=x1.dtypes.index,
                    )
                    columns = copy.copy(x1.columns_value)
                    columns.value.should_be_monotonic = False
                    column_shape = len(dtypes)
                else:  # pragma: no cover
                    dtypes = x1.dtypes  # FIXME
                    columns = infer_index_value(x1.columns_value, x2.index_value)
                    columns.value.should_be_monotonic = True
                    column_shape = np.nan
        else:
            assert axis == "index" or axis == 0
            column_shape = x1.shape[1]
            columns = x1.columns_value
            dtypes = x1.dtypes
            index_shape, index = np.nan, None
            if x1.index_value is not None and x1.index_value is not None:
                if x1.index_value.key == x2.index_value.key:
                    dtypes = pd.Series(
                        [infer_dtype(dt, x2.dtype, cls._operator) for dt in x1.dtypes],
                        index=x1.dtypes.index,
                    )
                    index = copy.copy(x1.index_value)
                    index.value.should_be_monotonic = False
                    index_shape = x1.shape[0]
                else:
                    if x1.dtypes is not None:
                        dtypes = pd.Series(
                            [
                                infer_dtype(dt, x2.dtype, cls._operator)
                                for dt in x1.dtypes
                            ],
                            index=x1.dtypes.index,
                        )
                    index = infer_index_value(x1.index_value, x2.index_value)
                    index.value.should_be_monotonic = True
                    index_shape = np.nan
        return {
            "shape": (index_shape, column_shape),
            "dtypes": dtypes,
            "columns_value": columns,
            "index_value": index,
        }

    if isinstance(x1, (SERIES_TYPE, SERIES_CHUNK_TYPE)) and isinstance(
        x2, (SERIES_TYPE, SERIES_CHUNK_TYPE)
    ):
        index_shape, dtype, index = np.nan, None, None

        dtype = infer_dtype(x1.dtype, x2.dtype, cls._operator)
        if x1.index_value is not None and x2.index_value is not None:
            if x1.index_value.key == x2.index_value.key:
                index = copy.copy(x1.index_value)
                index.value.should_be_monotonic = False
                index_shape = x1.shape[0]
            else:
                index = infer_index_value(x1.index_value, x2.index_value)
                index.value.should_be_monotonic = True
                if index.key == x1.index_value.key == x2.index_value.key and (
                    not np.isnan(x1.shape[0]) or not np.isnan(x2.shape[0])
                ):
                    index_shape = (
                        x1.shape[0] if not np.isnan(x1.shape[0]) else x2.shape[0]
                    )

        ret = {"shape": (index_shape,), "dtype": dtype, "index_value": index}
        if x1.name == x2.name:
            ret["name"] = x1.name
        return ret

    raise NotImplementedError("Unknown combination of parameters")