8000 ENH: add by_key by tacaswell · Pull Request #26 · matplotlib/cycler · GitHub
[go: up one dir, main page]

Skip to content

ENH: add by_key #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 13, 2015
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
TST: add explicit tests for by_key
Used internally for slicing so was implicitly covered.
  • Loading branch information
tacaswell committed Dec 1, 2015
commit 714b3466187486d6ee72f4adbad47e0a9a4fb958
28 changes: 28 additions & 0 deletions test_cycler.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
assert_raises, assert_true)
from itertools import product, cycle, chain
from operator import add, iadd, mul, imul
from collections import defaultdict


def _cycler_helper(c, length, keys, values):
Expand Down Expand Up @@ -300,3 +301,30 @@ def test_concat_fail():
b = cycler('b', range(3))
assert_raises(ValueError, concat, a, b)
assert_raises(ValueError, a.concat, b)


def _by_key_helper(cy):
res = cy.by_key()
target = defaultdict(list)
for sty in cy:
for k, v in sty.items():
target[k].append(v)

assert_equal(res, target)


def test_by_key_add():
input_dict = dict(c=list('rgb'), lw=[1, 2, 3])
cy = cycler(c=input_dict['c']) + cycler(lw=input_dict['lw'])
res = cy.by_key()
assert_equal(res, input_dict)
yield _by_key_helper, cy


def test_by_key_mul():
input_dict = dict(c=list('rg'), lw=[1, 2, 3])
cy = cycler(c=input_dict['c']) * cycler(lw=input_dict['lw'])
res = cy.by_key()
assert_equal(input_dict['lw'] * len(input_dict['c']),
res['lw'])
yield _by_key_helper, cy
0