Python numpy.compat.sixu() Examples

The following are code examples for showing how to use numpy.compat.sixu(). They are from open source Python projects. You can vote up the examples you like or vote down the ones you don't like.

Example 1
Project: LaserTOF   Author: kyleuckert   File: test_defchararray.py    MIT License 6 votes vote down vote up
def test_from_unicode_array(self):
        A = np.array([['abc', sixu('Sigma \u03a3')],
                      ['long   ', '0123456789']])
        assert_equal(A.dtype.type, np.unicode_)
        B = np.char.array(A)
        assert_array_equal(B, A)
        assert_equal(B.dtype, A.dtype)
        assert_equal(B.shape, A.shape)
        B = np.char.array(A, **kw_unicode_true)
        assert_array_equal(B, A)
        assert_equal(B.dtype, A.dtype)
        assert_equal(B.shape, A.shape)

        def fail():
            np.char.array(A, **kw_unicode_false)

        self.assertRaises(UnicodeEncodeError, fail) 
Example 2
Project: LaserTOF   Author: kyleuckert   File: test_defchararray.py    MIT License 6 votes vote down vote up
def test_lstrip(self):
        tgt = asbytes_nested([['abc ', ''],
                              ['12345', 'MixedCase'],
                              ['123 \t 345 \0 ', 'UPPER']])
        assert_(issubclass(self.A.lstrip().dtype.type, np.string_))
        assert_array_equal(self.A.lstrip(), tgt)

        tgt = asbytes_nested([[' abc', ''],
                              ['2345', 'ixedCase'],
                              ['23 \t 345 \x00', 'UPPER']])
        assert_array_equal(self.A.lstrip(asbytes_nested(['1', 'M'])), tgt)

        tgt = [[sixu('\u03a3 '), ''],
               ['12345', 'MixedCase'],
               ['123 \t 345 \0 ', 'UPPER']]
        assert_(issubclass(self.B.lstrip().dtype.type, np.unicode_))
        assert_array_equal(self.B.lstrip(), tgt) 
Example 3
Project: LaserTOF   Author: kyleuckert   File: test_defchararray.py    MIT License 6 votes vote down vote up
def test_replace(self):
        R = self.A.replace(asbytes_nested(['3', 'a']),
                           asbytes_nested(['##########', '@']))
        tgt = asbytes_nested([[' abc ', ''],
                              ['12##########45', '[email protected]'],
                              ['12########## \t ##########45 \x00', 'UPPER']])
        assert_(issubclass(R.dtype.type, np.string_))
        assert_array_equal(R, tgt)

        if sys.version_info[0] < 3:
            # NOTE: b'abc'.replace(b'a', 'b') is not allowed on Py3
            R = self.A.replace(asbytes('a'), sixu('\u03a3'))
            tgt = [[sixu(' \u03a3bc '), ''],
                   ['12345', sixu('MixedC\u03a3se')],
                   ['123 \t 345 \x00', 'UPPER']]
            assert_(issubclass(R.dtype.type, np.unicode_))
            assert_array_equal(R, tgt) 
Example 4
Project: LaserTOF   Author: kyleuckert   File: test_defchararray.py    MIT License 6 votes vote down vote up
def test_rstrip(self):
        assert_(issubclass(self.A.rstrip().dtype.type, np.string_))

        tgt = asbytes_nested([[' abc', ''],
                              ['12345', 'MixedCase'],
                              ['123 \t 345', 'UPPER']])
        assert_array_equal(self.A.rstrip(), tgt)

        tgt = asbytes_nested([[' abc ', ''],
                              ['1234', 'MixedCase'],
                              ['123 \t 345 \x00', 'UPP']
                              ])
        assert_array_equal(self.A.rstrip(asbytes_nested(['5', 'ER'])), tgt)

        tgt = [[sixu(' \u03a3'), ''],
               ['12345', 'MixedCase'],
               ['123 \t 345', 'UPPER']]
        assert_(issubclass(self.B.rstrip().dtype.type, np.unicode_))
        assert_array_equal(self.B.rstrip(), tgt) 
Example 5
Project: LaserTOF   Author: kyleuckert   File: test_defchararray.py    MIT License 6 votes vote down vote up
def test_strip(self):
        tgt = asbytes_nested([['abc', ''],
                              ['12345', 'MixedCase'],
                              ['123 \t 345', 'UPPER']])
        assert_(issubclass(self.A.strip().dtype.type, np.string_))
        assert_array_equal(self.A.strip(), tgt)

        tgt = asbytes_nested([[' abc ', ''],
                              ['234', 'ixedCas'],
                              ['23 \t 345 \x00', 'UPP']])
        assert_array_equal(self.A.strip(asbytes_nested(['15', 'EReM'])), tgt)

        tgt = [[sixu('\u03a3'), ''],
               ['12345', 'MixedCase'],
               ['123 \t 345', 'UPPER']]
        assert_(issubclass(self.B.strip().dtype.type, np.unicode_))
        assert_array_equal(self.B.strip(), tgt) 
