Skip to content

Commit 9f0d770

Browse files
authored
Merge pull request #6787 from story645/dict3
Python3.5 dictview support
2 parents 12cafa9 + 1a9640f commit 9f0d770

File tree

5 files changed

+111
-80
lines changed

5 files changed

+111
-80
lines changed

lib/matplotlib/__init__.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,10 @@
119119
import functools
120120
# cbook must import matplotlib only within function
121121
# definitions, so it is safe to import from it here.
122-
from matplotlib.cbook import is_string_like, mplDeprecation, dedent, get_label
122+
from matplotlib.cbook import (is_string_like,
123+
mplDeprecation,
124+
dedent, get_label,
125+
sanitize_sequence)
123126
from matplotlib.compat import subprocess
124127
from matplotlib.rcsetup import (defaultParams,
125128
validate_backend,
@@ -1544,7 +1547,7 @@ def _jupyter_nbextension_paths():
15441547
'matplotlib.tests.test_units',
15451548
'matplotlib.tests.test_widgets',
15461549
'matplotlib.tests.test_cycles',
1547-
'matplotlib.tests.test_labeled_data_unpacking',
1550+
'matplotlib.tests.test_preprocess_data',
15481551
'matplotlib.sphinxext.tests.test_tinypages',
15491552
'mpl_toolkits.tests.test_mplot3d',
15501553
'mpl_toolkits.tests.test_axes_grid1',
@@ -1652,12 +1655,15 @@ def test(verbosity=1, coverage=False):
16521655

16531656

16541657
def _replacer(data, key):
1658+
"""Either returns data[key] or passes data back. Also
1659+
converts input data to a sequence as needed.
1660+
"""
16551661
# if key isn't a string don't bother
16561662
if not isinstance(key, six.string_types):
1657-
return key
1663+
return (key)
16581664
# try to use __getitem__
16591665
try:
1660-
return data[key]
1666+
return sanitize_sequence(data[key])
16611667
# key does not exist, silently fall back to key
16621668
except KeyError:
16631669
return key
@@ -1676,7 +1682,7 @@ def _replacer(data, key):
16761682
"""
16771683

16781684

1679-
def unpack_labeled_data(replace_names=None, replace_all_args=False,
1685+
def _preprocess_data(replace_names=None, replace_all_args=False,
16801686
label_namer=None, positional_parameter_names=None):
16811687
"""
16821688
A decorator to add a 'data' kwarg to any a function. The signature
@@ -1710,6 +1716,8 @@ def foo(ax, *args, **kwargs)
17101716
NOTE: callables should only be used when the names and order of *args
17111717
can only be determined at runtime. Please use list of names
17121718
when the order and names of *args is clear before runtime!
1719+
1720+
.. note:: decorator also converts MappingView input data to list.
17131721
"""
17141722
if replace_names is not None:
17151723
replace_names = set(replace_names)
@@ -1850,7 +1858,10 @@ def inner(ax, *args, **kwargs):
18501858
label = None
18511859

18521860
data = kwargs.pop('data', None)
1853-
if data is not None:
1861+
1862+
if data is None: # data validation
1863+
args = tuple(sanitize_sequence(a) for a in args)
1864+
else:
18541865
if arg_names_at_runtime:
18551866
# update the information about replace names and
18561867
# label position

0 commit comments

Comments
 (0)