# Buggy code
def _reduce_for_stat_function(self, sfun, numeric_only=None):
    """
    :param sfun: the stats function to be used for aggregation
    :param numeric_only: not used by this implementation, but passed down by stats functions
    """
    from inspect import signature

    num_args = len(signature(sfun).parameters)
    col_sdf = self._scol
    col_type = self.schema[self.name].dataType
    if isinstance(col_type, BooleanType) and sfun.__name__ not in ("min", "max"):
        # Stat functions cannot be used with boolean values by default
        # Thus, cast to integer (true to 1 and false to 0)
        # Exclude the min and max methods though since those work with booleans
        col_sdf = col_sdf.cast("integer")
    if num_args == 1:
        # Only pass in the column if sfun accepts only one arg
        col_sdf = sfun(col_sdf)
    else:  # must be 2
        assert num_args == 2
        # Pass in both the column and its data type if sfun accepts two args
        col_sdf = sfun(col_sdf, col_type)
    return _unpack_scalar(self._kdf._sdf.select(col_sdf))


# 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 _reduce_for_stat_function(self, sfun, numeric_only=None):
    """
    :param sfun: the stats function to be used for aggregation
    :param numeric_only: not used by this implementation, but passed down by stats functions
    """
    from inspect import signature

    num_args = len(signature(sfun).parameters)
    col_sdf = self._scol
    col_type = self.spark_type
    if isinstance(col_type, BooleanType) and sfun.__name__ not in ("min", "max"):
        # Stat functions cannot be used with boolean values by default
        # Thus, cast to integer (true to 1 and false to 0)
        # Exclude the min and max methods though since those work with booleans
        col_sdf = col_sdf.cast("integer")
    if num_args == 1:
        # Only pass in the column if sfun accepts only one arg
        col_sdf = sfun(col_sdf)
    else:  # must be 2
        assert num_args == 2
        # Pass in both the column and its data type if sfun accepts two args
        col_sdf = sfun(col_sdf, col_type)
    return _unpack_scalar(self._kdf._sdf.select(col_sdf))