@@ -766,6 +766,33 @@ def test_conversions():
766766 hex_color
767767
768768
769+ def test_conversions_masked ():
770+ x1 = np .ma .array (['k' , 'b' ], mask = [True , False ])
771+ x2 = np .ma .array ([[0 , 0 , 0 , 1 ], [0 , 0 , 1 , 1 ]])
772+ x2 [0 ] = np .ma .masked
773+ assert mcolors .to_rgba (x1 [0 ]) == (0 , 0 , 0 , 0 )
774+ assert_array_equal (mcolors .to_rgba_array (x1 ),
775+ [[0 , 0 , 0 , 0 ], [0 , 0 , 1 , 1 ]])
776+ assert_array_equal (mcolors .to_rgba_array (x2 ), mcolors .to_rgba_array (x1 ))
777+
778+
779+ def test_to_rgba_array_single_str ():
780+ # single color name is valid
781+ assert_array_equal (mcolors .to_rgba_array ("red" ), [(1 , 0 , 0 , 1 )])
782+
783+ # single char color sequence is deprecated
784+ with pytest .warns (cbook .MatplotlibDeprecationWarning ,
785+ match = "Using a string of single character colors as a "
786+ "color sequence is deprecated" ):
787+ array = mcolors .to_rgba_array ("rgb" )
788+ assert_array_equal (array , [(1 , 0 , 0 , 1 ), (0 , 0.5 , 0 , 1 ), (0 , 0 , 1 , 1 )])
789+
790+ with pytest .raises (ValueError ,
791+ match = "neither a valid single color nor a color "
792+ "sequence" ):
793+ mcolors .to_rgba_array ("rgbx" )
794+
795+
769796def test_grey_gray ():
770797 color_mapping = mcolors ._colors_full_map
771798 for k in color_mapping .keys ():
0 commit comments