From: <ry...@us...> - 2009-01-16 20:26:48
|
Revision: 6798 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6798&view=rev Author: ryanmay Date: 2009-01-16 20:26:39 +0000 (Fri, 16 Jan 2009) Log Message: ----------- 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 Modified Paths: -------------- trunk/matplotlib/CHANGELOG trunk/matplotlib/lib/matplotlib/units.py trunk/matplotlib/unit/nose_tests.py Modified: trunk/matplotlib/CHANGELOG =================================================================== --- trunk/matplotlib/CHANGELOG 2009-01-16 20:06:55 UTC (rev 6797) +++ trunk/matplotlib/CHANGELOG 2009-01-16 20:26:39 UTC (rev 6798) @@ -1,8 +1,12 @@ -2009-11-16 Bugfix of C typedef of MPL_Int64 that was failing on +2009-01-16 Fix an infinite recursion in the unit registry when searching + for a converter for a sequence of strings. Add a corresponding + test. - RM + +2009-01-16 Bugfix of C typedef of MPL_Int64 that was failing on Windows XP 64 bit, as reported by George Goussard on numpy mailing list. - ADS -2009-11-16 Added helper function LinearSegmentedColormap.from_list to +2009-01-16 Added helper function LinearSegmentedColormap.from_list to facilitate building simple custom colomaps. See examples/pylab_examples/custom_cmap_fromlist.py - JDH Modified: trunk/matplotlib/lib/matplotlib/units.py =================================================================== --- trunk/matplotlib/lib/matplotlib/units.py 2009-01-16 20:06:55 UTC (rev 6797) +++ trunk/matplotlib/lib/matplotlib/units.py 2009-01-16 20:26:39 UTC (rev 6798) @@ -44,7 +44,7 @@ """ import numpy as np -from matplotlib.cbook import iterable, is_numlike +from matplotlib.cbook import iterable, is_numlike, is_string_like class AxisInfo: 'information to support default axis labeling and tick labeling' @@ -127,7 +127,10 @@ if classx is not None: converter = self.get(classx) - if converter is None and iterable(x): + # Check explicity for strings here because they would otherwise + # lead to an infinite recursion, because a single character will + # pass the iterable() check. + if converter is None and iterable(x) and not is_string_like(x): # if this is anything but an object array, we'll assume # there are no custom units if isinstance(x, np.ndarray) and x.dtype != np.object: Modified: trunk/matplotlib/unit/nose_tests.py =================================================================== --- trunk/matplotlib/unit/nose_tests.py 2009-01-16 20:06:55 UTC (rev 6797) +++ trunk/matplotlib/unit/nose_tests.py 2009-01-16 20:26:39 UTC (rev 6798) @@ -40,6 +40,17 @@ fig.canvas.draw() plt.close(fig) +def test_units_strings(): + # Make sure passing in sequences of strings doesn't cause the unit + # conversion registry to recurse infinitely + Id = ['50', '100', '150', '200', '250'] + pout = ['0', '7.4', '11.4', '14.2', '16.3'] + fig = plt.figure() + ax = fig.add_subplot(111) + ax.plot(Id, pout) + fig.canvas.draw() + plt.close(fig) + if __name__=='__main__': nose.runmodule(argv=['-s','--with-doctest'], exit=False) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |