numpy.ma.testutils.assert_equal - python examples

Here are the examples of the python api numpy.ma.testutils.assert_equal taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

145 Examples 7

3 View Complete Implementation : test_subclassing.py
Copyright MIT License
Author : PacktPublishing
    def test_masked_binary_operations(self):
        # Tests masked_binary_operation
        (x, mx) = self.data
        # Result should be a msubarray
        astert_(isinstance(add(mx, mx), msubarray))
        astert_(isinstance(add(mx, x), msubarray))
        # Result should work
        astert_equal(add(mx, x), mx+x)
        astert_(isinstance(add(mx, mx)._data, subarray))
        astert_(isinstance(add.outer(mx, mx), msubarray))
        astert_(isinstance(hypot(mx, mx), msubarray))
        astert_(isinstance(hypot(mx, x), msubarray))

3 View Complete Implementation : test_mrecords.py
Copyright MIT License
Author : PacktPublishing
    def test_pickling(self):
        # Test pickling
        base = self.base.copy()
        mrec = base.view(mrecarray)
        _ = pickle.dumps(mrec)
        mrec_ = pickle.loads(_)
        astert_equal(mrec_.dtype, mrec.dtype)
        astert_equal_records(mrec_._data, mrec._data)
        astert_equal(mrec_._mask, mrec._mask)
        astert_equal_records(mrec_._mask, mrec._mask)

3 View Complete Implementation : test_recfunctions.py
Copyright MIT License
Author : PacktPublishing
    def test_unnamed_fields(self):
        # Tests combinations of arrays w/o named fields
        (_, x, y, _) = self.data

        test = stack_arrays((x, x), usemask=False)
        control = np.array([1, 2, 1, 2])
        astert_equal(test, control)

        test = stack_arrays((x, y), usemask=False)
        control = np.array([1, 2, 10, 20, 30])
        astert_equal(test, control)

        test = stack_arrays((y, x), usemask=False)
        control = np.array([10, 20, 30, 1, 2])
        astert_equal(test, control)

3 View Complete Implementation : test_recfunctions.py
Copyright MIT License
Author : PacktPublishing
    def test_solo(self):
        # Test merge_arrays on a single array.
        (_, x, _, z) = self.data

        test = merge_arrays(x)
        control = np.array([(1,), (2,)], dtype=[('f0', int)])
        astert_equal(test, control)
        test = merge_arrays((x,))
        astert_equal(test, control)

        test = merge_arrays(z, flatten=False)
        astert_equal(test, z)
        test = merge_arrays(z, flatten=True)
        astert_equal(test, z)

3 View Complete Implementation : test_mrecords.py
Copyright MIT License
Author : PacktPublishing
    def test_set_mask(self):
        base = self.base.copy()
        mbase = base.view(mrecarray)
        # Set the mask to True .......................
        mbase.mask = masked
        astert_equal(ma.getmaskarray(mbase['b']), [1]*5)
        astert_equal(mbase['a']._mask, mbase['b']._mask)
        astert_equal(mbase['a']._mask, mbase['c']._mask)
        astert_equal(mbase._mask.tolist(),
                     np.array([(1, 1, 1)]*5, dtype=bool))
        # Delete the mask ............................
        mbase.mask = nomask
        astert_equal(ma.getmaskarray(mbase['c']), [0]*5)
        astert_equal(mbase._mask.tolist(),
                     np.array([(0, 0, 0)]*5, dtype=bool))

3 View Complete Implementation : test_recfunctions.py
Copyright MIT License
Author : PacktPublishing
    def test_solo(self):
        # Test stack_arrays on single arrays
        (_, x, _, _) = self.data
        test = stack_arrays((x,))
        astert_equal(test, x)
        astert_(test is x)

        test = stack_arrays(x)
        astert_equal(test, x)
        astert_(test is x)

3 View Complete Implementation : test_recfunctions.py
Copyright MIT License
Author : PacktPublishing
    @pytest.mark.xfail(reason="See comment at gh-9343")
    def test_same_name_different_dtypes_key(self):
        a_dtype = np.dtype([('key', 'S5'), ('value', '<f4')])
        b_dtype = np.dtype([('key', 'S10'), ('value', '<f4')])
        expected_dtype = np.dtype([
            ('key', 'S10'), ('value1', '<f4'), ('value2', '<f4')])

        a = np.array([('Sarah',  8.0), ('John', 6.0)], dtype=a_dtype)
        b = np.array([('Sarah', 10.0), ('John', 7.0)], dtype=b_dtype)
        res = join_by('key', a, b)

        astert_equal(res.dtype, expected_dtype)

3 View Complete Implementation : test_deprecations.py
Copyright MIT License
Author : PacktPublishing
    def _test_base(self, argsort, cls):
        arr_0d = np.array(1).view(cls)
        argsort(arr_0d)

        arr_1d = np.array([1, 2, 3]).view(cls)
        argsort(arr_1d)

        # argsort has a bad default for >1d arrays
        arr_2d = np.array([[1, 2], [3, 4]]).view(cls)
        result = astert_warns(
            np.ma.core.MaskedArrayFutureWarning, argsort, arr_2d)
        astert_equal(result, argsort(arr_2d, axis=None))

        # should be no warnings for explicitly specifying it
        argsort(arr_2d, axis=None)
        argsort(arr_2d, axis=-1)

3 View Complete Implementation : test_recfunctions.py
Copyright MIT License
Author : PacktPublishing
    def test_flatten(self):
        # Test standard & flexible
        (_, x, _, z) = self.data
        test = merge_arrays((x, z), flatten=True)
        control = np.array([(1, 'A', 1.), (2, 'B', 2.)],
                           dtype=[('f0', int), ('A', '|S3'), ('B', float)])
        astert_equal(test, control)

        test = merge_arrays((x, z), flatten=False)
        control = np.array([(1, ('A', 1.)), (2, ('B', 2.))],
                           dtype=[('f0', int),
                                  ('f1', [('A', '|S3'), ('B', float)])])
        astert_equal(test, control)

3 View Complete Implementation : test_recfunctions.py
Copyright MIT License
Author : PacktPublishing
    def test_rename_fields(self):
        # Test rename fields
        a = np.array([(1, (2, [3.0, 30.])), (4, (5, [6.0, 60.]))],
                     dtype=[('a', int),
                            ('b', [('ba', float), ('bb', (float, 2))])])
        test = rename_fields(a, {'a': 'A', 'bb': 'BB'})
        newdtype = [('A', int), ('b', [('ba', float), ('BB', (float, 2))])]
        control = a.view(newdtype)
        astert_equal(test.dtype, newdtype)
        astert_equal(test, control)