Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cce139d

Browse files
author
James Evans
committed
Changed the algorithm that determines what converter to use for
unitized data to allow for strings and numpy arrays of types other than 'object'. The new algorithm takes into account the possibility of infinite recursion for strings or any other type. svn path=/trunk/matplotlib/; revision=7905
1 parent 032edee commit cce139d

1 file changed

Lines changed: 7 additions & 11 deletions

File tree

lib/matplotlib/units.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -128,18 +128,14 @@ def get_converter(self, x):
128128
if classx is not None:
129129
converter = self.get(classx)
130130

131-
# Check explicity for strings here because they would otherwise
132-
# lead to an infinite recursion, because a single character will
133-
# pass the iterable() check.
134-
if converter is None and iterable(x) and not is_string_like(x):
135-
# if this is anything but an object array, we'll assume
136-
# there are no custom units
137-
if isinstance(x, np.ndarray) and x.dtype != np.object:
138-
return None
139-
131+
if converter is None and iterable(x):
140132
for thisx in x:
141-
converter = self.get_converter( thisx )
142-
return converter
133+
# Make sure that recursing might actually lead to a solution, if
134+
# we are just going to re-examine another item of the same kind,
135+
# then do not look at it.
136+
if classx and classx != getattr(thisx, '__class__', None):
137+
converter = self.get_converter( thisx )
138+
return converter
143139

144140
#DISABLED self._cached[idx] = converter
145141
return converter

0 commit comments

Comments
 (0)