Chris@87
|
1 from __future__ import division, absolute_import, print_function
|
Chris@87
|
2
|
Chris@87
|
3 import numpy as np
|
Chris@87
|
4 from numpy.testing import *
|
Chris@87
|
5 from numpy.compat import sixu
|
Chris@87
|
6
|
Chris@87
|
7 rlevel = 1
|
Chris@87
|
8
|
Chris@87
|
9
|
Chris@87
|
10 class TestRegression(TestCase):
|
Chris@87
|
11 def test_masked_array_create(self,level=rlevel):
|
Chris@87
|
12 # Ticket #17
|
Chris@87
|
13 x = np.ma.masked_array([0, 1, 2, 3, 0, 4, 5, 6],
|
Chris@87
|
14 mask=[0, 0, 0, 1, 1, 1, 0, 0])
|
Chris@87
|
15 assert_array_equal(np.ma.nonzero(x), [[1, 2, 6, 7]])
|
Chris@87
|
16
|
Chris@87
|
17 def test_masked_array(self,level=rlevel):
|
Chris@87
|
18 # Ticket #61
|
Chris@87
|
19 np.ma.array(1, mask=[1])
|
Chris@87
|
20
|
Chris@87
|
21 def test_mem_masked_where(self,level=rlevel):
|
Chris@87
|
22 # Ticket #62
|
Chris@87
|
23 from numpy.ma import masked_where, MaskType
|
Chris@87
|
24 a = np.zeros((1, 1))
|
Chris@87
|
25 b = np.zeros(a.shape, MaskType)
|
Chris@87
|
26 c = masked_where(b, a)
|
Chris@87
|
27 a-c
|
Chris@87
|
28
|
Chris@87
|
29 def test_masked_array_multiply(self,level=rlevel):
|
Chris@87
|
30 # Ticket #254
|
Chris@87
|
31 a = np.ma.zeros((4, 1))
|
Chris@87
|
32 a[2, 0] = np.ma.masked
|
Chris@87
|
33 b = np.zeros((4, 2))
|
Chris@87
|
34 a*b
|
Chris@87
|
35 b*a
|
Chris@87
|
36
|
Chris@87
|
37 def test_masked_array_repeat(self, level=rlevel):
|
Chris@87
|
38 # Ticket #271
|
Chris@87
|
39 np.ma.array([1], mask=False).repeat(10)
|
Chris@87
|
40
|
Chris@87
|
41 def test_masked_array_repr_unicode(self):
|
Chris@87
|
42 # Ticket #1256
|
Chris@87
|
43 repr(np.ma.array(sixu("Unicode")))
|
Chris@87
|
44
|
Chris@87
|
45 def test_atleast_2d(self):
|
Chris@87
|
46 # Ticket #1559
|
Chris@87
|
47 a = np.ma.masked_array([0.0, 1.2, 3.5], mask=[False, True, False])
|
Chris@87
|
48 b = np.atleast_2d(a)
|
Chris@87
|
49 assert_(a.mask.ndim == 1)
|
Chris@87
|
50 assert_(b.mask.ndim == 2)
|
Chris@87
|
51
|
Chris@87
|
52 def test_set_fill_value_unicode_py3(self):
|
Chris@87
|
53 # Ticket #2733
|
Chris@87
|
54 a = np.ma.masked_array(['a', 'b', 'c'], mask=[1, 0, 0])
|
Chris@87
|
55 a.fill_value = 'X'
|
Chris@87
|
56 assert_(a.fill_value == 'X')
|
Chris@87
|
57
|
Chris@87
|
58 def test_var_sets_maskedarray_scalar(self):
|
Chris@87
|
59 # Issue gh-2757
|
Chris@87
|
60 a = np.ma.array(np.arange(5), mask=True)
|
Chris@87
|
61 mout = np.ma.array(-1, dtype=float)
|
Chris@87
|
62 a.var(out=mout)
|
Chris@87
|
63 assert_(mout._data == 0)
|
Chris@87
|
64
|
Chris@87
|
65 def test_ddof_corrcoef(self):
|
Chris@87
|
66 # See gh-3336
|
Chris@87
|
67 x = np.ma.masked_equal([1, 2, 3, 4, 5], 4)
|
Chris@87
|
68 y = np.array([2, 2.5, 3.1, 3, 5])
|
Chris@87
|
69 r0 = np.ma.corrcoef(x, y, ddof=0)
|
Chris@87
|
70 r1 = np.ma.corrcoef(x, y, ddof=1)
|
Chris@87
|
71 # ddof should not have an effect (it gets cancelled out)
|
Chris@87
|
72 assert_allclose(r0.data, r1.data)
|
Chris@87
|
73
|
Chris@87
|
74 if __name__ == "__main__":
|
Chris@87
|
75 run_module_suite()
|