# Buggy code
def __getitem__(self, key):
    from databricks.koalas.frame import DataFrame
    from databricks.koalas.indexes import Index
    from databricks.koalas.series import Series

    def raiseNotImplemented(description):
        raise SparkPandasNotImplementedError(
            description=description,
            pandas_function=".iloc[..., ...]",
            spark_target_function="select, where",
        )

    rows_sel, cols_sel = _unfold(key, self._ks)

    sdf = self._kdf._sdf
    if isinstance(rows_sel, Index):
        sdf_for_check_schema = sdf.select(rows_sel._scol)
        assert isinstance(
            sdf_for_check_schema.schema.fields[0].dataType, BooleanType
        ), (str(sdf_for_check_schema), sdf_for_check_schema.schema.fields[0].dataType)
        sdf = sdf.where(rows_sel._scol)
    elif isinstance(rows_sel, slice):
        if rows_sel == slice(None):
            # If slice is None - select everything, so nothing to do
            pass
        elif (rows_sel.start is not None) or (rows_sel.step is not None):
            raiseNotImplemented("Cannot use start or step with Spark.")
        elif not isinstance(rows_sel.stop, int):
            raise TypeError(
                "cannot do slice indexing with these indexers [{}] of {}".format(
                    rows_sel.stop, type(rows_sel.stop)
                )
            )
        elif rows_sel.stop >= 0:
            sdf = sdf.limit(rows_sel.stop)
        else:
            sdf = sdf.limit(sdf.count() + rows_sel.stop)
    else:
        raiseNotImplemented(
            ".iloc requires numeric slice or conditional boolean Index, got {}".format(
                rows_sel
            )
        )

    # make cols_sel a 1-tuple of string if a single string
    if isinstance(cols_sel, Series):
        columns = [_make_col(cols_sel)]
    elif isinstance(cols_sel, int):
        columns = [_make_col(self._kdf.columns[cols_sel])]
    elif cols_sel is None or cols_sel == slice(None):
        columns = [_make_col(col) for col in self._kdf.columns]
    elif isinstance(cols_sel, slice):
        if all(
            s is None or isinstance(s, int)
            for s in (cols_sel.start, cols_sel.stop, cols_sel.step)
        ):
            columns = [_make_col(col) for col in self._kdf.columns[cols_sel]]
        else:
            not_none = (
                cols_sel.start
                if cols_sel.start is not None
                else cols_sel.stop
                if cols_sel.stop is not None
                else cols_sel.step
            )
            raise TypeError(
                "cannot do slice indexing with these indexers {} of {}".format(
                    not_none, type(not_none)
                )
            )
    elif is_list_like(cols_sel):
        if all(isinstance(s, int) for s in cols_sel):
            columns = [_make_col(col) for col in self._kdf.columns[cols_sel]]
        else:
            raise TypeError("cannot perform reduce with flexible type")
    else:
        raise ValueError(
            "Location based indexing can only have [integer, integer slice, "
            "listlike of integers, boolean array] types, got {}".format(cols_sel)
        )

    try:
        kdf = DataFrame(sdf.select(self._kdf._internal.index_columns + columns))
    except AnalysisException:
        raise KeyError(
            "[{}] don't exist in columns".format(
                [col._jc.toString() for col in columns]
            )
        )
    kdf._internal = kdf._internal.copy(
        data_columns=kdf._internal.data_columns[-len(columns) :],
        index_map=self._kdf._internal.index_map,
    )
    if cols_sel is not None and isinstance(cols_sel, (Series, int)):
        from databricks.koalas.series import _col

        return _col(kdf)
    else:
        return kdf


# Traceback (KeyError)
df = ks.read_parquet("/mnt/ivan/sample.parquet")
df['a.b']

