Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
23 changes: 17 additions & 6 deletions lib/matplotlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,10 @@
import functools
# cbook must import matplotlib only within function
# definitions, so it is safe to import from it here.
from matplotlib.cbook import is_string_like, mplDeprecation, dedent, get_label
from matplotlib.cbook import (is_string_like,
mplDeprecation,
dedent, get_label,
sanitize_sequence)
from matplotlib.compat import subprocess
from matplotlib.rcsetup import (defaultParams,
validate_backend,
Expand Down Expand Up @@ -1541,7 +1544,7 @@ def _jupyter_nbextension_paths():
'matplotlib.tests.test_units',
'matplotlib.tests.test_widgets',
'matplotlib.tests.test_cycles',
'matplotlib.tests.test_labeled_data_unpacking',
'matplotlib.tests.test_preprocess_data',
'matplotlib.sphinxext.tests.test_tinypages',
'mpl_toolkits.tests.test_mplot3d',
'mpl_toolkits.tests.test_axes_grid1',
Expand Down Expand Up @@ -1649,12 +1652,15 @@ def test(verbosity=1, coverage=False):


def _replacer(data, key):
"""Either returns data[key] or passes data back. Also
converts input data to a sequence as needed.
"""
# if key isn't a string don't bother
if not isinstance(key, six.string_types):
return key
return (key)
# try to use __getitem__
try:
return data[key]
return sanitize_sequence(data[key])
# key does not exist, silently fall back to key
except KeyError:
return key
Expand All @@ -1673,7 +1679,7 @@ def _replacer(data, key):
"""


def unpack_labeled_data(replace_names=None, replace_all_args=False,
def _preprocess_data(replace_names=None, replace_all_args=False,
label_namer=None, positional_parameter_names=None):
"""
A decorator to add a 'data' kwarg to any a function. The signature
Expand Down Expand Up @@ -1707,6 +1713,8 @@ def foo(ax, *args, **kwargs)
NOTE: callables should only be used when the names and order of *args
can only be determined at runtime. Please use list of names
when the order and names of *args is clear before runtime!

.. note:: decorator also converts MappingView input data to list.
"""
if replace_names is not None:
replace_names = set(replace_names)
Expand Down Expand Up @@ -1847,7 +1855,10 @@ def inner(ax, *args, **kwargs):
label = None

data = kwargs.pop('data', None)
if data is not None:

if data is None: # data validation
args = tuple(sanitize_sequence(a) for a in args)
else:
if arg_names_at_runtime:
# update the information about replace names and
# label position
Expand Down
Loading