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

Skip to content

Commit cee4ba9

Browse files
committed
Fix infinite recursion in units with ndarray subclasses.
This was partially addressed for masked arrays in #2290. However, this does not work for all ndarray sub-classes, like the quantities package. The fix here is to make sure ravel is actually succeeding in changing the shape of the object. If it doesn't just return what we've got.
1 parent c91589c commit cee4ba9

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

lib/matplotlib/units.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,13 @@ def get_converter(self, x):
149149
return converter
150150
except AttributeError:
151151
# not a masked_array
152-
converter = self.get_converter(xravel[0])
152+
# Make sure we don't recurse forever -- it's possible for
153+
# ndarray subclasses to continue to return subclasses and
154+
# not ever return a non-subclass for a single element.
155+
next_item = xravel[0]
156+
if (not isinstance(next_item, np.ndarray) or
157+
next_item.shape != x.shape):
158+
converter = self.get_converter(next_item)
153159
return converter
154160

155161
if converter is None and iterable(x):

0 commit comments

Comments
 (0)