Skip to content

Commit f887005

Browse files
committed
attempt to work around older numpy versions using ma.median
1 parent 5cc93a4 commit f887005

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

‎astropy/stats/funcs.py‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
import numpy as np
1515

16+
from astropy.utils.compat import NUMPY_LT_1_10
17+
1618
from ..extern.six.moves import xrange
1719

1820

@@ -766,8 +768,18 @@ def median_absolute_deviation(a, axis=None, ignore_nan=False):
766768
# returns an masked array even if the result should be scalar). (#4658)
767769
if isinstance(a, np.ma.MaskedArray):
768770
func = np.ma.median
771+
if ignore_nan:
772+
data = np.ma.masked_invalid(data)
769773
elif ignore_nan:
770-
func = np.nanmedian
774+
if NUMPY_LT_1_10:
775+
# older versions don't have nanmedian, but nanmedian
776+
# is generally faster than np.ma.median (at least, that is implied
777+
# in
778+
# https://github.com/astropy/astropy/pull/5232#issuecomment-239173872)
779+
data = np.ma.masked_invalid(data)
780+
func = np.ma.median
781+
else:
782+
func = np.nanmedian
771783
else:
772784
func = np.median
773785

0 commit comments

Comments
 (0)