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 ,
@@ -1544,7 +1547,7 @@ def _jupyter_nbextension_paths():
1544
1547
'matplotlib.tests.test_units' ,
1545
1548
'matplotlib.tests.test_widgets' ,
1546
1549
'matplotlib.tests.test_cycles' ,
1547
- 'matplotlib.tests.test_labeled_data_unpacking ' ,
1550
+ 'matplotlib.tests.test_preprocess_data ' ,
1548
1551
'matplotlib.sphinxext.tests.test_tinypages' ,
1549
1552
'mpl_toolkits.tests.test_mplot3d' ,
1550
1553
'mpl_toolkits.tests.test_axes_grid1' ,
@@ -1652,12 +1655,15 @@ def test(verbosity=1, coverage=False):
1652
1655
1653
1656
1654
1657
def _replacer (data , key ):
1658
+ """Either returns data[key] or passes data back. Also
1659
+ converts input data to a sequence as needed.
1660
+ """
1655
1661
# if key isn't a string don't bother
1656
1662
if not isinstance (key , six .string_types ):
1657
- return key
1663
+ return ( key )
1658
1664
# try to use __getitem__
1659
1665
try :
1660
- return data [key ]
1666
+ return sanitize_sequence ( data [key ])
1661
1667
# key does not exist, silently fall back to key
1662
1668
except KeyError :
1663
1669
return key
@@ -1676,7 +1682,7 @@ def _replacer(data, key):
1676
1682
"""
1677
1683
1678
1684
1679
- def unpack_labeled_data (replace_names = None , replace_all_args = False ,
1685
+ def _preprocess_data (replace_names = None , replace_all_args = False ,
1680
1686
label_namer = None , positional_parameter_names = None ):
1681
1687
"""
1682
1688
A decorator to add a 'data' kwarg to any a function. The signature
@@ -1710,6 +1716,8 @@ def foo(ax, *args, **kwargs)
1710
1716
NOTE: callables should only be used when the names and order of *args
1711
1717
can only be determined at runtime. Please use list of names
1712
1718
when the order and names of *args is clear before runtime!
1719
+
1720
+ .. note:: decorator also converts MappingView input data to list.
1713
1721
"""
1714
1722
if replace_names is not None :
1715
1723
replace_names = set (replace_names )
@@ -1850,7 +1858,10 @@ def inner(ax, *args, **kwargs):
1850
1858
label = None
1851
1859
1852
1860
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 :
1854
1865
if arg_names_at_runtime :
1855
1866
# update the information about replace names and
1856
1867
# label position
0 commit comments