Skip to content

Conversation

@dlovell
Copy link
Contributor

@dlovell dlovell commented Dec 23, 2018

I believe there's a bug in the In Memory Split-Apply-Combine section regarding where to import groupby and valmap from.

If I run

from toolz import compose, pipe
from toolz.curried import get, pluck


def run_working(accounts):
    from toolz.curried import groupby, valmap
    return pipe(accounts, groupby(get(3)), valmap(compose(sum, pluck(2))))


def run_borken(accounts):
    # TypeError: groupby() missing 1 required positional argument: 'seq'
    from toolz import groupby, valmap
    return pipe(accounts, groupby(get(3)), valmap(compose(sum, pluck(2))))


if __name__ == '__main__':
    accounts = [
        # id, name, balance, gender
        (1, 'Alice', 100, 'F'),
        (2, 'Bob', 200, 'M'),
        (3, 'Charlie', 150, 'M'),
        (4, 'Dennis', 50, 'M'),
        (5, 'Edith', 300, 'F'),
    ]
    print('run_working(accounts):')
    print(run_working(accounts))
    print('run_borken(accounts):')
    print(run_borken(accounts))

I see

run_working(accounts):
{'F': 400, 'M': 400}
run_borken(accounts):
Traceback (most recent call last):
  File "script.py", line 29, in <module>
    print(run_borken(accounts))
  File "script.py", line 14, in run_borken
    return pipe(accounts, groupby(get(3)), valmap(compose(sum, pluck(2))))
TypeError: groupby() missing 1 required positional argument: 'seq'

@eriknw
Copy link
Member

eriknw commented Jun 22, 2019

Looks good, thanks @dlovell (and sorry for the delay)!

@eriknw eriknw merged commit 0da106d into pytoolz:master Jun 22, 2019
@bitwombat
Copy link

Should this fix be showing up on https://toolz.readthedocs.io/en/latest/streaming-analytics.html ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants