def test_dual_argument_operation(self): exponent = 2 expected = self.masked_array ** exponent actual = Elementwise(self.masked_array, exponent, np.power, ma.power) result = actual.masked_array() assert_array_equal(result.mask, self.mask) assert_array_equal(result, expected)
def test_dual_argument_operation(self): exponent = 2 expected = self.masked_array**exponent actual = Elementwise(self.masked_array, exponent, np.power, ma.power) result = actual.masked_array() assert_array_equal(result.mask, self.mask) assert_array_equal(result, expected)
def test_partial_function(self): clip_between = partial(np.clip, a_min=1, a_max=4) self._test(clip_between) array = np.arange(10000, dtype=np.float32) actual = Elementwise(array, None, clip_between) assert_array_equal(actual.ndarray(), clip_between(array)) self.assertEqual(actual.ndarray().max(), 4)
def test_no_masked_array_function(self): result = Elementwise(self.masked_array, None, np.sign) msg = 'No sign operation defined for masked arrays' with self.assertRaisesRegexp(TypeError, msg): result.masked_array()
def test_single_argument_operation(self): expected = np.abs(self.masked_array) actual = Elementwise(self.masked_array, None, np.abs, ma.abs) result = actual.masked_array() assert_array_equal(result.mask, self.mask) assert_array_equal(result, expected)