Example 6
Project: LaserTOF   Author: kyleuckert   File: test_nditer.py    MIT License 6 votes vote down vote up
def test_iter_buffering_string():
    # Safe casting disallows shrinking strings
    a = np.array(['abc', 'a', 'abcd'], dtype=np.bytes_)
    assert_equal(a.dtype, np.dtype('S4'))
    assert_raises(TypeError, nditer, a, ['buffered'], ['readonly'],
                  op_dtypes='S2')
    i = nditer(a, ['buffered'], ['readonly'], op_dtypes='S6')
    assert_equal(i[0], asbytes('abc'))
    assert_equal(i[0].dtype, np.dtype('S6'))

    a = np.array(['abc', 'a', 'abcd'], dtype=np.unicode)
    assert_equal(a.dtype, np.dtype('U4'))
    assert_raises(TypeError, nditer, a, ['buffered'], ['readonly'],
                    op_dtypes='U2')
    i = nditer(a, ['buffered'], ['readonly'], op_dtypes='U6')
    assert_equal(i[0], sixu('abc'))
    assert_equal(i[0].dtype, np.dtype('U6')) 
Example 7
Project: att   Author: Centre-Alt-Rendiment-Esportiu   File: test_defchararray.py    GNU General Public License v3.0 6 votes vote down vote up
def test_lstrip(self):
        assert_(issubclass(self.A.lstrip().dtype.type, np.string_))
        assert_array_equal(self.A.lstrip(), asbytes_nested([
                ['abc ', ''],
                ['12345', 'MixedCase'],
                ['123 \t 345 \0 ', 'UPPER']]))
        assert_array_equal(self.A.lstrip(asbytes_nested(['1', 'M'])),
                           asbytes_nested([
                [' abc', ''],
                ['2345', 'ixedCase'],
                ['23 \t 345 \x00', 'UPPER']]))
        assert_(issubclass(self.B.lstrip().dtype.type, np.unicode_))
        assert_array_equal(self.B.lstrip(), [
                [sixu('\u03a3 '), ''],
                ['12345', 'MixedCase'],
                ['123 \t 345 \0 ', 'UPPER']]) 
Example 8
Project: att   Author: Centre-Alt-Rendiment-Esportiu   File: test_defchararray.py    GNU General Public License v3.0 6 votes vote down vote up
def test_replace(self):
        R = self.A.replace(asbytes_nested(['3', 'a']),
                           asbytes_nested(['##########', '@']))
        assert_(issubclass(R.dtype.type, np.string_))
        assert_array_equal(R, asbytes_nested([
                [' abc ', ''],
                ['12##########45', '[email protected]'],
                ['12########## \t ##########45 \x00', 'UPPER']]))

        if sys.version_info[0] < 3:
            # NOTE: b'abc'.replace(b'a', 'b') is not allowed on Py3
            R = self.A.replace(asbytes('a'), sixu('\u03a3'))
            assert_(issubclass(R.dtype.type, np.unicode_))
            assert_array_equal(R, [
                    [sixu(' \u03a3bc '), ''],
                    ['12345', sixu('MixedC\u03a3se')],
                    ['123 \t 345 \x00', 'UPPER']]) 
Example 9
Project: att   Author: Centre-Alt-Rendiment-Esportiu   File: test_defchararray.py    GNU General Public License v3.0 6 votes vote down vote up
def test_rstrip(self):
        assert_(issubclass(self.A.rstrip().dtype.type, np.string_))
        assert_array_equal(self.A.rstrip(), asbytes_nested([
                [' abc', ''],
                ['12345', 'MixedCase'],
                ['123 \t 345', 'UPPER']]))
        assert_array_equal(self.A.rstrip(asbytes_nested(['5', 'ER'])),
                           asbytes_nested([
                [' abc ', ''],
                ['1234', 'MixedCase'],
                ['123 \t 345 \x00', 'UPP']]))
        assert_(issubclass(self.B.rstrip().dtype.type, np.unicode_))
        assert_array_equal(self.B.rstrip(), [
                [sixu(' \u03a3'), ''],
                ['12345', 'MixedCase'],
                ['123 \t 345', 'UPPER']]) 
