refactor reindexing to index.py
add nan/non-sorted test