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

    Calculates the difference of a Series 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.b.diff()
    0    NaN
    1    0.0
    2    1.0
    3    1.0
    4    2.0
    5    3.0
    Name: b, dtype: float64

    Difference with previous value

    >>> df.c.diff(periods=3)
    0     NaN
    1     NaN
    2     NaN
    3    15.0
    4    21.0
    5    27.0
    Name: c, dtype: float64

    Difference with following value

    >>> df.c.diff(periods=-1)
    0    -3.0
    1    -5.0
    2    -7.0
    3    -9.0
    4   -11.0
    5     NaN
    Name: c, dtype: float64
    """

    if len(self._internal.index_columns) == 0:
        raise ValueError("Index must be set.")

    if not isinstance(periods, int):
        raise ValueError("periods should be an int; however, got [%s]" % type(periods))

    col = self._scol
    window = Window.orderBy(self._internal.index_columns[0]).rowsBetween(
        -periods, -periods
    )
    return self._with_new_scol(col - F.lag(col, periods).over(window)).alias(self.name)


# 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 Series 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.b.diff()
    0    NaN
    1    0.0
    2    1.0
    3    1.0
    4    2.0
    5    3.0
    Name: b, dtype: float64

    Difference with previous value

    >>> df.c.diff(periods=3)
    0     NaN
    1     NaN
    2     NaN
    3    15.0
    4    21.0
    5    27.0
    Name: c, dtype: float64

    Difference with following value

    >>> df.c.diff(periods=-1)
    0    -3.0
    1    -5.0
    2    -7.0
    3    -9.0
    4   -11.0
    5     NaN
    Name: c, dtype: float64
    """

    if len(self._internal.index_columns) == 0:
        raise ValueError("Index must be set.")

    if not isinstance(periods, int):
        raise ValueError("periods should be an int; however, got [%s]" % type(periods))

    col = self._scol
    window = Window.orderBy(self._internal.index_scols).rowsBetween(-periods, -periods)
    return self._with_new_scol(col - F.lag(col, periods).over(window)).alias(self.name)