Example 10
Project: att   Author: Centre-Alt-Rendiment-Esportiu   File: test_defchararray.py    GNU General Public License v3.0 6 votes vote down vote up
def test_strip(self):
        assert_(issubclass(self.A.strip().dtype.type, np.string_))
        assert_array_equal(self.A.strip(), asbytes_nested([
                ['abc', ''],
                ['12345', 'MixedCase'],
                ['123 \t 345', 'UPPER']]))
        assert_array_equal(self.A.strip(asbytes_nested(['15', 'EReM'])),
                           asbytes_nested([
                [' abc ', ''],
                ['234', 'ixedCas'],
                ['23 \t 345 \x00', 'UPP']]))
        assert_(issubclass(self.B.strip().dtype.type, np.unicode_))
        assert_array_equal(self.B.strip(), [
                [sixu('\u03a3'), ''],
                ['12345', 'MixedCase'],
                ['123 \t 345', 'UPPER']]) 
Example 11
Project: att   Author: Centre-Alt-Rendiment-Esportiu   File: test_nditer.py    GNU General Public License v3.0 6 votes vote down vote up
def test_iter_buffering_string():
    # Safe casting disallows shrinking strings
    a = np.array(['abc', 'a', 'abcd'], dtype=np.bytes_)
    assert_equal(a.dtype, np.dtype('S4'));
    assert_raises(TypeError, nditer, a, ['buffered'], ['readonly'],
                    op_dtypes='S2')
    i = nditer(a, ['buffered'], ['readonly'], op_dtypes='S6')
    assert_equal(i[0], asbytes('abc'))
    assert_equal(i[0].dtype, np.dtype('S6'))

    a = np.array(['abc', 'a', 'abcd'], dtype=np.unicode)
    assert_equal(a.dtype, np.dtype('U4'));
    assert_raises(TypeError, nditer, a, ['buffered'], ['readonly'],
                    op_dtypes='U2')
    i = nditer(a, ['buffered'], ['readonly'], op_dtypes='U6')
    assert_equal(i[0], sixu('abc'))
    assert_equal(i[0].dtype, np.dtype('U6')) 
Example 12
Project: auto-alt-text-lambda-api   Author: abhisuri97   File: test_defchararray.py    MIT License 6 votes vote down vote up
def test_from_unicode_array(self):
        A = np.array([['abc', sixu('Sigma \u03a3')],
                      ['long   ', '0123456789']])
        assert_equal(A.dtype.type, np.unicode_)
        B = np.char.array(A)
        assert_array_equal(B, A)
        assert_equal(B.dtype, A.dtype)
        assert_equal(B.shape, A.shape)
        B = np.char.array(A, **kw_unicode_true)
        assert_array_equal(B, A)
        assert_equal(B.dtype, A.dtype)
        assert_equal(B.shape, A.shape)

        def fail():
            np.char.array(A, **kw_unicode_false)

        self.assertRaises(UnicodeEncodeError, fail) 
Example 13
Project: auto-alt-text-lambda-api   Author: abhisuri97   File: test_defchararray.py    MIT License 6 votes vote down vote up
def test_lstrip(self):
        tgt = asbytes_nested([['abc ', ''],
                              ['12345', 'MixedCase'],
                              ['123 \t 345 \0 ', 'UPPER']])
        assert_(issubclass(self.A.lstrip().dtype.type, np.string_))
        assert_array_equal(self.A.lstrip(), tgt)

        tgt = asbytes_nested([[' abc', ''],
                              ['2345', 'ixedCase'],
                              ['23 \t 345 \x00', 'UPPER']])
        assert_array_equal(self.A.lstrip(asbytes_nested(['1', 'M'])), tgt)

        tgt = [[sixu('\u03a3 '), ''],
               ['12345', 'MixedCase'],
               ['123 \t 345 \0 ', 'UPPER']]
        assert_(issubclass(self.B.lstrip().dtype.type, np.unicode_))
        assert_array_equal(self.B.lstrip(), tgt) 
Example 14
Project: auto-alt-text-lambda-api   Author: abhisuri97   File: test_defchararray.py    MIT License 6 votes vote down vote up
def test_replace(self):
        R = self.A.replace(asbytes_nested(['3', 'a']),
                           asbytes_nested(['##########', '@']))
        tgt = asbytes_nested([[' abc ', ''],
                              ['12##########45', '[email protected]'],
                              ['12########## \t ##########45 \x00', 'UPPER']])
        assert_(issubclass(R.dtype.type, np.string_))
        assert_array_equal(R, tgt)

        if sys.version_info[0] < 3:
            # NOTE: b'abc'.replace(b'a', 'b') is not allowed on Py3
            R = self.A.replace(asbytes('a'), sixu('\u03a3'))
            tgt = [[sixu(' \u03a3bc '), ''],
                   ['12345', sixu('MixedC\u03a3se')],
                   ['123 \t 345 \x00', 'UPPER']]
            assert_(issubclass(R.dtype.type, np.unicode_))
            assert_array_equal(R, tgt) 
