graphkit icon indicating copy to clipboard operation
graphkit copied to clipboard

FEAT: +TOKEN modifier for side-effect functions

Open ankostis opened this issue 5 years ago • 3 comments

Inputs & outputs in needs & provides kwargs designated as token work as usual while solving the DAG but they are never assigned any values to/from the operation's functions:

from graphkit import operation, compose
from graphkit.modifiers import token

# Function appending a new dataframe column from two pre-existing ones.
def addcolumns(df):
    df['sum'] = df['a'] + df['b']

# Designate `a`, `b` & `sum` column names as an token arguments.
graph = compose('mygraph')(
    operation(
        name='addcolumns',
        needs=['df', token('a'), token('b')],
        provides=[token('sum')])(addcolumns)
)

# The graph works with and without 'c' provided as input.
df = pd.DataFrame({'a': [5], 'b': [2]})
assert graph({'df': df})['sum'] == 11

I confirm that this contribution is made under the terms of the license found in the root directory of this repository's source tree and that I have the authority necessary to make this contribution on behalf of its copyright owner.

ankostis avatar Sep 28 '19 09:09 ankostis

Thank you for submitting this pull request, however I do not see a valid CLA on file for you. Before we can merge this request please visit https://yahoocla.herokuapp.com/ and agree to the terms. Thanks! :smile:

yahoocla avatar Sep 28 '19 09:09 yahoocla

Just didi it.

Is it understood what I'm trying to achieve?

ankostis avatar Sep 28 '19 13:09 ankostis

Codecov Report

Merging #15 into master will increase coverage by 13.14%. The diff coverage is 92.81%.

Impacted file tree graph

@@             Coverage Diff             @@
##           master      #15       +/-   ##
===========================================
+ Coverage   77.87%   91.01%   +13.14%     
===========================================
  Files           5        6        +1     
  Lines         348      501      +153     
===========================================
+ Hits          271      456      +185     
+ Misses         77       45       -32
Impacted Files Coverage Δ
graphkit/modifiers.py 100% <100%> (ø) :arrow_up:
graphkit/functional.py 93.9% <100%> (+0.15%) :arrow_up:
graphkit/plot.py 89.68% <89.68%> (ø)
graphkit/base.py 81.01% <90.9%> (+1.64%) :arrow_up:
graphkit/network.py 94.14% <94.11%> (+23.94%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update e70718b...3e06148. Read the comment docs.

codecov-io avatar Sep 28 '19 15:09 codecov-io