10000 Fix inferring units for zero-sized arrays · matplotlib/matplotlib@c250254 · GitHub
[go: up one dir, main page]

Skip to content

Commit c250254

Browse files
committed
Fix inferring units for zero-sized arrays
1 parent b99e636 commit c250254

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

lib/matplotlib/units.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,13 +160,16 @@ def get_converter(self, x):
160160
x = x.values
161161

162162
# If x is an array, look inside the array for data with units
163-
if isinstance(x, np.ndarray) and x.size:
163+
if isinstance(x, np.ndarray):
164+
# If there are no elements in x, infer the units from its dtype
165+
if not x.size:
166+
return self.get_converter(np.array([0], dtype=x.dtype))
164167
xravel = x.ravel()
165168
try:
166169
# pass the first value of x that is not masked back to
167170
# get_converter
168171
if not np.all(xravel.mask):
169-
# some elements are not masked
172+
# Get first non-masked item
170173
converter = self.get_converter(
171174
xravel[np.argmin(xravel.mask)])
172175
return converter

0 commit comments

Comments
 (0)
0