# KeyError: 'a.b'
# ---------------------------------------------------------------------------
# KeyError                                  Traceback (most recent call last)
# <command-3188040896828876> in <module>()
#       1 df = ks.read_parquet("/mnt/ivan/sample.parquet")
# ----> 2 df['a.b']
#
# /databricks/python/lib/python3.5/site-packages/databricks/koalas/frame.py in __getitem__(self, key)
#     448
#     449     def __getitem__(self, key):
# --> 450         return self._pd_getitem(key)
#     451
#     452     def __setitem__(self, key, value):
#
# /databricks/python/lib/python3.5/site-packages/databricks/koalas/frame.py in _pd_getitem(self, key)
#     427                 return Series(self._sdf.__getitem__(key), self, self._metadata.index_info)
#     428             except AnalysisException:
# --> 429                 raise KeyError(key)
#     430         if np.isscalar(key) or isinstance(key, (tuple, string_types)):
#     431             raise NotImplementedError(key)
#
# KeyError: 'a.b'

# Fixed code
def __getitem__(self, key):
    from databricks.koalas.frame import DataFrame
    from databricks.koalas.indexes import Index
    from databricks.koalas.series import Series

    def raiseNotImplemented(description):
        raise SparkPandasNotImplementedError(
            description=description,
            pandas_function=".iloc[..., ...]",
            spark_target_function="select, where",
        )

    rows_sel, cols_sel = _unfold(key, self._ks)

    sdf = self._kdf._sdf
    if isinstance(rows_sel, Index):
        sdf_for_check_schema = sdf.select(rows_sel._scol)
        assert isinstance(
            sdf_for_check_schema.schema.fields[0].dataType, BooleanType
        ), (str(sdf_for_check_schema), sdf_for_check_schema.schema.fields[0].dataType)
        sdf = sdf.where(rows_sel._scol)
    elif isinstance(rows_sel, slice):
        if rows_sel == slice(None):
            # If slice is None - select everything, so nothing to do
            pass
        elif (rows_sel.start is not None) or (rows_sel.step is not None):
            raiseNotImplemented("Cannot use start or step with Spark.")
        elif not isinstance(rows_sel.stop, int):
            raise TypeError(
                "cannot do slice indexing with these indexers [{}] of {}".format(
                    rows_sel.stop, type(rows_sel.stop)
                )
            )
        elif rows_sel.stop >= 0:
            sdf = sdf.limit(rows_sel.stop)
        else:
            sdf = sdf.limit(sdf.count() + rows_sel.stop)
    else:
        raiseNotImplemented(
            ".iloc requires numeric slice or conditional boolean Index, got {}".format(
                rows_sel
            )
        )

    # make cols_sel a 1-tuple of string if a single string
    if isinstance(cols_sel, Series):
        columns = [cols_sel._scol]
    elif isinstance(cols_sel, int):
        columns = [self._kdf._internal.data_scols[cols_sel]]
    elif cols_sel is None or cols_sel == slice(None):
        columns = self._kdf._internal.data_scols
    elif isinstance(cols_sel, slice):
        if all(
            s is None or isinstance(s, int)
            for s in (cols_sel.start, cols_sel.stop, cols_sel.step)
        ):
            columns = self._kdf._internal.data_scols[cols_sel]
        else:
            not_none = (
                cols_sel.start
                if cols_sel.start is not None
                else cols_sel.stop
                if cols_sel.stop is not None
                else cols_sel.step
            )
            raise TypeError(
                "cannot do slice indexing with these indexers {} of {}".format(
                    not_none, type(not_none)
                )
            )
    elif is_list_like(cols_sel):
        if all(isinstance(s, int) for s in cols_sel):
            columns = [
                self._kdf._internal.scol_for(col) for col in self._kdf.columns[cols_sel]
            ]
        else:
            raise TypeError("cannot perform reduce with flexible type")
    else:
        raise ValueError(
            "Location based indexing can only have [integer, integer slice, "
            "listlike of integers, boolean array] types, got {}".format(cols_sel)
        )

    try:
        kdf = DataFrame(sdf.select(self._kdf._internal.index_scols + columns))
    except AnalysisException:
        raise KeyError(
            "[{}] don't exist in columns".format(
                [col._jc.toString() for col in columns]
            )
        )
    kdf._internal = kdf._internal.copy(
        data_columns=kdf._internal.data_columns[-len(columns) :],
        index_map=self._kdf._internal.index_map,
    )
    if cols_sel is not None and isinstance(cols_sel, (Series, int)):
        from databricks.koalas.series import _col

        return _col(kdf)
    else:
        return kdf