File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -127,3 +127,8 @@ def test_jpl_barh_units():
127127 fig , ax = plt .subplots ()
128128 ax .barh (x , w , left = b )
129129 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):
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
You can’t perform that action at this time.
0 commit comments