# Buggy code
def diff(self, periods=1):
    """
    First discrete difference of element.

    Calculates the difference of a DataFrame element compared with another element in the
    DataFrame (default is the element in the same column of the previous row).

    .. note:: the current implementation of diff uses Spark's Window without
        specifying partition specification. This leads to move all data into
        single partition in single machine and could cause serious
        performance degradation. Avoid this method against very large dataset.

    Parameters
    ----------
    periods : int, default 1
        Periods to shift for calculating difference, accepts negative values.

    Returns
    -------
    diffed : DataFrame

    Examples
    --------
    >>> df = ks.DataFrame({'a': [1, 2, 3, 4, 5, 6],
    ...                    'b': [1, 1, 2, 3, 5, 8],
    ...                    'c': [1, 4, 9, 16, 25, 36]}, columns=['a', 'b', 'c'])
    >>> df
       a  b   c
    0  1  1   1
    1  2  1   4
    2  3  2   9
    3  4  3  16
    4  5  5  25
    5  6  8  36

    >>> df.diff()
         a    b     c
    0  NaN  NaN   NaN
    1  1.0  0.0   3.0
    2  1.0  1.0   5.0
    3  1.0  1.0   7.0
    4  1.0  2.0   9.0
    5  1.0  3.0  11.0

    Difference with previous column

    >>> df.diff(periods=3)
         a    b     c
    0  NaN  NaN   NaN
    1  NaN  NaN   NaN
    2  NaN  NaN   NaN
    3  3.0  2.0  15.0
    4  3.0  4.0  21.0
    5  3.0  6.0  27.0

    Difference with following row

    >>> df.diff(periods=-1)
         a    b     c
    0 -1.0  0.0  -3.0
    1 -1.0 -1.0  -5.0
    2 -1.0 -1.0  -7.0
    3 -1.0 -2.0  -9.0
    4 -1.0 -3.0 -11.0
    5  NaN  NaN   NaN
    """
    applied = []
    for column in self._internal.data_columns:
        applied.append(self[column].diff(periods))
    sdf = self._sdf.select(self._internal.index_columns + [c._scol for c in applied])
    internal = self._internal.copy(sdf=sdf, data_columns=[c.name for c in applied])
    return DataFrame(internal)


# 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 diff(self, periods=1):
    """
    First discrete difference of element.

    Calculates the difference of a DataFrame element compared with another element in the
    DataFrame (default is the element in the same column of the previous row).

    .. note:: the current implementation of diff uses Spark's Window without
        specifying partition specification. This leads to move all data into
        single partition in single machine and could cause serious
        performance degradation. Avoid this method against very large dataset.

    Parameters
    ----------
    periods : int, default 1
        Periods to shift for calculating difference, accepts negative values.

    Returns
    -------
    diffed : DataFrame

    Examples
    --------
    >>> df = ks.DataFrame({'a': [1, 2, 3, 4, 5, 6],
    ...                    'b': [1, 1, 2, 3, 5, 8],
    ...                    'c': [1, 4, 9, 16, 25, 36]}, columns=['a', 'b', 'c'])
    >>> df
       a  b   c
    0  1  1   1
    1  2  1   4
    2  3  2   9
    3  4  3  16
    4  5  5  25
    5  6  8  36

    >>> df.diff()
         a    b     c
    0  NaN  NaN   NaN
    1  1.0  0.0   3.0
    2  1.0  1.0   5.0
    3  1.0  1.0   7.0
    4  1.0  2.0   9.0
    5  1.0  3.0  11.0

    Difference with previous column

    >>> df.diff(periods=3)
         a    b     c
    0  NaN  NaN   NaN
    1  NaN  NaN   NaN
    2  NaN  NaN   NaN
    3  3.0  2.0  15.0
    4  3.0  4.0  21.0
    5  3.0  6.0  27.0

    Difference with following row

    >>> df.diff(periods=-1)
         a    b     c
    0 -1.0  0.0  -3.0
    1 -1.0 -1.0  -5.0
    2 -1.0 -1.0  -7.0
    3 -1.0 -2.0  -9.0
    4 -1.0 -3.0 -11.0
    5  NaN  NaN   NaN
    """
    applied = []
    for column in self._internal.data_columns:
        applied.append(self[column].diff(periods))
    sdf = self._sdf.select(self._internal.index_scols + [c._scol for c in applied])
    internal = self._internal.copy(sdf=sdf, data_columns=[c.name for c in applied])
    return DataFrame(internal)