ENH: improve nanmedian performance

remove unnecessary copy, an unnecessary sort and use inplace median on
the compressed copy.
Merge pull request #3335 from juliantaylor/nanmedian

ENH: improve nanmedian performance