def test_space_delimiter(self): "Test space delimiter" strg = asbytes(" 1 2 3 4 5 # test") test = LineSplitter(asbytes(" "))(strg) assert_equal(test, asbytes_nested(["1", "2", "3", "4", "", "5"])) test = LineSplitter(asbytes(" "))(strg) assert_equal(test, asbytes_nested(["1 2 3 4", "5"]))
def test_space_delimiter(self): "Test space delimiter" strg = asbytes(" 1 2 3 4 5 # test") test = LineSplitter(asbytes(' '))(strg) assert_equal(test, asbytes_nested(['1', '2', '3', '4', '', '5'])) test = LineSplitter(asbytes(' '))(strg) assert_equal(test, asbytes_nested(['1 2 3 4', '5']))
def test_no_delimiter(self): "Test LineSplitter w/o delimiter" strg = asbytes(" 1 2 3 4 5 # test") test = LineSplitter()(strg) assert_equal(test, asbytes_nested(["1", "2", "3", "4", "5"])) test = LineSplitter("")(strg) assert_equal(test, asbytes_nested(["1", "2", "3", "4", "5"]))
def test_set_elements(self): base = self.base.copy() # Set an element to mask ..................... mbase = base.view(mrecarray).copy() mbase[-2] = masked assert_equal( mbase._mask.tolist(), np.array([(0, 0, 0), (1, 1, 1), (0, 0, 0), (1, 1, 1), (1, 1, 1)], dtype=bool)) # Used to be mask, now it's recordmask! assert_equal(mbase.recordmask, [0, 1, 0, 1, 1]) # Set slices ................................. mbase = base.view(mrecarray).copy() mbase[:2] = (5, 5, 5) assert_equal(mbase.a._data, [5, 5, 3, 4, 5]) assert_equal(mbase.a._mask, [0, 0, 0, 0, 1]) assert_equal(mbase.b._data, [5., 5., 3.3, 4.4, 5.5]) assert_equal(mbase.b._mask, [0, 0, 0, 0, 1]) assert_equal(mbase.c._data, asbytes_nested(['5', '5', 'three', 'four', 'five'])) assert_equal(mbase.b._mask, [0, 0, 0, 0, 1]) mbase = base.view(mrecarray).copy() mbase[:2] = masked assert_equal(mbase.a._data, [1, 2, 3, 4, 5]) assert_equal(mbase.a._mask, [1, 1, 0, 0, 1]) assert_equal(mbase.b._data, [1.1, 2.2, 3.3, 4.4, 5.5]) assert_equal(mbase.b._mask, [1, 1, 0, 0, 1]) assert_equal(mbase.c._data, asbytes_nested(['one', 'two', 'three', 'four', 'five'])) assert_equal(mbase.b._mask, [1, 1, 0, 0, 1])
def test_no_delimiter(self): "Test LineSplitter w/o delimiter" strg = asbytes(" 1 2 3 4 5 # test") test = LineSplitter()(strg) assert_equal(test, asbytes_nested(['1', '2', '3', '4', '5'])) test = LineSplitter('')(strg) assert_equal(test, asbytes_nested(['1', '2', '3', '4', '5']))
def test_rpartition(self): P = self.A.rpartition(asbytes_nested(['3', 'M'])) assert_(issubclass(P.dtype.type, np.string_)) assert_array_equal(P, asbytes_nested([ [('', '', ' abc '), ('', '', '')], [('12', '3', '45'), ('', 'M', 'ixedCase')], [('123 \t ', '3', '45 \0 '), ('', '', 'UPPER')]]))
def test_partition(self): P = self.A.partition(asbytes_nested(['3', 'M'])) tgt = asbytes_nested([[(' abc ', '', ''), ('', '', '')], [('12', '3', '45'), ('', 'M', 'ixedCase')], [('12', '3', ' \t 345 \0 '), ('UPPER', '', '')]]) assert_(issubclass(P.dtype.type, np.string_)) assert_array_equal(P, tgt)
def test_variable_fixed_width(self): strg = asbytes(" 1 3 4 5 6# test") test = LineSplitter((3, 6, 6, 3))(strg) assert_equal(test, asbytes_nested(['1', '3', '4 5', '6'])) # strg = asbytes(" 1 3 4 5 6# test") test = LineSplitter((6, 6, 9))(strg) assert_equal(test, asbytes_nested(['1', '3 4', '5 6']))
def test_partition(self): if sys.version_info >= (2, 5): P = self.A.partition(asbytes_nested(['3', 'M'])) assert issubclass(P.dtype.type, np.string_) assert_array_equal(P, asbytes_nested([ [(' abc ', '', ''), ('', '', '')], [('12', '3', '45'), ('', 'M', 'ixedCase')], [('12', '3', ' \t 345 \0 '), ('UPPER', '', '')]]))
def test_rpartition(self): P = self.A.rpartition(asbytes_nested(['3', 'M'])) assert_(issubclass(P.dtype.type, np.string_)) assert_array_equal( P, asbytes_nested([[('', '', ' abc '), ('', '', '')], [('12', '3', '45'), ('', 'M', 'ixedCase')], [('123 \t ', '3', '45 \0 '), ('', '', 'UPPER')]]))
def test_tab_delimiter(self): "Test tab delimiter" strg = asbytes(" 1\t 2\t 3\t 4\t 5 6") test = LineSplitter(asbytes("\t"))(strg) assert_equal(test, asbytes_nested(["1", "2", "3", "4", "5 6"])) strg = asbytes(" 1 2\t 3 4\t 5 6") test = LineSplitter(asbytes("\t"))(strg) assert_equal(test, asbytes_nested(["1 2", "3 4", "5 6"]))
def test_tab_delimiter(self): "Test tab delimiter" strg = asbytes(" 1\t 2\t 3\t 4\t 5 6") test = LineSplitter(asbytes('\t'))(strg) assert_equal(test, asbytes_nested(['1', '2', '3', '4', '5 6'])) strg = asbytes(" 1 2\t 3 4\t 5 6") test = LineSplitter(asbytes('\t'))(strg) assert_equal(test, asbytes_nested(['1 2', '3 4', '5 6']))
def test_variable_fixed_width(self): strg = asbytes(" 1 3 4 5 6# test") test = LineSplitter((3, 6, 6, 3))(strg) assert_equal(test, asbytes_nested(["1", "3", "4 5", "6"])) # strg = asbytes(" 1 3 4 5 6# test") test = LineSplitter((6, 6, 9))(strg) assert_equal(test, asbytes_nested(["1", "3 4", "5 6"]))
def test_other_delimiter(self): "Test LineSplitter on delimiter" strg = asbytes("1,2,3,4,,5") test = LineSplitter(asbytes(','))(strg) assert_equal(test, asbytes_nested(['1', '2', '3', '4', '', '5'])) # strg = asbytes(" 1,2,3,4,,5 # test") test = LineSplitter(asbytes(','))(strg) assert_equal(test, asbytes_nested(['1', '2', '3', '4', '', '5']))
def test_other_delimiter(self): "Test LineSplitter on delimiter" strg = asbytes("1,2,3,4,,5") test = LineSplitter(asbytes(","))(strg) assert_equal(test, asbytes_nested(["1", "2", "3", "4", "", "5"])) # strg = asbytes(" 1,2,3,4,,5 # test") test = LineSplitter(asbytes(","))(strg) assert_equal(test, asbytes_nested(["1", "2", "3", "4", "", "5"]))
def test_lapack(self): f = FindDependenciesLdd() depsLibg2c = f.grep_dependencies(lapack_lite.__file__, asbytes_nested(['libg2c'])) depsLibgfortran = f.grep_dependencies(lapack_lite.__file__, asbytes_nested(['libgfortran'])) self.assertFalse(len(depsLibg2c)*len(depsLibgfortran) > 0, """Both g77 and gfortran runtimes linked in lapack_lite ! This is likely to cause random crashes and wrong results. See numpy INSTALL.txt for more information.""")
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(), [["\u03a3", ""], ["12345", "MixedCase"], ["123 \t 345", "UPPER"]])
def test_constant_fixed_width(self): "Test LineSplitter w/ fixed-width fields" strg = asbytes(" 1 2 3 4 5 # test") test = LineSplitter(3)(strg) assert_equal(test, asbytes_nested(["1", "2", "3", "4", "", "5", ""])) # strg = asbytes(" 1 3 4 5 6# test") test = LineSplitter(20)(strg) assert_equal(test, asbytes_nested(["1 3 4 5 6"])) # strg = asbytes(" 1 3 4 5 6# test") test = LineSplitter(30)(strg) assert_equal(test, asbytes_nested(["1 3 4 5 6"]))
def test_constant_fixed_width(self): "Test LineSplitter w/ fixed-width fields" strg = asbytes(" 1 2 3 4 5 # test") test = LineSplitter(3)(strg) assert_equal(test, asbytes_nested(['1', '2', '3', '4', '', '5', ''])) # strg = asbytes(" 1 3 4 5 6# test") test = LineSplitter(20)(strg) assert_equal(test, asbytes_nested(['1 3 4 5 6'])) # strg = asbytes(" 1 3 4 5 6# test") test = LineSplitter(30)(strg) assert_equal(test, asbytes_nested(['1 3 4 5 6']))
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)
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(), [[u' \u03a3', ''], ['12345', 'MixedCase'], ['123 \t 345', 'UPPER']])
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']])
def test_rpartition(self): if sys.version_info >= (2, 5): P = self.A.rpartition(asbytes_nested(["3", "M"])) assert issubclass(P.dtype.type, np.string_) assert_array_equal( P, asbytes_nested( [ [("", "", " abc "), ("", "", "")], [("12", "3", "45"), ("", "M", "ixedCase")], [("123 \t ", "3", "45 \0 "), ("", "", "UPPER")], ] ), )
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"), "\u03a3") assert issubclass(R.dtype.type, np.unicode_) assert_array_equal(R, [[" \u03a3bc ", ""], ["12345", "MixedC\u03a3se"], ["123 \t 345 \x00", "UPPER"]])
def test_array(self): a = np.array([[1, 2], [3, 4]], float) fmt = "%.18e" c = StringIO() np.savetxt(c, a, fmt=fmt) c.seek(0) assert_equal( c.readlines(), asbytes_nested([(fmt + " " + fmt + "\n") % (1, 2), (fmt + " " + fmt + "\n") % (3, 4)]) ) a = np.array([[1, 2], [3, 4]], int) c = StringIO() np.savetxt(c, a, fmt="%d") c.seek(0) assert_equal(c.readlines(), asbytes_nested(["1 2\n", "3 4\n"]))
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(), [ [u' \u03a3', ''], ['12345', 'MixedCase'], ['123 \t 345', 'UPPER']])
def test_array(self): a = np.array([[1, 2], [3, 4]], float) fmt = "%.18e" c = StringIO() np.savetxt(c, a, fmt=fmt) c.seek(0) assert_equal(c.readlines(), asbytes_nested( [(fmt + ' ' + fmt + '\n') % (1, 2), (fmt + ' ' + fmt + '\n') % (3, 4)])) a = np.array([[1, 2], [3, 4]], int) c = StringIO() np.savetxt(c, a, fmt='%d') c.seek(0) assert_equal(c.readlines(), asbytes_nested(['1 2\n', '3 4\n']))
def test_usecols(self): a = np.array([[1, 2], [3, 4]], float) c = BytesIO() np.savetxt(c, a) c.seek(0) x = textadapter.loadtxt(c, dtype=float, usecols=(1, )) assert_array_equal(x, a[:, 1]) a = np.array([[1, 2, 3], [3, 4, 5]], float) c = BytesIO() np.savetxt(c, a) c.seek(0) x = textadapter.loadtxt(c, dtype=float, usecols=(1, 2)) assert_array_equal(x, a[:, 1:]) # Testing with arrays instead of tuples. c.seek(0) x = textadapter.loadtxt(c, dtype=float, usecols=np.array([1, 2])) assert_array_equal(x, a[:, 1:]) # Checking with dtypes defined converters. data = '''JOE 70.1 25.3\nBOB 60.5 27.9''' c = StringIO(data) names = ['stid', 'temp'] dtypes = ['S3', 'f8'] arr = textadapter.loadtxt(c, usecols=(0, 2), dtype=list(zip(names, dtypes))) assert_equal(arr['stid'], asbytes_nested(["JOE", "BOB"])) assert_equal(arr['temp'], [25.3, 27.9])
def test_usecols(self): a = np.array([[1, 2], [3, 4]], float) c = StringIO() np.savetxt(c, a) c.seek(0) x = np.loadtxt(c, dtype=float, usecols=(1,)) assert_array_equal(x, a[:, 1]) a = np.array([[1, 2, 3], [3, 4, 5]], float) c = StringIO() np.savetxt(c, a) c.seek(0) x = np.loadtxt(c, dtype=float, usecols=(1, 2)) assert_array_equal(x, a[:, 1:]) # Testing with arrays instead of tuples. c.seek(0) x = np.loadtxt(c, dtype=float, usecols=np.array([1, 2])) assert_array_equal(x, a[:, 1:]) # Checking with dtypes defined converters. data = """JOE 70.1 25.3 BOB 60.5 27.9 """ c = StringIO(data) names = ["stid", "temp"] dtypes = ["S4", "f8"] arr = np.loadtxt(c, usecols=(0, 2), dtype=zip(names, dtypes)) assert_equal(arr["stid"], asbytes_nested(["JOE", "BOB"])) assert_equal(arr["temp"], [25.3, 27.9])
def test_1D(self): a = np.array([1, 2, 3, 4], int) c = StringIO() np.savetxt(c, a, fmt='%d') c.seek(0) lines = c.readlines() assert_equal(lines, asbytes_nested(['1\n', '2\n', '3\n', '4\n']))
def test_split(self): A = self.A.split(asbytes('3')) assert_(issubclass(A.dtype.type, np.object_)) assert_equal( A.tolist(), asbytes_nested([[[' abc '], ['']], [['12', '45'], ['MixedCase']], [['12', ' \t ', '45 \x00 '], ['UPPER']]]))
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']])
def test_from_object_array(self): A = np.array([['abc', 2], ['long ', '0123456789']], dtype='O') B = np.char.array(A) assert_equal(B.dtype.itemsize, 10) assert_array_equal(B, asbytes_nested([['abc', '2'], ['long', '0123456789']]))
def test_setslices_hardmask(self): "Tests setting slices w/ hardmask." base = self.base.copy() mbase = base.view(mrecarray) mbase.harden_mask() try: mbase[-2:] = (5, 5, 5) assert_equal(mbase.a._data, [1, 2, 3, 5, 5]) assert_equal(mbase.b._data, [1.1, 2.2, 3.3, 5, 5.5]) assert_equal(mbase.c._data, asbytes_nested(['one', 'two', 'three', '5', 'five'])) assert_equal(mbase.a._mask, [0, 1, 0, 0, 1]) assert_equal(mbase.b._mask, mbase.a._mask) assert_equal(mbase.b._mask, mbase.c._mask) except NotImplementedError: # OK, not implemented yet... pass except AssertionError: raise else: raise Exception("Flexible hard masks should be supported !") # Not using a tuple should crash try: mbase[-2:] = 3 except (NotImplementedError, TypeError): pass else: raise TypeError("Should have expected a readable buffer object!")
def test_1D(self): a = np.array([1, 2, 3, 4], int) c = StringIO() np.savetxt(c, a, fmt="%d") c.seek(0) lines = c.readlines() assert_equal(lines, asbytes_nested(["1\n", "2\n", "3\n", "4\n"]))
def test_array(self): a = np.array([[1, 2], [3, 4]], float) fmt = "%.18e" c = StringIO() np.savetxt(c, a, fmt=fmt) c.seek(0) assert_equal( c.readlines(), asbytes_nested([(fmt + ' ' + fmt + '\n') % (1, 2), (fmt + ' ' + fmt + '\n') % (3, 4)])) a = np.array([[1, 2], [3, 4]], int) c = StringIO() np.savetxt(c, a, fmt='%d') c.seek(0) assert_equal(c.readlines(), asbytes_nested(['1 2\n', '3 4\n']))
def test_arrays_replicated_3d(self): s = idlsave.read(path.join(DATA_PATH, 'struct_arrays_replicated_3d.sav'), verbose=False) # Check column types assert_true(s.arrays_rep.a.dtype.type is np.object_) assert_true(s.arrays_rep.b.dtype.type is np.object_) assert_true(s.arrays_rep.c.dtype.type is np.object_) assert_true(s.arrays_rep.d.dtype.type is np.object_) # Check column shapes assert_equal(s.arrays_rep.a.shape, (4, 3, 2)) assert_equal(s.arrays_rep.b.shape, (4, 3, 2)) assert_equal(s.arrays_rep.c.shape, (4, 3, 2)) assert_equal(s.arrays_rep.d.shape, (4, 3, 2)) # Check values for i in range(4): for j in range(3): for k in range(2): assert_array_identical(s.arrays_rep.a[i, j, k], np.array([1, 2, 3], dtype=np.int16)) assert_array_identical( s.arrays_rep.b[i, j, k], np.array([4., 5., 6., 7.], dtype=np.float32)) assert_array_identical( s.arrays_rep.c[i, j, k], np.array([np.complex64(1 + 2j), np.complex64(7 + 8j)])) assert_array_identical( s.arrays_rep.d[i, j, k], np.array(asbytes_nested(["cheese", "bacon", "spam"]), dtype=np.object))
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']])
def test_split(self): A = self.A.split(asbytes('3')) assert_(issubclass(A.dtype.type, np.object_)) assert_equal(A.tolist(), asbytes_nested([ [[' abc '], ['']], [['12', '45'], ['MixedCase']], [['12', ' \t ', '45 \x00 '], ['UPPER']]]))
def test_setslices_hardmask(self): # Tests setting slices w/ hardmask. base = self.base.copy() mbase = base.view(mrecarray) mbase.harden_mask() try: mbase[-2:] = (5, 5, 5) assert_equal(mbase.a._data, [1, 2, 3, 5, 5]) assert_equal(mbase.b._data, [1.1, 2.2, 3.3, 5, 5.5]) assert_equal(mbase.c._data, asbytes_nested(['one', 'two', 'three', '5', 'five'])) assert_equal(mbase.a._mask, [0, 1, 0, 0, 1]) assert_equal(mbase.b._mask, mbase.a._mask) assert_equal(mbase.b._mask, mbase.c._mask) except NotImplementedError: # OK, not implemented yet... pass except AssertionError: raise else: raise Exception("Flexible hard masks should be supported !") # Not using a tuple should crash try: mbase[-2:] = 3 except (NotImplementedError, TypeError): pass else: raise TypeError("Should have expected a readable buffer object!")
def test_keep_missing_values(self): "Check that we're not losing missing values" converter = StringConverter(int, default=0, missing_values=asbytes("N/A")) assert_equal(converter.missing_values, set(asbytes_nested(['', 'N/A'])))
def test_scalars(self): s = readsav(path.join(DATA_PATH, 'struct_scalars.sav'), verbose=False) assert_identical(s.scalars.a, np.array(np.int16(1))) assert_identical(s.scalars.b, np.array(np.int32(2))) assert_identical(s.scalars.c, np.array(np.float32(3.))) assert_identical(s.scalars.d, np.array(np.float64(4.))) assert_identical(s.scalars.e, np.array(asbytes_nested(["spam"]), dtype=np.object)) assert_identical(s.scalars.f, np.array(np.complex64(-1.+3j)))
def test_usecols_with_structured_dtype(self): "Test usecols with an explicit structured dtype" data = StringIO("""JOE 70.1 25.3\nBOB 60.5 27.9""") names = ['stid', 'temp'] dtypes = ['S4', 'f8'] test = np.ndfromtxt(data, usecols=(0, 2), dtype=zip(names, dtypes)) assert_equal(test['stid'], asbytes_nested(["JOE", "BOB"])) assert_equal(test['temp'], [25.3, 27.9])
def test_lapack(self): f = FindDependenciesLdd() deps = f.grep_dependencies(lapack_lite.__file__, asbytes_nested(['libg2c', 'libgfortran'])) self.assertFalse(len(deps) > 1, """Both g77 and gfortran runtimes linked in lapack_lite ! This is likely to cause random crashes and wrong results. See numpy INSTALL.txt for more information.""")
def setup(self): "Generic setup" ilist = [1,2,3,4,5] flist = [1.1,2.2,3.3,4.4,5.5] slist = asbytes_nested(['one','two','three','four','five']) ddtype = [('a',int),('b',float),('c','|S8')] mask = [0,1,0,0,1] self.base = ma.array(list(zip(ilist,flist,slist)), mask=mask, dtype=ddtype)
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(), [[u' \u03a3 ', u''], [u'12345', u'MIXEDCASE'], [u'123 \t 345 \0 ', u'UPPER']])
def test_capitalize(self): assert_(issubclass(self.A.capitalize().dtype.type, np.string_)) assert_array_equal( self.A.capitalize(), asbytes_nested([[' abc ', ''], ['12345', 'Mixedcase'], ['123 \t 345 \0 ', 'Upper']])) assert_(issubclass(self.B.capitalize().dtype.type, np.unicode_)) assert_array_equal(self.B.capitalize(), [[sixu(' \u03c3 '), ''], ['12345', 'Mixedcase'], ['123 \t 345 \0 ', 'Upper']])
def test_swapcase(self): assert_(issubclass(self.A.swapcase().dtype.type, np.string_)) assert_array_equal( self.A.swapcase(), asbytes_nested([[' ABC ', ''], ['12345', 'mIXEDcASE'], ['123 \t 345 \0 ', 'upper']])) assert_(issubclass(self.B.swapcase().dtype.type, np.unicode_)) assert_array_equal(self.B.swapcase(), [[u' \u03c3 ', u''], [u'12345', u'mIXEDcASE'], [u'123 \t 345 \0 ', u'upper']])
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(), [[u' \u03c3 ', u''], [u'12345', u'mixedcase'], [u'123 \t 345 \0 ', u'upper']])
def test_compressed(self): s = readsav(path.join(DATA_PATH, 'various_compressed.sav'), verbose=False) assert_identical(s.i8u, np.uint8(234)) assert_identical(s.f32, np.float32(-3.1234567e+37)) assert_identical(s.c64, np.complex128(1.1987253647623157e+112-5.1987258887729157e+307j)) assert_equal(s.array5d.shape, (4, 3, 4, 6, 5)) assert_identical(s.arrays.a[0], np.array([1, 2, 3], dtype=np.int16)) assert_identical(s.arrays.b[0], np.array([4., 5., 6., 7.], dtype=np.float32)) assert_identical(s.arrays.c[0], np.array([np.complex64(1+2j), np.complex64(7+8j)])) assert_identical(s.arrays.d[0], np.array(asbytes_nested(["cheese", "bacon", "spam"]), dtype=np.object))
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(), [[u' \u03a3 ', u''], [u'12345', u'Mixedcase'], [u'123 \t 345 \0 ', u'Upper']])
def test_header(self): "Test retrieving a header" data = StringIO('gender age weight\nM 64.0 75.0\nF 25.0 60.0') test = np.ndfromtxt(data, dtype=None, names=True) control = {'gender': np.array(asbytes_nested(['M', 'F'])), 'age': np.array([64.0, 25.0]), 'weight': np.array([75.0, 60.0])} assert_equal(test['gender'], control['gender']) assert_equal(test['age'], control['age']) assert_equal(test['weight'], control['weight'])
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)