# Buggy code
def is_monotonic_decreasing(self):
    """
    Return boolean if values in the object are monotonically decreasing.

    .. note:: the current implementation of is_monotonic_decreasing 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.

    Returns
    -------
    is_monotonic : boolean

    Examples
    --------
    >>> ser = ks.Series(['4/1/2018', '3/1/2018', '1/1/2018'])
    >>> ser.is_monotonic_decreasing
    True

    >>> df = ks.DataFrame({'dates': [None, '3/1/2018', '2/1/2018', '1/1/2018']})
    >>> df.dates.is_monotonic_decreasing
    False

    >>> df.index.is_monotonic_decreasing
    False

    >>> ser = ks.Series([1])
    >>> ser.is_monotonic_decreasing
    True

    >>> ser = ks.Series([])
    >>> ser.is_monotonic_decreasing
    True
    """
    if len(self._kdf._internal.index_columns) == 0:
        raise ValueError("Index must be set.")

    col = self._scol
    index_columns = self._kdf._internal.index_columns
    window = Window.orderBy(index_columns).rowsBetween(-1, -1)
    sdf = self._kdf._sdf.withColumn(
        "__monotonic_col", (col <= F.lag(col, 1).over(window)) & col.isNotNull()
    )
    kdf = ks.DataFrame(
        self._kdf._internal.copy(
            sdf=sdf, data_columns=self._kdf._internal.data_columns + ["__monotonic_col"]
        )
    )
    return kdf["__monotonic_col"].all()


# 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 is_monotonic_decreasing(self):
    """
    Return boolean if values in the object are monotonically decreasing.

    .. note:: the current implementation of is_monotonic_decreasing 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.

    Returns
    -------
    is_monotonic : boolean

    Examples
    --------
    >>> ser = ks.Series(['4/1/2018', '3/1/2018', '1/1/2018'])
    >>> ser.is_monotonic_decreasing
    True

    >>> df = ks.DataFrame({'dates': [None, '3/1/2018', '2/1/2018', '1/1/2018']})
    >>> df.dates.is_monotonic_decreasing
    False

    >>> df.index.is_monotonic_decreasing
    False

    >>> ser = ks.Series([1])
    >>> ser.is_monotonic_decreasing
    True

    >>> ser = ks.Series([])
    >>> ser.is_monotonic_decreasing
    True
    """
    if len(self._kdf._internal.index_columns) == 0:
        raise ValueError("Index must be set.")

    col = self._scol
    window = Window.orderBy(self._kdf._internal.index_scols).rowsBetween(-1, -1)
    sdf = self._kdf._sdf.withColumn(
        "__monotonic_col", (col <= F.lag(col, 1).over(window)) & col.isNotNull()
    )
    kdf = ks.DataFrame(
        self._kdf._internal.copy(
            sdf=sdf, data_columns=self._kdf._internal.data_columns + ["__monotonic_col"]
        )
    )
    return kdf["__monotonic_col"].all()