File tree 2 files changed +10
-2
lines changed 2 files changed +10
-2
lines changed Original file line number Diff line number Diff line change @@ -127,3 +127,8 @@ def test_jpl_barh_units():
127
127
fig , ax = plt .subplots ()
128
128
ax .barh (x , w , left = b )
129
129
ax .set_xlim ([b - 1 * day , b + w [- 1 ]+ 1 * day ])
130
+
131
+
132
+ def test_emtpy_arrays ():
133
+ # Check that plotting an empty array with a dtype works
134
+ plt .scatter (np .array ([], dtype = 'datetime64[ns]' ), np .array ([]))
Original file line number Diff line number Diff line change @@ -160,13 +160,16 @@ def get_converter(self, x):
160
160
x = x .values
161
161
162
162
# 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 ))
164
167
xravel = x .ravel ()
165
168
try :
166
169
# pass the first value of x that is not masked back to
167
170
# get_converter
168
171
if not np .all (xravel .mask ):
169
- # some elements are not masked
172
+ # Get first non- masked item
170
173
converter = self .get_converter (
171
174
xravel [np .argmin (xravel .mask )])
172
175
return converter
You can’t perform that action at this time.
0 commit comments