ENH: improve nanmedian performance

remove unnecessary copy, an unnecessary sort and use inplace median on
the compressed copy.