@@ -361,11 +361,11 @@ def to_rgba(self, x, alpha=None, bytes=False, norm=True):
361
361
362
362
def set_array (self , A ):
363
363
"""
364
- Set the image array from numpy array *A*.
364
+ Set the image array from array-like *A*.
365
365
366
366
Parameters
367
367
----------
368
- A : ndarray or None
368
+ A : array-like or None
369
369
"""
370
370
if A is None :
371
371
self ._A = None
@@ -375,14 +375,14 @@ def set_array(self, A):
375
375
A_ = A .ravel ()
376
376
width , height = self ._meshWidth , self ._meshHeight
377
377
if self ._shading == 'flat' :
378
- if not ( len (A_ ) == width * height or
379
- len (A_ ) == (width + 1 ) * (height + 1 )):
378
+ if not (len (A_ ) == width * height or
379
+ len (A_ ) == (width + 1 ) * (height + 1 )):
380
380
raise TypeError (
381
381
'Dimensions of A %s are incompatible with '
382
382
'X (%d) and/or Y (%d)' %
383
383
(A .shape , width , height ))
384
384
elif self ._shading == 'nearest' :
385
- if not ( len (A_ ) == width * height :
385
+ if not (len (A_ ) == width * height ) :
386
386
raise TypeError (
387
387
'Dimensions of A %s are incompatible with '
388
388
'X (%d) and/or Y (%d)' %
@@ -394,6 +394,11 @@ def set_array(self, A):
394
394
'X (%d) and/or Y (%d)' %
395
395
(A .shape , width , height ))
396
396
397
+ A = cbook .safe_masked_invalid (A , copy = True )
398
+ if not np .can_cast (A .dtype , float , "same_kind" ):
399
+ raise TypeError (f"Image data of dtype { A .dtype } cannot be "
400
+ "converted to float" )
401
+
397
402
self ._A = A
398
403
399
404
def get_array (self ):
0 commit comments