def test_nd(self): array_a = np.array(np.arange(24).reshape(2, 3, 4)) array_b = np.array(np.arange(24).reshape(2, 3, 4)) array_c = np.array(np.arange(24).reshape(2, 3, 4)) array_c[0, 1, 2] = 100 self.assertTrue(array_equal(array_a, array_b)) self.assertFalse(array_equal(array_a, array_c))
def test_string_arrays_unequal_dimensionality(self): array_a = np.array('abc') array_b = np.array(['abc']) array_c = np.array([['abc']]) self.assertFalse(array_equal(array_a, array_b)) self.assertFalse(array_equal(array_b, array_a)) self.assertFalse(array_equal(array_a, array_c)) self.assertFalse(array_equal(array_b, array_c))
def test_1d_and_sequences(self): for sequence_type in (list, tuple): seq_a = sequence_type([1, 2, 3]) array_a = np.array(seq_a) self.assertTrue(array_equal(array_a, seq_a)) self.assertFalse(array_equal(array_a, seq_a[:-1])) array_a[1] = 45 self.assertFalse(array_equal(array_a, seq_a))
def __eq__(self, other): """ Perform :class:`~iris._data_manager.DataManager` instance equality. Note that, this is explicitly not a lazy operation and will load any lazy payload to determine the equality result. Comparison is strict with regards to lazy or real managed payload, the realised_dtype, the dtype of the payload, the fill-value and the payload content. Args: * other: The :class:`~iris._data_manager.DataManager` instance to compare with. Returns: Boolean. """ result = NotImplemented if isinstance(other, type(self)): result = False same_lazy = self.has_lazy_data() == other.has_lazy_data() same_fill_value = self.fill_value == other.fill_value same_realised_dtype = self._realised_dtype == other._realised_dtype same_dtype = self.dtype == other.dtype if same_lazy and same_fill_value and same_realised_dtype \ and same_dtype: result = array_equal(self.core_data(), other.core_data()) return result
def __eq__(self, other): """ Perform :class:`~iris._data_manager.DataManager` instance equality. Note that, this is explicitly not a lazy operation and will load any lazy payload to determine the equality result. Comparison is strict with regards to lazy or real managed payload, the realised_dtype, the dtype of the payload, the fill-value and the payload content. Args: * other: The :class:`~iris._data_manager.DataManager` instance to compare with. Returns: Boolean. """ result = NotImplemented if isinstance(other, type(self)): result = False same_lazy = self.has_lazy_data() == other.has_lazy_data() same_dtype = self.dtype == other.dtype if same_lazy and same_dtype: result = array_equal(self.core_data(), other.core_data()) return result
def _cmp(coord, other): """ Compare the coordinates for concatenation compatibility. Returns: A boolean tuple pair of whether the coordinates are compatible, and whether they represent a candidate axis of concatenation. """ # A candidate axis must have non-identical coordinate points. candidate_axis = not array_equal(coord.points, other.points) if candidate_axis: # Ensure both have equal availability of bounds. result = (coord.bounds is None) == (other.bounds is None) else: if coord.bounds is not None and other.bounds is not None: # Ensure equality of bounds. result = array_equal(coord.bounds, other.bounds) else: # Ensure both have equal availability of bounds. result = coord.bounds is None and other.bounds is None return result, candidate_axis
def test_string_arrays_equal(self): array_a = np.array(['abc', 'def', 'efg']) array_b = np.array(['abc', 'def', 'efg']) self.assertTrue(array_equal(array_a, array_b))
def test_partially_masked_string_arrays(self): array_a = np.ma.masked_array(['a', 'b', 'c'], mask=[1, 0, 1]) array_b = np.ma.masked_array(['a', 'b', 'c'], mask=[1, 0, 1]) self.assertTrue(array_equal(array_a, array_b))
def test_fully_masked_0d_arrays(self): array_a = np.ma.masked_array(3, mask=True) array_b = np.ma.masked_array(3, mask=True) self.assertTrue(array_equal(array_a, array_b))
def test_fully_masked_arrays(self): array_a = np.ma.masked_array(np.arange(24).reshape(2, 3, 4), mask=True) array_b = np.ma.masked_array(np.arange(24).reshape(2, 3, 4), mask=True) self.assertTrue(array_equal(array_a, array_b))
def test_string_arrays_equal(self): array_a = np.array(["abc", "def", "efg"]) array_b = np.array(["abc", "def", "efg"]) self.assertTrue(array_equal(array_a, array_b))
def test_fully_masked_string_arrays(self): array_a = ma.masked_array(['a', 'b', 'c'], mask=True) array_b = ma.masked_array(['a', 'b', 'c'], mask=[1, 1, 1]) self.assertTrue(array_equal(array_a, array_b))
def test_nan_equality_nan_ne_nan(self): array = np.array([1.0, np.nan, 2.0, np.nan, 3.0]) self.assertFalse(array_equal(array, array))
def test_string_arrays_0d_and_scalar(self): array_a = np.array('foobar') self.assertTrue(array_equal(array_a, 'foobar')) self.assertFalse(array_equal(array_a, 'foo')) self.assertFalse(array_equal(array_a, 'foobar.'))
def test_0d(self): array_a = np.array(23) array_b = np.array(23) array_c = np.array(7) self.assertTrue(array_equal(array_a, array_b)) self.assertFalse(array_equal(array_a, array_c))
def test_string_arrays_0d_and_scalar(self): array_a = np.array("foobar") self.assertTrue(array_equal(array_a, "foobar")) self.assertFalse(array_equal(array_a, "foo")) self.assertFalse(array_equal(array_a, "foobar."))
def test_string_arrays_subset(self): array_a = np.array(["abc", "def", "efg"]) array_b = np.array(["abc", "def"]) self.assertFalse(array_equal(array_a, array_b)) self.assertFalse(array_equal(array_b, array_a))
def test_string_arrays_different_contents(self): array_a = np.array(["abc", "def", "efg"]) array_b = np.array(["abc", "de", "efg"]) self.assertFalse(array_equal(array_a, array_b))
def test_string_arrays_different_contents(self): array_a = np.array(['abc', 'def', 'efg']) array_b = np.array(['abc', 'de', 'efg']) self.assertFalse(array_equal(array_a, array_b))
def test_nan_equality_a_nanne_b(self): array_a = np.array([1.0, np.nan, 2.0, np.nan, 3.0]) array_b = np.array([1.0, np.nan, 2.0, np.nan, 4.0]) self.assertFalse(array_equal(array_a, array_b, withnans=True))
def test_string_arrays_subset(self): array_a = np.array(['abc', 'def', 'efg']) array_b = np.array(['abc', 'def']) self.assertFalse(array_equal(array_a, array_b)) self.assertFalse(array_equal(array_b, array_a))
def test_nan_equality_nan_naneq_nan(self): array_a = np.array([1.0, np.nan, 2.0, np.nan, 3.0]) array_b = np.array([1.0, np.nan, 2.0, np.nan, 3.0]) self.assertTrue(array_equal(array_a, array_b, withnans=True))
def test_masked_is_ignored(self): array_a = np.ma.masked_array([1, 2, 3], mask=[1, 0, 1]) array_b = np.ma.masked_array([2, 2, 2], mask=[1, 0, 1]) self.assertFalse(array_equal(array_a, array_b))
def test_0d_and_scalar(self): array_a = np.array(23) self.assertTrue(array_equal(array_a, 23)) self.assertFalse(array_equal(array_a, 45))
def test_partially_masked_string_arrays(self): array_a = ma.masked_array(["a", "b", "c"], mask=[1, 0, 1]) array_b = ma.masked_array(["a", "b", "c"], mask=[1, 0, 1]) self.assertTrue(array_equal(array_a, array_b))