|
10 | 10 | from __future__ import division, absolute_import, print_function
|
11 | 11 |
|
12 | 12 | import warnings
|
| 13 | +import itertools |
13 | 14 |
|
14 | 15 | import numpy as np
|
15 | 16 | from numpy.testing import (
|
@@ -684,6 +685,37 @@ def test_docstring_examples(self):
|
684 | 685 | assert_equal(ma_x.shape, (2,), "shape mismatch")
|
685 | 686 | assert_(type(ma_x) is MaskedArray)
|
686 | 687 |
|
| 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 | + |
687 | 719 | def test_masked_1d(self):
|
688 | 720 | x = array(np.arange(5), mask=True)
|
689 | 721 | assert_equal(np.ma.median(x), np.ma.masked)
|
|
0 commit comments