Exemplo n.º 1
0
def alias_series_agg(name):
    method = method_agg_op(name, is_property=False, accessor=False)

    def decorator(dispatcher):
        dispatcher.register(SeriesGroupBy, method)
        return dispatcher

    return decorator
Exemplo n.º 2
0
                     ]))

data_str = data_frame(g=['a', 'a', 'b', 'b'], x=['abc', 'cde', 'fg', 'h'])

data_default = data_frame(g=['a', 'a', 'b', 'b'],
                          x=[10, 11, 12, 13],
                          y=[1, 2, 3, 4])

data = {'dt': data_dt, 'str': data_str, None: data_default}

# Test translator =============================================================

from pandas.testing import assert_frame_equal, assert_series_equal
from siuba.experimental.pd_groups.groupby import GroupByAgg, SeriesGroupBy

f_min = method_agg_op('min', is_property=False, accessor=None)
f_add = method_el_op2('add', is_property=False, accessor=None)
f_abs = method_el_op('abs', is_property=False, accessor=None)

# GroupByAgg is liskov substitutable, so check that our functions operate
# like similarly substitutable subtypes. This means that...
# * input type is the same or more general, and
# * output type is the same or more specific


@pytest.mark.parametrize(
    'f_op, f_dst, cls_result',
    [
        # aggregation 1-arity
        # f(SeriesGroupBy) -> GroupByAgg <= f(GroupByAgg) -> GroupByAgg
        (lambda g: f_min(g.x), lambda g: g.x.min(), GroupByAgg),