def compose(f, g):
    """
    Compose two filter f and g.

    :param f: Outer filter function.
    :type f: filter function.
    :param g: Inner filter function.
    :type g: filter function.

    :return: lambda x: f(g(x))
    :rtype: filter function.
    """

    def filter_fn(df):
        df = g(df)
        if len(df) > 0:
            return f(df)
        else:
            return df
    return filter_fn