From: Travis O. <oli...@ie...> - 2006-11-04 01:54:41
|
George Sakkis wrote: > Albert Strasheim wrote: > > >> Check the thread "Strange results when sorting array with fields" from >> about a week back. Travis made some changes to sorting in the presence >> of fields that should solve your problem, assuming your fields appear in >> the order you want to sort (i.e. you want to sort f1, f2, f3 and not >> something like f1, f3, f2). >> > > I'm afraid this won't help in my case; I want to sort twice, once by f1 > and once by f2. I guess I could make a second file with the fields > swapped but this seems more messy and inefficient than Francesc's > suggestion. > As a final contribution before I become more quiet for a few weeks (and aside from hopefully releasing 1.0.1 soon), I've added a feature to allow specifying the sorting order for record arrays. It's added to the sort method as the order= keyword. You can pass in a string (specifying which field comes first --- all other fields will stay in the same order) or you can pass in a list or tuple which indicates the field order (any fields un-specified will stay in their same relative order). It works be creating a new data-type object with the .names attribute replaced with a newly ordered one and then calling sort on a view of the array with that data-type. The VOID_compare uses the names tuple to determine the ordering. This was the un-named option in my previous list. It's a better solution than all of the others, I think. The newly created data-type is discarded after the sorting is complete. -Travis |