# Buggy code
def value_counts(
    self, normalize=False, sort=True, ascending=False, bins=None, dropna=True
):
    """
    Return a Series containing counts of unique values.
    The resulting object will be in descending order so that the
    first element is the most frequently-occurring element.
    Excludes NA values by default.

    Parameters
    ----------
    normalize : boolean, default False
        If True then the object returned will contain the relative
        frequencies of the unique values.
    sort : boolean, default True
        Sort by values.
    ascending : boolean, default False
        Sort in ascending order.
    bins : Not Yet Supported
    dropna : boolean, default True
        Don't include counts of NaN.

    Returns
    -------
    counts : Series

    See Also
    --------
    Series.count: Number of non-NA elements in a Series.

    Examples
    --------
    >>> df = ks.DataFrame({'x':[0, 0, 1, 1, 1, np.nan]})
    >>> df.x.value_counts()  # doctest: +NORMALIZE_WHITESPACE
    1.0    3
    0.0    2
    Name: x, dtype: int64

    With `normalize` set to `True`, returns the relative frequency by
    dividing all values by the sum of values.

    >>> df.x.value_counts(normalize=True)  # doctest: +NORMALIZE_WHITESPACE
    1.0    0.6
    0.0    0.4
    Name: x, dtype: float64

    **dropna**
    With `dropna` set to `False` we can also see NaN index values.

    >>> df.x.value_counts(dropna=False)  # doctest: +NORMALIZE_WHITESPACE
    1.0    3
    0.0    2
    NaN    1
    Name: x, dtype: int64
    """
    if bins is not None:
        raise NotImplementedError("value_counts currently does not support bins")

    if dropna:
        sdf_dropna = self._kdf._sdf.filter(self.notna()._scol)
    else:
        sdf_dropna = self._kdf._sdf
    sdf = sdf_dropna.groupby(self._scol).count()
    if sort:
        if ascending:
            sdf = sdf.orderBy(F.col("count"))
        else:
            sdf = sdf.orderBy(F.col("count").desc())

    if normalize:
        sum = sdf_dropna.count()
        sdf = sdf.withColumn("count", F.col("count") / F.lit(sum))

    index_name = "index" if self.name != "index" else "level_0"
    sdf = sdf.select(sdf[self.name].alias(index_name), sdf["count"].alias(self.name))
    internal = _InternalFrame(
        sdf=sdf, data_columns=[self.name], index_map=[(index_name, None)]
    )
    return _col(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 value_counts(
    self, normalize=False, sort=True, ascending=False, bins=None, dropna=True
):
    """
    Return a Series containing counts of unique values.
    The resulting object will be in descending order so that the
    first element is the most frequently-occurring element.
    Excludes NA values by default.

    Parameters
    ----------
    normalize : boolean, default False
        If True then the object returned will contain the relative
        frequencies of the unique values.
    sort : boolean, default True
        Sort by values.
    ascending : boolean, default False
        Sort in ascending order.
    bins : Not Yet Supported
    dropna : boolean, default True
        Don't include counts of NaN.

    Returns
    -------
    counts : Series

    See Also
    --------
    Series.count: Number of non-NA elements in a Series.

    Examples
    --------
    >>> df = ks.DataFrame({'x':[0, 0, 1, 1, 1, np.nan]})
    >>> df.x.value_counts()  # doctest: +NORMALIZE_WHITESPACE
    1.0    3
    0.0    2
    Name: x, dtype: int64

    With `normalize` set to `True`, returns the relative frequency by
    dividing all values by the sum of values.

    >>> df.x.value_counts(normalize=True)  # doctest: +NORMALIZE_WHITESPACE
    1.0    0.6
    0.0    0.4
    Name: x, dtype: float64

    **dropna**
    With `dropna` set to `False` we can also see NaN index values.

    >>> df.x.value_counts(dropna=False)  # doctest: +NORMALIZE_WHITESPACE
    1.0    3
    0.0    2
    NaN    1
    Name: x, dtype: int64
    """
    if bins is not None:
        raise NotImplementedError("value_counts currently does not support bins")

    if dropna:
        sdf_dropna = self._kdf._sdf.filter(self.notna()._scol)
    else:
        sdf_dropna = self._kdf._sdf
    sdf = sdf_dropna.groupby(self._scol).count()
    if sort:
        if ascending:
            sdf = sdf.orderBy(F.col("count"))
        else:
            sdf = sdf.orderBy(F.col("count").desc())

    if normalize:
        sum = sdf_dropna.count()
        sdf = sdf.withColumn("count", F.col("count") / F.lit(sum))

    index_name = "index" if self.name != "index" else "level_0"
    sdf = sdf.select(
        scol_for(sdf, self.name).alias(index_name),
        scol_for(sdf, "count").alias(self.name),
    )
    internal = _InternalFrame(
        sdf=sdf, data_columns=[self.name], index_map=[(index_name, None)]
    )
    return _col(DataFrame(internal))