@@ -766,6 +766,29 @@ 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+ array = mcolors .to_rgba_array ("rgb" )
785+ assert_array_equal (array , [(1 , 0 , 0 , 1 ), (0 , 0.5 , 0 , 1 ), (0 , 0 , 1 , 1 )])
786+
787+ with pytest .raises (ValueError ,
788+ match = "Invalid RGBA argument: 'x'" ):
789+ mcolors .to_rgba_array ("rgbx" )
790+
791+
769792def test_grey_gray ():
770793 color_mapping = mcolors ._colors_full_map
771794 for k in color_mapping .keys ():
0 commit comments