Example 15
Project: auto-alt-text-lambda-api   Author: abhisuri97   File: test_defchararray.py    MIT License 6 votes vote down vote up
def test_rstrip(self):
        assert_(issubclass(self.A.rstrip().dtype.type, np.string_))

        tgt = asbytes_nested([[' abc', ''],
                              ['12345', 'MixedCase'],
                              ['123 \t 345', 'UPPER']])
        assert_array_equal(self.A.rstrip(), tgt)

        tgt = asbytes_nested([[' abc ', ''],
                              ['1234', 'MixedCase'],
                              ['123 \t 345 \x00', 'UPP']
                              ])
        assert_array_equal(self.A.rstrip(asbytes_nested(['5', 'ER'])), tgt)

        tgt = [[sixu(' \u03a3'), ''],
               ['12345', 'MixedCase'],
               ['123 \t 345', 'UPPER']]
        assert_(issubclass(self.B.rstrip().dtype.type, np.unicode_))
        assert_array_equal(self.B.rstrip(), tgt) 
Example 16
Project: auto-alt-text-lambda-api   Author: abhisuri97   File: test_nditer.py    MIT License 6 votes vote down vote up
def test_iter_buffering_string():
    # Safe casting disallows shrinking strings
    a = np.array(['abc', 'a', 'abcd'], dtype=np.bytes_)
    assert_equal(a.dtype, np.dtype('S4'))
    assert_raises(TypeError, nditer, a, ['buffered'], ['readonly'],
                  op_dtypes='S2')
    i = nditer(a, ['buffered'], ['readonly'], op_dtypes='S6')
    assert_equal(i[0], asbytes('abc'))
    assert_equal(i[0].dtype, np.dtype('S6'))

    a = np.array(['abc', 'a', 'abcd'], dtype=np.unicode)
    assert_equal(a.dtype, np.dtype('U4'))
    assert_raises(TypeError, nditer, a, ['buffered'], ['readonly'],
                    op_dtypes='U2')
    i = nditer(a, ['buffered'], ['readonly'], op_dtypes='U6')
    assert_equal(i[0], sixu('abc'))
    assert_equal(i[0].dtype, np.dtype('U6')) 
Example 17
Project: LaserTOF   Author: kyleuckert   File: test_regression.py    MIT License 5 votes vote down vote up
def test_masked_array_repr_unicode(self):
        # Ticket #1256
        repr(np.ma.array(sixu("Unicode"))) 
Example 18
Project: LaserTOF   Author: kyleuckert   File: test_arrayprint.py    MIT License 5 votes vote down vote up
def test_unicode_object_array():
    import sys
    if sys.version_info[0] >= 3:
        expected = "array(['é'], dtype=object)"
    else:
        expected = "array([u'\\xe9'], dtype=object)"
    x = np.array([sixu('\xe9')], dtype=object)
    assert_equal(repr(x), expected) 
Example 19
Project: LaserTOF   Author: kyleuckert   File: test_multiarray.py    MIT License 5 votes vote down vote up
def test_unicode(self):
        g1 = np.array([sixu("This"), sixu("is"), sixu("example")])
        g2 = np.array([sixu("This"), sixu("was"), sixu("example")])
        assert_array_equal(g1 == g2, [g1[i] == g2[i] for i in [0, 1, 2]])
        assert_array_equal(g1 != g2, [g1[i] != g2[i] for i in [0, 1, 2]])
        assert_array_equal(g1 <= g2, [g1[i] <= g2[i] for i in [0, 1, 2]])
        assert_array_equal(g1 >= g2, [g1[i] >= g2[i] for i in [0, 1, 2]])
        assert_array_equal(g1 < g2,  [g1[i] < g2[i] for i in [0, 1, 2]])
        assert_array_equal(g1 > g2,  [g1[i] > g2[i] for i in [0, 1, 2]]) 
