# Buggy code
def _install():
    from ..core import DATAFRAME_TYPE, SERIES_TYPE, INDEX_TYPE
    from .standardize_range_index import ChunkStandardizeRangeIndex
    from .string_ import _string_method_to_handlers
    from .datetimes import _datetime_method_to_handlers
    from .accessor import StringAccessor, DatetimeAccessor, CachedAccessor

    for t in DATAFRAME_TYPE:
        setattr(t, "to_gpu", to_gpu)
        setattr(t, "to_cpu", to_cpu)
        setattr(t, "rechunk", rechunk)
        setattr(t, "describe", describe)
        setattr(t, "apply", df_apply)
        setattr(t, "transform", df_transform)
        setattr(t, "fillna", fillna)
        setattr(t, "ffill", ffill)
        setattr(t, "bfill", bfill)
        setattr(t, "isin", df_isin)
        setattr(t, "isna", isna)
        setattr(t, "isnull", isnull)
        setattr(t, "notna", notna)
        setattr(t, "notnull", notnull)
        setattr(t, "dropna", df_dropna)
        setattr(t, "shift", shift)
        setattr(t, "tshift", tshift)
        setattr(t, "diff", df_diff)
        setattr(t, "astype", astype)
        setattr(t, "drop", df_drop)
        setattr(t, "pop", df_pop)
        setattr(
            t, "__delitem__", lambda df, items: df_drop(df, items, axis=1, inplace=True)
        )
        setattr(t, "drop_duplicates", df_drop_duplicates)
        setattr(t, "melt", melt)
        setattr(t, "memory_usage", df_memory_usage)
        setattr(t, "select_dtypes", select_dtypes)
        setattr(t, "map_chunk", map_chunk)
        setattr(t, "rebalance", rebalance)
        setattr(t, "stack", stack)

    for t in SERIES_TYPE:
        setattr(t, "to_gpu", to_gpu)
        setattr(t, "to_cpu", to_cpu)
        setattr(t, "rechunk", rechunk)
        setattr(t, "map", map_)
        setattr(t, "describe", describe)
        setattr(t, "apply", series_apply)
        setattr(t, "transform", series_transform)
        setattr(t, "fillna", fillna)
        setattr(t, "ffill", ffill)
        setattr(t, "bfill", bfill)
        setattr(t, "isin", series_isin)
        setattr(t, "isna", isna)
        setattr(t, "isnull", isnull)
        setattr(t, "notna", notna)
        setattr(t, "notnull", notnull)
        setattr(t, "dropna", series_dropna)
        setattr(t, "shift", shift)
        setattr(t, "tshift", tshift)
        setattr(t, "diff", series_diff)
        setattr(t, "value_counts", value_counts)
        setattr(t, "astype", astype)
        setattr(t, "drop", series_drop)
        setattr(t, "drop_duplicates", series_drop_duplicates)
        setattr(t, "memory_usage", series_memory_usage)
        setattr(t, "map_chunk", map_chunk)
        setattr(t, "rebalance", rebalance)

    for t in INDEX_TYPE:
        setattr(t, "rechunk", rechunk)
        setattr(t, "drop", index_drop)
        setattr(t, "drop_duplicates", index_drop_duplicates)
        setattr(t, "memory_usage", index_memory_usage)

    for method in _string_method_to_handlers:
        if not hasattr(StringAccessor, method):
            StringAccessor._register(method)

    for method in _datetime_method_to_handlers:
        if not hasattr(DatetimeAccessor, method):
            DatetimeAccessor._register(method)

    for series in SERIES_TYPE:
        series.str = CachedAccessor("str", StringAccessor)
        series.dt = CachedAccessor("dt", DatetimeAccessor)


# Traceback (AttributeError)
In [4]: df.sort_values(by='col1').execute()
Out[4]: ---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
~/miniconda3/lib/python3.7/site-packages/IPython/core/formatters.py in __call__(self, obj)
700                 type_pprinters=self.type_printers,
701                 deferred_pprinters=self.deferred_printers)
--> 702             printer.pretty(obj)
703             printer.flush()
704             return stream.getvalue()

~/miniconda3/lib/python3.7/site-packages/IPython/lib/pretty.py in pretty(self, obj)
392                         if cls is not object \
393                                 and callable(cls.__dict__.get('__repr__')):
--> 394                             return _repr_pprint(obj, self, cycle)
395
396             return _default_pprint(obj, self, cycle)

~/miniconda3/lib/python3.7/site-packages/IPython/lib/pretty.py in _repr_pprint(obj, p, cycle)
698     """A pprint that just redirects to the normal repr function."""
699     # Find newlines and replace them with p.break_()
--> 700     output = repr(obj)
701     lines = output.splitlines()
702     with p.group():

~/Documents/mars_dev/mars/mars/core.py in __repr__(self)
129
130     def __repr__(self):
--> 131         return self._data.__repr__()
132
133     def _check_data(self, data):

~/Documents/mars_dev/mars/mars/dataframe/core.py in __repr__(self)
1084
1085     def __repr__(self):
-> 1086         return self._to_str(representation=True)
1087
1088     def _repr_html_(self):

~/Documents/mars_dev/mars/mars/dataframe/core.py in _to_str(self, representation)
1057         else:
1058             corner_data = fetch_corner_data(
-> 1059                 self, session=self._executed_sessions[-1])
1060
1061             buf = StringIO()

~/Documents/mars_dev/mars/mars/dataframe/utils.py in fetch_corner_data(df_or_series, session)
895         head_data, tail_data = \
896             ExecutableTuple([head, tail]).fetch(session=session)
--> 897         return pd.concat([head_data, tail_data], axis='index')
898
899

