119
119
import functools
120
120
# cbook must import matplotlib only within function
121
121
# 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 )
123
126
from matplotlib .compat import subprocess
124
127
from matplotlib .rcsetup import (defaultParams ,
125
128
validate_backend ,
@@ -1541,7 +1544,7 @@ def _jupyter_nbextension_paths():
1541
1544
'matplotlib.tests.test_units' ,
1542
1545
'matplotlib.tests.test_widgets' ,
1543
1546
'matplotlib.tests.test_cycles' ,
1544
- 'matplotlib.tests.test_labeled_data_unpacking ' ,
1547
+ 'matplotlib.tests.test_preprocess_data ' ,
1545
1548
'matplotlib.sphinxext.tests.test_tinypages' ,
1546
1549
'mpl_toolkits.tests.test_mplot3d' ,
1547
1550
'mpl_toolkits.tests.test_axes_grid1' ,
@@ -1649,12 +1652,15 @@ def test(verbosity=1, coverage=False):
1649
1652
1650
1653
1651
1654
def _replacer (data , key ):
1655
+ """Either returns data[key] or passes data back. Also
1656
+ converts input data to a sequence as needed.
1657
+ """
1652
1658
# if key isn't a string don't bother
1653
1659
if not isinstance (key , six .string_types ):
1654
- return key
1660
+ return ( key )
1655
1661
# try to use __getitem__
1656
1662
try :
1657
- return data [key ]
1663
+ return sanitize_sequence ( data [key ])
1658
1664
# key does not exist, silently fall back to key
1659
1665
except KeyError :
1660
1666
return key
@@ -1673,7 +1679,7 @@ def _replacer(data, key):
1673
1679
"""
1674
1680
1675
1681
1676
- def unpack_labeled_data (replace_names = None , replace_all_args = False ,
1682
+ def _preprocess_data (replace_names = None , replace_all_args = False ,
1677
1683
label_namer = None , positional_parameter_names = None ):
1678
1684
"""
1679
1685
A decorator to add a 'data' kwarg to any a function. The signature
@@ -1707,6 +1713,8 @@ def foo(ax, *args, **kwargs)
1707
1713
NOTE: callables should only be used when the names and order of *args
1708
1714
can only be determined at runtime. Please use list of names
1709
1715
when the order and names of *args is clear before runtime!
1716
+
1717
+ .. note:: decorator also converts MappingView input data to list.
1710
1718
"""
1711
1719
if replace_names is not None :
1712
1720
replace_names = set (replace_names )
@@ -1847,7 +1855,10 @@ def inner(ax, *args, **kwargs):
1847
1855
label = None
1848
1856
1849
1857
data = kwargs .pop ('data' , None )
1850
- if data is not None :
1858
+
1859
+ if data is None : # data validation
1860
+ args = tuple (sanitize_sequence (a ) for a in args )
1861
+ else :
1851
1862
if arg_names_at_runtime :
1852
1863
# update the information about replace names and
1853
1864
# label position
0 commit comments