Skip to content

Commit b4709b3

Browse files
committed
Allow using non-strings as data keys
1 parent 6646545 commit b4709b3

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

lib/matplotlib/__init__.py

+6-8
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@
123123
from matplotlib.rcsetup import (defaultParams,
124124
validate_backend)
125125

126+
from collections import Hashable
127+
import numbers
126128
import numpy
127129
from matplotlib.externals.six.moves.urllib.request import urlopen
128130
from matplotlib.externals.six.moves import reload_module as reload
@@ -1517,15 +1519,11 @@ def test(verbosity=1):
15171519

15181520

15191521
def _replacer(data, key):
1520-
# if key isn't a string don't bother
1521-
if not isinstance(key, six.string_types):
1522-
return key
1523-
# try to use __getitem__
1524-
try:
1525-
return data[key]
1526-
# key does not exist, silently fall back to key
1527-
except KeyError:
1522+
# don't bother if key is a number or array, or not a possible hash key
1523+
if isinstance(key, (numbers.Number, numpy.ndarray)) or not isinstance(key, Hashable):
15281524
return key
1525+
# try to use __getitem__, otherwise fall back to key
1526+
return data.get(key, key)
15291527

15301528

15311529
def unpack_labeled_data(wl_args=None, wl_kwargs=None, label_pos=None):

0 commit comments

Comments
 (0)