How to use the pdpipe.col_generation.ApplyToRows function in pdpipe

To help you get started, weโ€™ve selected a few pdpipe examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pdpipe / pdpipe / tests / col_generation / test_applytorows.py View on Github external
def test_applytorows_with_df_generation_and_optionals():
    """Testing ApplyToRows pipeline stages."""
    df = _num_df()
    cbf_stage = ApplyToRows(
        func=_sum_and_diff,
        func_desc="calculates sum and diff of num1 and num2",
        prec=lambda df: 'num1' in df.columns and 'num2' in df.columns
    )
    res_df = cbf_stage(df)
    assert 'sum' in res_df.columns
    assert 'diff' in res_df.columns
    assert res_df['sum'][1] == 3
    assert res_df['sum'][2] == 6
    assert res_df['diff'][1] == -1
    assert res_df['diff'][2] == -2
github pdpipe / pdpipe / tests / col_generation / test_applytorows.py View on Github external
def test_applytorows_with_df_generation():
    """Testing ApplyToRows pipeline stages."""
    df = _num_df()
    cbf_stage = ApplyToRows(_sum_and_diff)
    res_df = cbf_stage(df)
    assert 'sum' in res_df.columns
    assert 'diff' in res_df.columns
    assert res_df['sum'][1] == 3
    assert res_df['sum'][2] == 6
    assert res_df['diff'][1] == -1
    assert res_df['diff'][2] == -2
github pdpipe / pdpipe / tests / col_generation / test_applytorows.py View on Github external
def test_applytorows_with_follow_column():
    """Testing ApplyToRows pipeline stages."""
    df = _some_df()
    cbf_stage = ApplyToRows(_total_rev, 'total_revenue', follow_column='years')
    res_df = cbf_stage(df)
    assert res_df.columns.get_loc('total_revenue') == 1
    assert res_df['total_revenue'][1] == 3 * 2143
    assert res_df['total_revenue'][2] == 10 * 1321
    assert res_df['total_revenue'][3] == 7 * 1255
github pdpipe / pdpipe / tests / col_generation / test_applytorows.py View on Github external
def test_applytorows():
    """Testing ApplyToRows pipeline stages."""
    df = _some_df()
    cbf_stage = ApplyToRows(_total_rev, 'total_revenue')
    res_df = cbf_stage(df)
    assert res_df.columns.get_loc('total_revenue') == 2
    assert res_df['total_revenue'][1] == 3 * 2143
    assert res_df['total_revenue'][2] == 10 * 1321
    assert res_df['total_revenue'][3] == 7 * 1255
github pdpipe / pdpipe / tests / col_generation / test_applytorows.py View on Github external
def test_applytorows_with_df_generation_follow():
    """Testing ApplyToRows pipeline stages."""
    df = _num_df()
    cbf_stage = ApplyToRows(_sum_and_diff, follow_column='num1')
    res_df = cbf_stage(df)
    print(res_df.columns)
    assert res_df.columns.get_loc('sum') == 2
    assert res_df.columns.get_loc('diff') == 1
    assert 'sum' in res_df.columns
    assert 'diff' in res_df.columns
    assert res_df['sum'][1] == 3
    assert res_df['sum'][2] == 6
    assert res_df['diff'][1] == -1
    assert res_df['diff'][2] == -2
github pdpipe / pdpipe / pdpipe / col_generation.py View on Github external
**kwargs
    ):
        if colname is None:
            colname = ApplyToRows._DEF_COLNAME
        if func_desc is None:
            func_desc = ""
        if prec is None:
            prec = _always_true
        self._func = func
        self._colname = colname
        self._follow_column = follow_column
        self._func_desc = func_desc
        self._prec_func = prec
        super_kwargs = {
            "exmsg": ApplyToRows._DEF_APPLYTOROWS_EXC_MSG.format(func_desc),
            "appmsg": ApplyToRows._DEF_APPLYTOROWS_APP_MSG.format(func_desc),
            "desc": "Generating a column with a function {}.".format(
                self._func_desc
            ),
        }
        super_kwargs.update(**kwargs)
        super().__init__(**super_kwargs)
github pdpipe / pdpipe / pdpipe / col_generation.py View on Github external
def __init__(
        self,
        func,
        colname=None,
        follow_column=None,
        func_desc=None,
        prec=None,
        **kwargs
    ):
        if colname is None:
            colname = ApplyToRows._DEF_COLNAME
        if func_desc is None:
            func_desc = ""
        if prec is None:
            prec = _always_true
        self._func = func
        self._colname = colname
        self._follow_column = follow_column
        self._func_desc = func_desc
        self._prec_func = prec
        super_kwargs = {
            "exmsg": ApplyToRows._DEF_APPLYTOROWS_EXC_MSG.format(func_desc),
            "appmsg": ApplyToRows._DEF_APPLYTOROWS_APP_MSG.format(func_desc),
            "desc": "Generating a column with a function {}.".format(
                self._func_desc
            ),
        }
github pdpipe / pdpipe / pdpipe / col_generation.py View on Github external
prec=None,
        **kwargs
    ):
        if colname is None:
            colname = ApplyToRows._DEF_COLNAME
        if func_desc is None:
            func_desc = ""
        if prec is None:
            prec = _always_true
        self._func = func
        self._colname = colname
        self._follow_column = follow_column
        self._func_desc = func_desc
        self._prec_func = prec
        super_kwargs = {
            "exmsg": ApplyToRows._DEF_APPLYTOROWS_EXC_MSG.format(func_desc),
            "appmsg": ApplyToRows._DEF_APPLYTOROWS_APP_MSG.format(func_desc),
            "desc": "Generating a column with a function {}.".format(
                self._func_desc
            ),
        }
        super_kwargs.update(**kwargs)
        super().__init__(**super_kwargs)