Skip to content

Commit eb93ad1

Browse files
committed
Fix an infinite recursion in the unit registry when trying to find a converter for a sequence of strings. Add a test for this to unit/nose_tests.py
svn path=/trunk/matplotlib/; revision=6798
1 parent 877532e commit eb93ad1

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

CHANGELOG

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
2009-11-16 Bugfix of C typedef of MPL_Int64 that was failing on
1+
2009-01-16 Fix an infinite recursion in the unit registry when searching
2+
for a converter for a sequence of strings. Add a corresponding
3+
test. - RM
4+
5+
2009-01-16 Bugfix of C typedef of MPL_Int64 that was failing on
26
Windows XP 64 bit, as reported by George Goussard on numpy
37
mailing list. - ADS
48

5-
2009-11-16 Added helper function LinearSegmentedColormap.from_list to
9+
2009-01-16 Added helper function LinearSegmentedColormap.from_list to
610
facilitate building simple custom colomaps. See
711
examples/pylab_examples/custom_cmap_fromlist.py - JDH
812

lib/matplotlib/units.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def default_units(x):
4444
4545
"""
4646
import numpy as np
47-
from matplotlib.cbook import iterable, is_numlike
47+
from matplotlib.cbook import iterable, is_numlike, is_string_like
4848

4949
class AxisInfo:
5050
'information to support default axis labeling and tick labeling'
@@ -127,7 +127,10 @@ def get_converter(self, x):
127127
if classx is not None:
128128
converter = self.get(classx)
129129

130-
if converter is None and iterable(x):
130+
# Check explicity for strings here because they would otherwise
131+
# lead to an infinite recursion, because a single character will
132+
# pass the iterable() check.
133+
if converter is None and iterable(x) and not is_string_like(x):
131134
# if this is anything but an object array, we'll assume
132135
# there are no custom units
133136
if isinstance(x, np.ndarray) and x.dtype != np.object:

unit/nose_tests.py

+11
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,17 @@ def test_markevery():
4040
fig.canvas.draw()
4141
plt.close(fig)
4242

43+
def test_units_strings():
44+
# Make sure passing in sequences of strings doesn't cause the unit
45+
# conversion registry to recurse infinitely
46+
Id = ['50', '100', '150', '200', '250']
47+
pout = ['0', '7.4', '11.4', '14.2', '16.3']
48+
fig = plt.figure()
49+
ax = fig.add_subplot(111)
50+
ax.plot(Id, pout)
51+
fig.canvas.draw()
52+
plt.close(fig)
53+
4354
if __name__=='__main__':
4455
nose.runmodule(argv=['-s','--with-doctest'], exit=False)
4556

0 commit comments

Comments
 (0)