Skip to content

Commit 1a9640f

Browse files
committed
renames: asSequence->sanitize_sequence, unpack_labeled_data->_preprocess_data
1 parent d308eec commit 1a9640f

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,
@@ -1541,7 +1544,7 @@ def _jupyter_nbextension_paths():
15411544
'matplotlib.tests.test_units',
15421545
'matplotlib.tests.test_widgets',
15431546
'matplotlib.tests.test_cycles',
1544-
'matplotlib.tests.test_labeled_data_unpacking',
1547+
'matplotlib.tests.test_preprocess_data',
15451548
'matplotlib.sphinxext.tests.test_tinypages',
15461549
'mpl_toolkits.tests.test_mplot3d',
15471550
'mpl_toolkits.tests.test_axes_grid1',
@@ -1649,12 +1652,15 @@ def test(verbosity=1, coverage=False):
16491652

16501653

16511654
def _replacer(data, key):
1655+
"""Either returns data[key] or passes data back. Also
1656+
converts input data to a sequence as needed.
1657+
"""
16521658
# if key isn't a string don't bother
16531659
if not isinstance(key, six.string_types):
1654-
return key
1660+
return (key)
16551661
# try to use __getitem__
16561662
try:
1657-
return data[key]
1663+
return sanitize_sequence(data[key])
16581664
# key does not exist, silently fall back to key
16591665
except KeyError:
16601666
return key
@@ -1673,7 +1679,7 @@ def _replacer(data, key):
16731679
"""
16741680

16751681

1676-
def unpack_labeled_data(replace_names=None, replace_all_args=False,
1682+
def _preprocess_data(replace_names=None, replace_all_args=False,
16771683
label_namer=None, positional_parameter_names=None):
16781684
"""
16791685
A decorator to add a 'data' kwarg to any a function. The signature
@@ -1707,6 +1713,8 @@ def foo(ax, *args, **kwargs)
17071713
NOTE: callables should only be used when the names and order of *args
17081714
can only be determined at runtime. Please use list of names
17091715
when the order and names of *args is clear before runtime!
1716+
1717+
.. note:: decorator also converts MappingView input data to list.
17101718
"""
17111719
if replace_names is not None:
17121720
replace_names = set(replace_names)
@@ -1847,7 +1855,10 @@ def inner(ax, *args, **kwargs):
18471855
label = None
18481856

18491857
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:
18511862
if arg_names_at_runtime:
18521863
# update the information about replace names and
18531864
# label position

0 commit comments

Comments
 (0)