I'm not sure about the bug, but the workaround may be the following:
sorted(
(2, 1, float('nan')),
lambda x,y: x is float('nan') and -1
or (y is float('nan') and 1
or cmp(x,y)))
which results in:
('nan', 1, 2)
Or remove nans before sorting or anything else.