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

Skip to content

Commit eda2d01

Browse files
committed
Use iterator to avoid keyerror
1 parent 125dec7 commit eda2d01

1 file changed

Lines changed: 13 additions & 7 deletions

File tree

lib/matplotlib/axis.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1527,15 +1527,21 @@ def have_units(self):
15271527
def convert_units(self, x):
15281528
# If x is already a number
15291529
if munits.ConversionInterface.is_numlike(x):
1530+
if np.iterable(x):
1531+
is_decimal = False
1532+
# use iterator to avoid key error
1533+
for thisx in x:
1534+
is_decimal = isinstance(thisx, Decimal)
1535+
if is_decimal:
1536+
converter = np.asarray
1537+
if isinstance(x, ma.MaskedArray):
1538+
converter = ma.asarray
1539+
return converter(x, dtype=np.float)
1540+
else:
1541+
return x
15301542
# need to convert when x is a Decimal
1531-
if isinstance(x, Decimal):
1543+
elif isinstance(x, Decimal):
15321544
return np.float(x)
1533-
# need to convert when x is a list of Decimal
1534-
elif np.iterable(x) and len(x) > 0 and isinstance(x[0], Decimal):
1535-
converter = np.asarray
1536-
if isinstance(x, ma.MaskedArray):
1537-
converter = ma.asarray
1538-
return converter(x, dtype=np.float)
15391545
# Otherwise, doesn't need converting
15401546
else:
15411547
return x

0 commit comments

Comments
 (0)