Index union sort hack
- [x] closes #17376
- [x] tests added / passed
- [x] passes `git diff master -u -- "*.py" | flake8 --diff`
- [x] whatsnew entry

This is an attempt to adapt #17378 according to @gfyoung 's suggestions.

(I do plan to investigate more in depth the problem in Windows, I just won't be able to do it soon)