Chris@87: from __future__ import division, absolute_import, print_function Chris@87: Chris@87: import numpy as np Chris@87: from numpy.testing import * Chris@87: from numpy.compat import sixu Chris@87: Chris@87: rlevel = 1 Chris@87: Chris@87: Chris@87: class TestRegression(TestCase): Chris@87: def test_masked_array_create(self,level=rlevel): Chris@87: # Ticket #17 Chris@87: x = np.ma.masked_array([0, 1, 2, 3, 0, 4, 5, 6], Chris@87: mask=[0, 0, 0, 1, 1, 1, 0, 0]) Chris@87: assert_array_equal(np.ma.nonzero(x), [[1, 2, 6, 7]]) Chris@87: Chris@87: def test_masked_array(self,level=rlevel): Chris@87: # Ticket #61 Chris@87: np.ma.array(1, mask=[1]) Chris@87: Chris@87: def test_mem_masked_where(self,level=rlevel): Chris@87: # Ticket #62 Chris@87: from numpy.ma import masked_where, MaskType Chris@87: a = np.zeros((1, 1)) Chris@87: b = np.zeros(a.shape, MaskType) Chris@87: c = masked_where(b, a) Chris@87: a-c Chris@87: Chris@87: def test_masked_array_multiply(self,level=rlevel): Chris@87: # Ticket #254 Chris@87: a = np.ma.zeros((4, 1)) Chris@87: a[2, 0] = np.ma.masked Chris@87: b = np.zeros((4, 2)) Chris@87: a*b Chris@87: b*a Chris@87: Chris@87: def test_masked_array_repeat(self, level=rlevel): Chris@87: # Ticket #271 Chris@87: np.ma.array([1], mask=False).repeat(10) Chris@87: Chris@87: def test_masked_array_repr_unicode(self): Chris@87: # Ticket #1256 Chris@87: repr(np.ma.array(sixu("Unicode"))) Chris@87: Chris@87: def test_atleast_2d(self): Chris@87: # Ticket #1559 Chris@87: a = np.ma.masked_array([0.0, 1.2, 3.5], mask=[False, True, False]) Chris@87: b = np.atleast_2d(a) Chris@87: assert_(a.mask.ndim == 1) Chris@87: assert_(b.mask.ndim == 2) Chris@87: Chris@87: def test_set_fill_value_unicode_py3(self): Chris@87: # Ticket #2733 Chris@87: a = np.ma.masked_array(['a', 'b', 'c'], mask=[1, 0, 0]) Chris@87: a.fill_value = 'X' Chris@87: assert_(a.fill_value == 'X') Chris@87: Chris@87: def test_var_sets_maskedarray_scalar(self): Chris@87: # Issue gh-2757 Chris@87: a = np.ma.array(np.arange(5), mask=True) Chris@87: mout = np.ma.array(-1, dtype=float) Chris@87: a.var(out=mout) Chris@87: assert_(mout._data == 0) Chris@87: Chris@87: def test_ddof_corrcoef(self): Chris@87: # See gh-3336 Chris@87: x = np.ma.masked_equal([1, 2, 3, 4, 5], 4) Chris@87: y = np.array([2, 2.5, 3.1, 3, 5]) Chris@87: r0 = np.ma.corrcoef(x, y, ddof=0) Chris@87: r1 = np.ma.corrcoef(x, y, ddof=1) Chris@87: # ddof should not have an effect (it gets cancelled out) Chris@87: assert_allclose(r0.data, r1.data) Chris@87: Chris@87: if __name__ == "__main__": Chris@87: run_module_suite()