8000 MNT: unify code path of set, update, setp by tacaswell · Pull Request #5599 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

MNT: unify code path of set, update, setp #5599

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 7 commits into from
Dec 14, 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
Next Next commit
MNT: use ordereddict to order args in setp
Make one call to `update` with the ordered dict rather than
one call per element.
  • Loading branch information
tacaswell committed Dec 1, 2015
commit 0ea5fff31083924d9992161a30476e6fbd10e928
12 changes: 6 additions & 6 deletions lib/matplotlib/artist.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
unicode_literals)

from matplotlib.externals import six
from collections import OrderedDict

import re
import warnings
Expand Down Expand Up @@ -1451,17 +1452,16 @@ def setp(obj, *args, **kwargs):
if not cbook.iterable(obj):
objs = [obj]
else:
objs = cbook.flatten(obj)
objs = list(cbook.flatten(obj))

if len(args) % 2:
raise ValueError('The set args must be string, value pairs')

funcvals = []
# put args into ordereddict to maintain order
funcvals = OrderedDict()
for i in range(0, len(args) - 1, 2):
funcvals.append((args[i], args[i + 1]))
# do the *args one at a time to ensure order
ret = [o.update({s: val}) for s, val in funcvals for o in objs]
# apply kwargs in bulk
funcvals[args[i]] = args[i + 1]
ret = [o.update(funcvals) for o in objs]
ret.extend([o.update(kwargs) for o in objs])
return [x for x in cbook.flatten(ret)]

Expand Down
0