Pipeline output looked sorted except where it obviously wasn't. Took me a while to narrow down.
>>> nan = float('nan') >>> sorted([3, nan, 1, 2])
[3, nan, 1, 2]
All comparisons with NaN return False, so sorted's assumption that < is a consistent ordering is broken. It doesn't raise. It returns something, and what it returns depends on where the NaN happens to be. Same goes for min and max.
Filter them first, or use a key that puts them at the end: sorted(xs, key=lambda x: (math.isnan(x), x)). pandas sort_values puts NaN last so I'd never seen this until I dropped to plain lists.