BUG: preserve ndarray subclasses in median

closes gh-3846
Merge pull request #3855 from charris/backport-1.8-3851

Backport 1.8 3851