@@ -29,6 +29,14 @@ class StrRow:
2929 rank : int = blosc2 .field (blosc2 .int64 (ge = 0 ), default = 0 )
3030
3131
32+ @dataclass
33+ class ListRow :
34+ id : int = blosc2 .field (blosc2 .int64 (ge = 0 ))
35+ tags : list [str ] = blosc2 .field ( # noqa: RUF009
36+ blosc2 .list (blosc2 .string (max_length = 16 ), nullable = True , batch_rows = 2 )
37+ )
38+
39+
3240DATA = [
3341 (3 , 80.0 , True ),
3442 (1 , 50.0 , False ),
@@ -185,6 +193,28 @@ def test_sort_all_columns_consistent():
185193 assert v == pytest .approx (expected [int (i )])
186194
187195
196+ def test_sort_copy_keeps_list_columns_aligned ():
197+ data = [(3 , ["c" ]), (1 , ["a" , "one" ]), (4 , ["d" ]), (2 , None ), (0 , [])]
198+ t = CTable (ListRow , new_data = data )
199+
200+ s = t .sort_by ("id" )
201+
202+ assert list (s ["id" ][:]) == [0 , 1 , 2 , 3 , 4 ]
203+ assert s ["tags" ][:] == [[], ["a" , "one" ], None , ["c" ], ["d" ]]
204+ assert t ["tags" ][:] == [["c" ], ["a" , "one" ], ["d" ], None , []]
205+
206+
207+ def test_sort_inplace_keeps_list_columns_aligned ():
208+ data = [(3 , ["c" ]), (1 , ["a" , "one" ]), (4 , ["d" ]), (2 , None ), (0 , [])]
209+ t = CTable (ListRow , new_data = data )
210+
211+ result = t .sort_by ("id" , inplace = True )
212+
213+ assert result is t
214+ assert list (t ["id" ][:]) == [0 , 1 , 2 , 3 , 4 ]
215+ assert t ["tags" ][:] == [[], ["a" , "one" ], None , ["c" ], ["d" ]]
216+
217+
188218# ===========================================================================
189219# Edge cases
190220# ===========================================================================
0 commit comments