Example 20
Project: LaserTOF   Author: kyleuckert   File: test_unicode.py    MIT License 5 votes vote down vote up
def content_check(self, ua, ua_scalar, nbytes):

        # Check the length of the unicode base type
        self.assertTrue(int(ua.dtype.str[2:]) == self.ulen)
        # Check the length of the data buffer
        self.assertTrue(buffer_length(ua) == nbytes)
        # Small check that data in array element is ok
        self.assertTrue(ua_scalar == sixu(''))
        # Encode to ascii and double check
        self.assertTrue(ua_scalar.encode('ascii') == asbytes(''))
        # Check buffer lengths for scalars
        if ucs4:
            self.assertTrue(buffer_length(ua_scalar) == 0)
        else:
            self.assertTrue(buffer_length(ua_scalar) == 0) 
Example 21
Project: LaserTOF   Author: kyleuckert   File: test_longdouble.py    MIT License 5 votes vote down vote up
def test_unicode():
    np.longdouble(sixu("1.2")) 
Example 22
Project: LaserTOF   Author: kyleuckert   File: test_defchararray.py    MIT License 5 votes vote down vote up
def test_unicode_upconvert(self):
        A = np.char.array(['abc'])
        B = np.char.array([sixu('\u03a3')])
        assert_(issubclass((A + B).dtype.type, np.unicode_)) 
Example 23
Project: LaserTOF   Author: kyleuckert   File: test_defchararray.py    MIT License 5 votes vote down vote up
def test_from_unicode(self):
        A = np.char.array(sixu('\u03a3'))
        assert_equal(len(A), 1)
        assert_equal(len(A[0]), 1)
        assert_equal(A.itemsize, 4)
        assert_(issubclass(A.dtype.type, np.unicode_)) 
Example 24
Project: LaserTOF   Author: kyleuckert   File: test_defchararray.py    MIT License 5 votes vote down vote up
def setUp(self):
        self.A = np.array([[' abc ', ''],
                           ['12345', 'MixedCase'],
                           ['123 \t 345 \0 ', 'UPPER']]).view(np.chararray)
        self.B = np.array([[sixu(' \u03a3 '), sixu('')],
                           [sixu('12345'), sixu('MixedCase')],
                           [sixu('123 \t 345 \0 '), sixu('UPPER')]]).view(np.chararray) 
Example 25
Project: LaserTOF   Author: kyleuckert   File: test_defchararray.py    MIT License 5 votes vote down vote up
def setUp(self):
        self.A = np.array([[' abc ', ''],
                           ['12345', 'MixedCase'],
                           ['123 \t 345 \0 ', 'UPPER']],
                          dtype='S').view(np.chararray)
        self.B = np.array([[sixu(' \u03a3 '), sixu('')],
                           [sixu('12345'), sixu('MixedCase')],
                           [sixu('123 \t 345 \0 '), sixu('UPPER')]]).view(np.chararray) 
Example 26
Project: LaserTOF   Author: kyleuckert   File: test_defchararray.py    MIT License 5 votes vote down vote up
def test_lower(self):
        tgt = asbytes_nested([[' abc ', ''],
                              ['12345', 'mixedcase'],
                              ['123 \t 345 \0 ', 'upper']])
        assert_(issubclass(self.A.lower().dtype.type, np.string_))
        assert_array_equal(self.A.lower(), tgt)

        tgt = [[sixu(' \u03c3 '), sixu('')],
               [sixu('12345'), sixu('mixedcase')],
               [sixu('123 \t 345 \0 '), sixu('upper')]]
        assert_(issubclass(self.B.lower().dtype.type, np.unicode_))
        assert_array_equal(self.B.lower(), tgt) 
Example 27
Project: LaserTOF   Author: kyleuckert   File: test_defchararray.py    MIT License 5 votes vote down vote up
def test_title(self):
        tgt = asbytes_nested([[' Abc ', ''],
                              ['12345', 'Mixedcase'],
                              ['123 \t 345 \0 ', 'Upper']])
        assert_(issubclass(self.A.title().dtype.type, np.string_))
        assert_array_equal(self.A.title(), tgt)

        tgt = [[sixu(' \u03a3 '), sixu('')],
               [sixu('12345'), sixu('Mixedcase')],
               [sixu('123 \t 345 \0 '), sixu('Upper')]]
        assert_(issubclass(self.B.title().dtype.type, np.unicode_))
        assert_array_equal(self.B.title(), tgt) 
Example 28
Project: LaserTOF   Author: kyleuckert   File: test_defchararray.py    MIT License 5 votes vote down vote up
def test_upper(self):
        tgt = asbytes_nested([[' ABC ', ''],
                              ['12345', 'MIXEDCASE'],
                              ['123 \t 345 \0 ', 'UPPER']])
        assert_(issubclass(self.A.upper().dtype.type, np.string_))
        assert_array_equal(self.A.upper(), tgt)

        tgt = [[sixu(' \u03a3 '), sixu('')],
               [sixu('12345'), sixu('MIXEDCASE')],
               [sixu('123 \t 345 \0 '), sixu('UPPER')]]
        assert_(issubclass(self.B.upper().dtype.type, np.unicode_))
        assert_array_equal(self.B.upper(), tgt) 
Example 29
Project: LaserTOF   Author: kyleuckert   File: test_regression.py    MIT License 5 votes vote down vote up
def test_unicode_swapping(self, level=rlevel):
        # Ticket #79
        ulen = 1
        ucs_value = sixu('\U0010FFFF')
        ua = np.array([[[ucs_value*ulen]*2]*3]*4, dtype='U%s' % ulen)
        ua.newbyteorder()  # Should succeed. 
Example 30
Project: LaserTOF   Author: kyleuckert   File: test_regression.py    MIT License 5 votes vote down vote up
def test_unaligned_unicode_access(self, level=rlevel):
        # Ticket #825
        for i in range(1, 9):
            msg = 'unicode offset: %d chars' % i
            t = np.dtype([('a', 'S%d' % i), ('b', 'U2')])
            x = np.array([(asbytes('a'), sixu('b'))], dtype=t)
            if sys.version_info[0] >= 3:
                assert_equal(str(x), "[(b'a', 'b')]", err_msg=msg)
            else:
                assert_equal(str(x), "[('a', u'b')]", err_msg=msg) 
Example 31
Project: LaserTOF   Author: kyleuckert   File: test_regression.py    MIT License 5 votes vote down vote up
def test_unicode_to_string_cast(self):
        # Ticket #1240.
        a = np.array([[sixu('abc'), sixu('\u03a3')],
                      [sixu('asdf'), sixu('erw')]],
                     dtype='U')
        self.assertRaises(UnicodeEncodeError, np.array, a, 'S4') 
Example 32
Project: LaserTOF   Author: kyleuckert   File: test_regression.py    MIT License 5 votes vote down vote up
def test_string_truncation_ucs2(self):
        # Ticket #2081. Python compiled with two byte unicode
        # can lead to truncation if itemsize is not properly
        # adjusted for NumPy's four byte unicode.
        if sys.version_info[0] >= 3:
            a = np.array(['abcd'])
        else:
            a = np.array([sixu('abcd')])
        assert_equal(a.dtype.itemsize, 16) 
Example 33
Project: LaserTOF   Author: kyleuckert   File: test_regression.py    MIT License 5 votes vote down vote up
def test_fortran_order_buffer(self):
        import numpy as np
        a = np.array([['Hello', 'Foob']], dtype='U5', order='F')
        arr = np.ndarray(shape=[1, 2, 5], dtype='U1', buffer=a)
        arr2 = np.array([[[sixu('H'), sixu('e'), sixu('l'), sixu('l'), sixu('o')],
                          [sixu('F'), sixu('o'), sixu('o'), sixu('b'), sixu('')]]])
        assert_array_equal(arr, arr2) 
Example 34
Project: att   Author: Centre-Alt-Rendiment-Esportiu   File: test_regression.py    GNU General Public License v3.0 5 votes vote down vote up
def test_masked_array_repr_unicode(self):
        # Ticket #1256
        repr(np.ma.array(sixu("Unicode"))) 
Example 35
Project: att   Author: Centre-Alt-Rendiment-Esportiu   File: test_arrayprint.py    GNU General Public License v3.0 5 votes vote down vote up
def test_unicode_object_array():
    import sys
    if sys.version_info[0] >= 3:
        expected = "array(['é'], dtype=object)"
    else:
        expected = "array([u'\\xe9'], dtype=object)"
    x = np.array([sixu('\xe9')], dtype=object)
    assert_equal(repr(x), expected) 
Example 36
Project: att   Author: Centre-Alt-Rendiment-Esportiu   File: test_multiarray.py    GNU General Public License v3.0 5 votes vote down vote up
def test_unicode(self):
        g1 = array([sixu("This"), sixu("is"), sixu("example")])
        g2 = array([sixu("This"), sixu("was"), sixu("example")])
        assert_array_equal(g1 == g2, [g1[i] == g2[i] for i in [0, 1, 2]])
        assert_array_equal(g1 != g2, [g1[i] != g2[i] for i in [0, 1, 2]])
        assert_array_equal(g1 <= g2, [g1[i] <= g2[i] for i in [0, 1, 2]])
        assert_array_equal(g1 >= g2, [g1[i] >= g2[i] for i in [0, 1, 2]])
        assert_array_equal(g1 < g2,  [g1[i] < g2[i] for i in [0, 1, 2]])
        assert_array_equal(g1 > g2,  [g1[i] > g2[i] for i in [0, 1, 2]]) 
Example 37
Project: att   Author: Centre-Alt-Rendiment-Esportiu   File: test_unicode.py    GNU General Public License v3.0 5 votes vote down vote up
def content_check(self, ua, ua_scalar, nbytes):

        # Check the length of the unicode base type
        self.assertTrue(int(ua.dtype.str[2:]) == self.ulen)
        # Check the length of the data buffer
        self.assertTrue(buffer_length(ua) == nbytes)
        # Small check that data in array element is ok
        self.assertTrue(ua_scalar == sixu(''))
        # Encode to ascii and double check
        self.assertTrue(ua_scalar.encode('ascii') == asbytes(''))
        # Check buffer lengths for scalars
        if ucs4:
            self.assertTrue(buffer_length(ua_scalar) == 0)
        else:
            self.assertTrue(buffer_length(ua_scalar) == 0) 
Example 38
Project: att   Author: Centre-Alt-Rendiment-Esportiu   File: test_defchararray.py    GNU General Public License v3.0 5 votes vote down vote up
def test_from_unicode_array(self):
        A = np.array([['abc', sixu('Sigma \u03a3')],
                      ['long   ', '0123456789']])
        assert_equal(A.dtype.type, np.unicode_)
        B = np.char.array(A)
        assert_array_equal(B, A)
        assert_equal(B.dtype, A.dtype)
        assert_equal(B.shape, A.shape)
        B = np.char.array(A, **kw_unicode_true)
        assert_array_equal(B, A)
        assert_equal(B.dtype, A.dtype)
        assert_equal(B.shape, A.shape)
        def fail():
            B = np.char.array(A, **kw_unicode_false)
        self.assertRaises(UnicodeEncodeError, fail) 
Example 39
Project: att   Author: Centre-Alt-Rendiment-Esportiu   File: test_defchararray.py    GNU General Public License v3.0 5 votes vote down vote up
def test_unicode_upconvert(self):
        A = np.char.array(['abc'])
        B = np.char.array([sixu('\u03a3')])
        assert_(issubclass((A + B).dtype.type, np.unicode_)) 
Example 40
Project: att   Author: Centre-Alt-Rendiment-Esportiu   File: test_defchararray.py    GNU General Public License v3.0 5 votes vote down vote up
def test_from_unicode(self):
        A = np.char.array(sixu('\u03a3'))
        assert_equal(len(A), 1)
        assert_equal(len(A[0]), 1)
        assert_equal(A.itemsize, 4)
        assert_(issubclass(A.dtype.type, np.unicode_)) 
Example 41
Project: att   Author: Centre-Alt-Rendiment-Esportiu   File: test_defchararray.py    GNU General Public License v3.0 5 votes vote down vote up
def setUp(self):
        self.A = np.array([[' abc ', ''],
                           ['12345', 'MixedCase'],
                           ['123 \t 345 \0 ', 'UPPER']]).view(np.chararray)
        self.B = np.array([[sixu(' \u03a3 '), sixu('')],
                           [sixu('12345'), sixu('MixedCase')],
                           [sixu('123 \t 345 \0 '), sixu('UPPER')]]).view(np.chararray) 
Example 42
Project: att   Author: Centre-Alt-Rendiment-Esportiu   File: test_defchararray.py    GNU General Public License v3.0 5 votes vote down vote up
def setUp(self):
        self.A = np.array([[' abc ', ''],
                           ['12345', 'MixedCase'],
                           ['123 \t 345 \0 ', 'UPPER']],
                          dtype='S').view(np.chararray)
        self.B = np.array([[sixu(' \u03a3 '), sixu('')],
                           [sixu('12345'), sixu('MixedCase')],
                           [sixu('123 \t 345 \0 '), sixu('UPPER')]]).view(np.chararray) 
Example 43
Project: att   Author: Centre-Alt-Rendiment-Esportiu   File: test_defchararray.py    GNU General Public License v3.0 5 votes vote down vote up
def test_lower(self):
        assert_(issubclass(self.A.lower().dtype.type, np.string_))
        assert_array_equal(self.A.lower(), asbytes_nested([
                [' abc ', ''],
                ['12345', 'mixedcase'],
                ['123 \t 345 \0 ', 'upper']]))
        assert_(issubclass(self.B.lower().dtype.type, np.unicode_))
        assert_array_equal(self.B.lower(), [
                [sixu(' \u03c3 '), sixu('')],
                [sixu('12345'), sixu('mixedcase')],
                [sixu('123 \t 345 \0 '), sixu('upper')]]) 
