@@ -1127,6 +1127,28 @@ def test_precomputed_rgba_passthrough(self):
11271127 arr = np .array ([[1.0 , 0.0 , 0.0 , 1.0 ], [0.0 , 0.0 , 1.0 , 1.0 ]])
11281128 np .testing .assert_allclose (ColorSpec ("continuous" , None , arr ).to_rgba (self ._params ()), arr )
11291129
1130+ def test_codes_gather_matches_per_row_parse (self ):
1131+ # the categorical codes-gather and the object factorize-gather must equal to_rgba_array(list(...))
1132+ from matplotlib import colors
1133+
1134+ from spatialdata_plot .pl ._color import ColorSpec
1135+
1136+ hexes = ["#e41a1cff" , "#377eb8ff" , "#4daf4aff" , "#984ea3ff" ]
1137+ na = "#cccccc00"
1138+ rng = np .random .default_rng (0 )
1139+ clean = pd .Categorical .from_codes (rng .integers (0 , len (hexes ), 2000 ), categories = hexes )
1140+ with_na = pd .Categorical .from_codes (rng .integers (0 , len (hexes ) + 1 , 2000 ), categories = [* hexes , na ])
1141+ variants = [
1142+ clean , # categorical fast-path
1143+ with_na , # NaN replaced with an na_color category -> codes still >= 0
1144+ clean [:800 ].remove_unused_categories (), # filtered -> remapped codes
1145+ np .full (500 , na , dtype = object ), # uniform na (object vector)
1146+ np .concatenate ([np .asarray (list (clean [:300 ]), dtype = object ), np .full (100 , na , dtype = object )]), # padded
1147+ ]
1148+ for cv in variants : # cv doubles as the (only-checked-for-not-None) source_vector
1149+ spec = ColorSpec ("categorical" if hasattr (cv , "codes" ) else "none" , cv , cv )
1150+ np .testing .assert_array_equal (spec .to_rgba (self ._params ()), np .asarray (colors .to_rgba_array (list (cv ))))
1151+
11301152
11311153class TestPercentileNormalize :
11321154 """PercentileNormalize + _resolve_continuous_norm (issue #370: dim multichannel renders)."""
0 commit comments