script_utils.getObjects() sorts by IDs#1202
Conversation
|
In terms of logic, sorting objects returned by the server by input ids is sensible and should fix bugs in other scripts than the one ticketed. 👍 Ready to merge. NB: I tried to test this PR using the |
|
Ticket for Combine_Images script: https://trac.openmicroscopy.org.uk/ome/ticket/10960 |
There was a problem hiding this comment.
NB: Assuming objects is a list objects.sort(lambda left, right: cmp(left.id, right.id)) would suffice.
There was a problem hiding this comment.
I'm not trying to sort the objects by their own IDs. I'm trying to sort them so that they are in the same order as the list of ids that I used to retrieve them. E.g. ids = [5, 3, 4] then I want to sort objects to be: [<ImageWrapper id:5>, <ImageWrapper id:3>, <ImageWrapper id:4>]
I thought there might be a 'one-liner' to do it, but I couldn't work it out.
There was a problem hiding this comment.
Ugh. Ok. Agreed. As interesting as that sounds, I bet it's going to be way more confusing than your two liner! Sorry for the noise.
...objects.sort(lambda l,r: cmp(ids.index(l.id), ids.index(r.id)))
comes close but will throw a ValueError if the id isn't in ids
but so would yours.
|
Being quiet now. |
script_utils.getObjects() sorts by IDs
See bug #10745. We now sort objects by IDs in script_utils.getObjects().
To test: