diff options
author | Michael Seifert <michaelseifert04@yahoo.de> | 2017-02-22 16:50:49 +0100 |
---|---|---|
committer | Michael Seifert <michaelseifert04@yahoo.de> | 2017-02-28 01:11:24 +0100 |
commit | d0bf15d1b99dd239530b25a0d939ee4475f85af5 (patch) | |
tree | 3954c44d0f6035645f601af3a0f7b8debba95608 /numpy | |
parent | e58c6adc591e47675192ecfc584dad54a00cf401 (diff) | |
download | numpy-d0bf15d1b99dd239530b25a0d939ee4475f85af5.tar.gz |
MAINT: Warn users when calling np.ma.MaskedArray.(arg-)partition function.
Using the np.median function on MaskedArrays uses the not-overriden
partition method of a plain np.ndarray without error or warning. (#7330)
This PR overrides the partition method on MaskedArrays but simply to
throw a Warning. This will make users aware that something ignores the
mask without breaking backwards-compatibility. This also applies to
the argpartition method (even if it's not called by np.median).
Diffstat (limited to 'numpy')
-rw-r--r-- | numpy/ma/core.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/numpy/ma/core.py b/numpy/ma/core.py index af8a523ab..ea4a1d85f 100644 --- a/numpy/ma/core.py +++ b/numpy/ma/core.py @@ -5635,6 +5635,18 @@ class MaskedArray(ndarray): np.subtract(out, min_value, out=out, casting='unsafe') return out + def partition(self, *args, **kwargs): + warnings.warn("Warning: 'partition' will ignore the 'mask' " + "of the {}.".format(self.__class__.__name__), + stacklevel=2) + return super(MaskedArray, self).partition(*args, **kwargs) + + def argpartition(self, *args, **kwargs): + warnings.warn("Warning: 'argpartition' will ignore the 'mask' " + "of the {}.".format(self.__class__.__name__), + stacklevel=2) + return super(MaskedArray, self).argpartition(*args, **kwargs) + def take(self, indices, axis=None, out=None, mode='raise'): """ """ |