~/miniconda3/lib/python3.7/site-packages/pandas/core/reshape/concat.py in concat(objs, axis, join, ignore_index, keys, levels, names, verify_integrity, sort, copy)
279         verify_integrity=verify_integrity,
280         copy=copy,
--> 281         sort=sort,
282     )
283

~/miniconda3/lib/python3.7/site-packages/pandas/core/reshape/concat.py in __init__(self, objs, axis, join, keys, levels, names, ignore_index, verify_integrity, copy, sort)
358
359             # consolidate
--> 360             obj._consolidate(inplace=True)
361             ndims.add(obj.ndim)
362

~/miniconda3/lib/python3.7/site-packages/pandas/core/generic.py in _consolidate(self, inplace)
5363         inplace = validate_bool_kwarg(inplace, "inplace")
5364         if inplace:
-> 5365             self._consolidate_inplace()
5366         else:
5367             f = lambda: self._data.consolidate()

~/miniconda3/lib/python3.7/site-packages/pandas/core/generic.py in _consolidate_inplace(self)
5345             self._data = self._data.consolidate()
5346
-> 5347         self._protect_consolidate(f)
5348
5349     def _consolidate(self, inplace: bool_t = False):

~/miniconda3/lib/python3.7/site-packages/pandas/core/generic.py in _protect_consolidate(self, f)
5333         cache
5334         """
-> 5335         blocks_before = len(self._data.blocks)
5336         result = f()
5337         if len(self._data.blocks) != blocks_before:

~/miniconda3/lib/python3.7/site-packages/pandas/core/generic.py in __getattr__(self, name)
5268             or name in self._accessors
5269         ):
-> 5270             return object.__getattribute__(self, name)
5271         else:
5272             if self._info_axis._can_hold_identifiers_and_holds_name(name):

AttributeError: 'DataFrame' object has no attribute '_data'

# Fixed code
def _install():
    from ..core import DATAFRAME_TYPE, SERIES_TYPE, INDEX_TYPE
    from .standardize_range_index import ChunkStandardizeRangeIndex
    from .string_ import _string_method_to_handlers
    from .datetimes import _datetime_method_to_handlers
    from .accessor import StringAccessor, DatetimeAccessor, CachedAccessor

    for t in DATAFRAME_TYPE:
        setattr(t, "to_gpu", to_gpu)
        setattr(t, "to_cpu", to_cpu)
        setattr(t, "rechunk", rechunk)
        setattr(t, "describe", describe)
        setattr(t, "apply", df_apply)
        setattr(t, "transform", df_transform)
        setattr(t, "fillna", fillna)
        setattr(t, "ffill", ffill)
        setattr(t, "bfill", bfill)
        setattr(t, "isin", df_isin)
        setattr(t, "isna", isna)
        setattr(t, "isnull", isnull)
        setattr(t, "notna", notna)
        setattr(t, "notnull", notnull)
        setattr(t, "dropna", df_dropna)
        setattr(t, "shift", shift)
        setattr(t, "tshift", tshift)
        setattr(t, "diff", df_diff)
        setattr(t, "astype", astype)
        setattr(t, "drop", df_drop)
        setattr(t, "pop", df_pop)
        setattr(
            t, "__delitem__", lambda df, items: df_drop(df, items, axis=1, inplace=True)
        )
        setattr(t, "drop_duplicates", df_drop_duplicates)
        setattr(t, "melt", melt)
        setattr(t, "memory_usage", df_memory_usage)
        setattr(t, "select_dtypes", select_dtypes)
        setattr(t, "map_chunk", map_chunk)
        setattr(t, "rebalance", rebalance)
        setattr(t, "stack", stack)
        setattr(t, "explode", df_explode)

    for t in SERIES_TYPE:
        setattr(t, "to_gpu", to_gpu)
        setattr(t, "to_cpu", to_cpu)
        setattr(t, "rechunk", rechunk)
        setattr(t, "map", map_)
        setattr(t, "describe", describe)
        setattr(t, "apply", series_apply)
        setattr(t, "transform", series_transform)
        setattr(t, "fillna", fillna)
        setattr(t, "ffill", ffill)
        setattr(t, "bfill", bfill)
        setattr(t, "isin", series_isin)
        setattr(t, "isna", isna)
        setattr(t, "isnull", isnull)
        setattr(t, "notna", notna)
        setattr(t, "notnull", notnull)
        setattr(t, "dropna", series_dropna)
        setattr(t, "shift", shift)
        setattr(t, "tshift", tshift)
        setattr(t, "diff", series_diff)
        setattr(t, "value_counts", value_counts)
        setattr(t, "astype", astype)
        setattr(t, "drop", series_drop)
        setattr(t, "drop_duplicates", series_drop_duplicates)
        setattr(t, "memory_usage", series_memory_usage)
        setattr(t, "map_chunk", map_chunk)
        setattr(t, "rebalance", rebalance)
        setattr(t, "explode", series_explode)

    for t in INDEX_TYPE:
        setattr(t, "rechunk", rechunk)
        setattr(t, "drop", index_drop)
        setattr(t, "drop_duplicates", index_drop_duplicates)
        setattr(t, "memory_usage", index_memory_usage)

    for method in _string_method_to_handlers:
        if not hasattr(StringAccessor, method):
            StringAccessor._register(method)

    for method in _datetime_method_to_handlers:
        if not hasattr(DatetimeAccessor, method):
            DatetimeAccessor._register(method)

    for series in SERIES_TYPE:
        series.str = CachedAccessor("str", StringAccessor)
        series.dt = CachedAccessor("dt", DatetimeAccessor)