Python numpy.compat.sixu() Examples
The following are 30
code examples of numpy.compat.sixu().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
numpy.compat
, or try the search function
.
Example #1
Source File: test_nditer.py From Computable with MIT License | 6 votes |
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 #2
Source File: test_defchararray.py From auto-alt-text-lambda-api with MIT License | 6 votes |
def test_replace(self): R = self.A.replace(asbytes_nested(['3', 'a']), asbytes_nested(['##########', '@'])) tgt = asbytes_nested([[' abc ', ''], ['12##########45', 'MixedC@se'], ['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 #3
Source File: test_nditer.py From auto-alt-text-lambda-api with MIT License | 6 votes |
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 #4
Source File: test_defchararray.py From keras-lambda with MIT License | 6 votes |
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 #5
Source File: test_defchararray.py From auto-alt-text-lambda-api with MIT License | 6 votes |
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 #6
Source File: test_defchararray.py From auto-alt-text-lambda-api with MIT License | 6 votes |
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 #7
Source File: test_defchararray.py From auto-alt-text-lambda-api with MIT License | 6 votes |
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 #8
Source File: test_nditer.py From ImageFusion with MIT License | 6 votes |
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 #9
Source File: test_defchararray.py From ImageFusion with MIT License | 6 votes |
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 #10
Source File: test_defchararray.py From ImageFusion with MIT License | 6 votes |
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 #11
Source File: test_defchararray.py From ImageFusion with MIT License | 6 votes |
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', 'MixedC@se'], ['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 #12
Source File: test_defchararray.py From ImageFusion with MIT License | 6 votes |
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 #13
Source File: test_defchararray.py From Computable with MIT License | 6 votes |
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 #14
Source File: test_defchararray.py From Computable with MIT License | 6 votes |
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', 'MixedC@se'], ['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 #15
Source File: test_defchararray.py From Computable with MIT License | 6 votes |
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 #16
Source File: test_defchararray.py From Computable with MIT License | 6 votes |
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 #17
Source File: test_defchararray.py From keras-lambda with MIT License | 5 votes |
def test_capitalize(self): tgt = asbytes_nested([[' abc ', ''], ['12345', 'Mixedcase'], ['123 \t 345 \0 ', 'Upper']]) assert_(issubclass(self.A.capitalize().dtype.type, np.string_)) assert_array_equal(self.A.capitalize(), tgt) tgt = [[sixu(' \u03c3 '), ''], ['12345', 'Mixedcase'], ['123 \t 345 \0 ', 'Upper']] assert_(issubclass(self.B.capitalize().dtype.type, np.unicode_)) assert_array_equal(self.B.capitalize(), tgt)
Example #18
Source File: test_defchararray.py From ImageFusion with MIT License | 5 votes |
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 #19
Source File: test_defchararray.py From keras-lambda with MIT License | 5 votes |
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 #20
Source File: test_multiarray.py From ImageFusion with MIT License | 5 votes |
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 #21
Source File: test_arrayprint.py From ImageFusion with MIT License | 5 votes |
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 #22
Source File: test_regression.py From ImageFusion with MIT License | 5 votes |
def test_masked_array_repr_unicode(self): # Ticket #1256 repr(np.ma.array(sixu("Unicode")))
Example #23
Source File: test_unicode.py From ImageFusion with MIT License | 5 votes |
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 #24
Source File: test_defchararray.py From keras-lambda with MIT License | 5 votes |
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
Source File: test_defchararray.py From keras-lambda with MIT License | 5 votes |
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 #26
Source File: test_defchararray.py From ImageFusion with MIT License | 5 votes |
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 #27
Source File: test_defchararray.py From ImageFusion with MIT License | 5 votes |
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 #28
Source File: test_defchararray.py From ImageFusion with MIT License | 5 votes |
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 #29
Source File: test_defchararray.py From ImageFusion with MIT License | 5 votes |
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 #30
Source File: test_defchararray.py From ImageFusion with MIT License | 5 votes |
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)