Example 44
Project: att   Author: Centre-Alt-Rendiment-Esportiu   File: test_defchararray.py    GNU General Public License v3.0 5 votes vote down vote up
def test_title(self):
        assert_(issubclass(self.A.title().dtype.type, np.string_))
        assert_array_equal(self.A.title(), asbytes_nested([
                [' Abc ', ''],
                ['12345', 'Mixedcase'],
                ['123 \t 345 \0 ', 'Upper']]))
        assert_(issubclass(self.B.title().dtype.type, np.unicode_))
        assert_array_equal(self.B.title(), [
                [sixu(' \u03a3 '), sixu('')],
                [sixu('12345'), sixu('Mixedcase')],
                [sixu('123 \t 345 \0 '), sixu('Upper')]]) 
Example 45
Project: att   Author: Centre-Alt-Rendiment-Esportiu   File: test_defchararray.py    GNU General Public License v3.0 5 votes vote down vote up
def test_upper(self):
        assert_(issubclass(self.A.upper().dtype.type, np.string_))
        assert_array_equal(self.A.upper(), asbytes_nested([
                [' ABC ', ''],
                ['12345', 'MIXEDCASE'],
                ['123 \t 345 \0 ', 'UPPER']]))
        assert_(issubclass(self.B.upper().dtype.type, np.unicode_))
        assert_array_equal(self.B.upper(), [
                [sixu(' \u03a3 '), sixu('')],
                [sixu('12345'), sixu('MIXEDCASE')],
                [sixu('123 \t 345 \0 '), sixu('UPPER')]]) 
Example 46
Project: att   Author: Centre-Alt-Rendiment-Esportiu   File: test_regression.py    GNU General Public License v3.0 5 votes vote down vote up
def test_unicode_swapping(self,level=rlevel):
        """Ticket #79"""
        ulen = 1
        ucs_value = sixu('\U0010FFFF')
        ua = np.array([[[ucs_value*ulen]*2]*3]*4, dtype='U%s' % ulen)
        ua2 = ua.newbyteorder() 
Example 47
Project: att   Author: Centre-Alt-Rendiment-Esportiu   File: test_regression.py    GNU General Public License v3.0 5 votes vote down vote up
def test_unaligned_unicode_access(self, level=rlevel) :
        """Ticket #825"""
        for i in range(1, 9) :
            msg = 'unicode offset: %d chars'%i
            t = np.dtype([('a', 'S%d'%i), ('b', 'U2')])
            x = np.array([(asbytes('a'), sixu('b'))], dtype=t)
            if sys.version_info[0] >= 3:
                assert_equal(str(x), "[(b'a', 'b')]", err_msg=msg)
            else:
                assert_equal(str(x), "[('a', u'b')]", err_msg=msg) 
Example 48
Project: att   Author: Centre-Alt-Rendiment-Esportiu   File: test_regression.py    GNU General Public License v3.0 5 votes vote down vote up
def test_unicode_to_string_cast(self):
        """Ticket #1240."""
        a = np.array(
                [   [sixu('abc'), sixu('\u03a3')],
                    [sixu('asdf'), sixu('erw')]
                ], dtype='U')
        def fail():
            b = np.array(a, 'S4')
        self.assertRaises(UnicodeEncodeError, fail) 
Example 49
Project: att   Author: Centre-Alt-Rendiment-Esportiu   File: test_regression.py    GNU General Public License v3.0 5 votes vote down vote up
def test_string_truncation_ucs2(self):
        # Ticket #2081. Python compiled with two byte unicode
        # can lead to truncation if itemsize is not properly
        # adjusted for Numpy's four byte unicode.
        if sys.version_info[0] >= 3:
            a = np.array(['abcd'])
        else:
            a = np.array([sixu('abcd')])
        assert_equal(a.dtype.itemsize, 16) 
Example 50
Project: att   Author: Centre-Alt-Rendiment-Esportiu   File: test_regression.py    GNU General Public License v3.0 5 votes vote down vote up
def test_fortran_order_buffer(self):
        import numpy as np
        a = np.array([['Hello', 'Foob']], dtype='U5', order='F')
        arr = np.ndarray(shape=[1, 2, 5], dtype='U1', buffer=a)
        arr2 = np.array([[[sixu('H'), sixu('e'), sixu('l'), sixu('l'), sixu('o')],
                          [sixu('F'), sixu('o'), sixu('o'), sixu('b'), sixu('')]]])
        assert_array_equal(arr, arr2)