8000 TST: Add ma.median tests for valid axis. · numpy/numpy@ad5b13a · GitHub
[go: up one dir, main page]

Skip to content

Commit ad5b13a

Browse files
committed
TST: Add ma.median tests for valid axis.
1 parent 66f313f commit ad5b13a

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

numpy/ma/tests/test_extras.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from __future__ import division, absolute_import, print_function
1111

1212
import warnings
13+
import itertools
1314

1415
import numpy as np
1516
from numpy.testing import (
@@ -684,6 +685,37 @@ def test_docstring_examples(self):
684685
assert_equal(ma_x.shape, (2,), "shape mismatch")
685686
assert_(type(ma_x) is MaskedArray)
686687

688+
def test_axis_argument_errors(self):
689+
msg = "mask = %s, ndim = %s, axis = %s, overwrite_input = %s"
690+
for ndmin in range(5):
691+
for mask in [False, True]:
692+
x = array(1, ndmin=ndmin, mask=mask)
693+
694+
# Valid axis values should not raise exception
695+
args = itertools.product(range(-ndmin, ndmin), [False, True])
696+
for axis, over in args:
697+
try:
698+
np.ma.median(x, axis=axis, overwrite_input=over)
699+
except:
700+
raise AssertionError(msg % (mask, ndmin, axis, over))
701+
702+
# Invalid axis values should raise exception
703+
args = itertools.product([-(ndmin + 1), ndmin], [False, True])
704+
for axis, over in args:
705+
try:
706+
np.ma.median(x, axis=axis, overwrite_input=over)
707+
except IndexError:
708+
pass
709+
else:
710+
raise AssertionError(msg % (mask, ndmin, axis, over))
711+
712+
def test_masked_0d(self):
713+
# Check values
714+
x = array(1, mask=False)
715+
assert_equal(np.ma.median(x), 1)
716+
x = array(1, mask=True)
717+
assert_equal(np.ma.median(x), np.ma.masked)
718+
687719
def test_masked_1d(self):
688720
x = array(np.arange(5), mask=True)
689721
assert_equal(np.ma.median(x), np.ma.masked)

0 commit comments

Comments
 (0)
0