Ejemplo n.º 1
0
 def test12(self):
     df=DataFrame()
     df['DUM']=range(48) # Shouldn't complain
     self.assertEqual(df.keys(),['DUM'])
     
     df['DUM']=['A' for i in range(48)] # Shouldn't complain
     self.assertEqual(df.keys(),['DUM'])
     self.assertEqual(df._sqltypesdict['DUM'],'text')
Ejemplo n.º 2
0
 def test_kn(self):
     df = DataFrame()
     df.read_tbl('data/example.csv')
     y = [23]*len(df['X'])
     df['X'] = y
     
     self.assertEqual(df.keys(), ['CASE', 'TIME', 'CONDITION', 'X'])
Ejemplo n.º 3
0
    def test4(self):
        df = DataFrame()
        df[1] = list(range(100))
        df[2] = ['bob' for i in range(100)]
        df[3] = [i * 1.234232 for i in range(100)]
        df[4] = ['bob' for i in range(50)] + list(range(50))

        with self.assertRaises(TypeError) as cm:
            df._build_sqlite3_tbl(list(df.keys())[:2], 42)

        self.assertEqual(str(cm.exception), "'int' object is not iterable")
Ejemplo n.º 4
0
    def test4(self):
        df = DataFrame()
        df[1] = range(100)
        df[2] = ["bob" for i in range(100)]
        df[3] = [i * 1.234232 for i in range(100)]
        df[4] = ["bob" for i in range(50)] + range(50)

        with self.assertRaises(TypeError) as cm:
            df._build_sqlite3_tbl(df.keys()[:2], 42)

        self.assertEqual(str(cm.exception), "'int' object is not iterable")
Ejemplo n.º 5
0
    def test3(self):

        tupa = ('a1','a2','a3')
        tupb = ('a1','b2','b3')
        
        df=DataFrame()
        df.insert([(('a1','a2','a3'),34), (('a1','b2','b3'),1)])
        df.insert([(('a1','a2','a3'),34), (('a1','b2','b3'),2)])
        df.insert([(('a1','a2','a3'),42), (('a1','b2','b3'),3)])

        namea,nameb = df.keys()
        
        self.assertEqual(namea, tupa)
        self.assertEqual(nameb, tupb)
Ejemplo n.º 6
0
    def test31(self):
        df = DataFrame()
        df[1] = range(100)
        df[2] = ["bob" for i in range(100)]
        df[3] = [i * 1.234232 for i in range(100)]
        df[4] = ["bob" for i in range(50)] + range(50)

        shuffle(df[1])
        shuffle(df[2])
        shuffle(df[3])

        with self.assertRaises(KeyError) as cm:
            df._build_sqlite3_tbl(df.keys()[:2], ['4 != "bob"'])

        self.assertEqual(str(cm.exception), "'4'")
Ejemplo n.º 7
0
    def test31(self):
        df = DataFrame()
        df[1] = list(range(100))
        df[2] = ['bob' for i in range(100)]
        df[3] = [i * 1.234232 for i in range(100)]
        df[4] = ['bob' for i in range(50)] + list(range(50))

        shuffle(df[1])
        shuffle(df[2])
        shuffle(df[3])

        with self.assertRaises(KeyError) as cm:
            df._build_sqlite3_tbl(list(df.keys())[:2], ['4 != "bob"'])

        self.assertEqual(str(cm.exception), "'4'")
Ejemplo n.º 8
0
    def test1(self):
        R = {'DUM': 'integer',
          'COURSE': 'text',
           'ERROR': 'integer',
           'MODEL': 'text',
       'TIMEOFDAY': 'text',
         'SUBJECT': 'integer'}
        
        df=DataFrame()
        df.read_tbl('data/error~subjectXtimeofdayXcourseXmodel_MISSING.csv')
        df['DUM']=range(48) # Shouldn't complain

        self.assertEqual(df.keys(),
            ['SUBJECT', 'TIMEOFDAY', 'COURSE', 'MODEL', 'ERROR', 'DUM'])

        for k in R:
            self.assertEqual(df._sqltypesdict[k],R[k])
Ejemplo n.º 9
0
class Test_del_item(unittest.TestCase):
    def setUp(self):
        self.df=DataFrame()
        self.df.read_tbl('data/error~subjectXtimeofdayXcourseXmodel_MISSING.csv')
    
        del self.df['COURSE']

    def test0(self):
        self.assertEqual(self.df.keys(),
                         ['SUBJECT', 'TIMEOFDAY', 'MODEL', 'ERROR'])

    def test1(self):
        self.assertEqual(list(self.df.types()),
                         ['integer', 'text', 'text', 'integer'])

    def test3(self):
        self.assertEqual(len(self.df), 4)
Ejemplo n.º 10
0
    def test22(self):
        """test with string keys and where condition"""
        df = DataFrame()
        df['1'] = list(range(100))
        df['2'] = ['bob' for i in range(100)]
        df['3'] = [i * 1.234232 for i in range(100)]
        df['4'] = ['bob' for i in range(50)] + list(range(50))

        shuffle(df['1'])
        shuffle(df['2'])
        shuffle(df['3'])

        df._build_sqlite3_tbl(list(df.keys())[:2], ['4 not in ("bob")'])

        df._execute('select * from TBL')
        for i, (a, b) in enumerate(df.cur):
            self.assertEqual(a, df['1'][i + 50])
            self.assertEqual(b, df['2'][i + 50])
Ejemplo n.º 11
0
    def test22(self):
        """test with string keys and where condition"""
        df = DataFrame()
        df["1"] = range(100)
        df["2"] = ["bob" for i in range(100)]
        df["3"] = [i * 1.234232 for i in range(100)]
        df["4"] = ["bob" for i in range(50)] + range(50)

        shuffle(df["1"])
        shuffle(df["2"])
        shuffle(df["3"])

        df._build_sqlite3_tbl(df.keys()[:2], ['4 not in ("bob")'])

        df._execute("select * from TBL")
        for i, (a, b) in enumerate(df.cur):
            self.assertEqual(a, df["1"][i + 50])
            self.assertEqual(b, df["2"][i + 50])
Ejemplo n.º 12
0
    def test3(self):
        """test with string keys and tuple where condition"""
        df = DataFrame()
        df[1] = range(100)
        df[2] = ["bob" for i in range(100)]
        df[3] = [i * 1.234232 for i in range(100)]
        df[4] = ["bob" for i in range(50)] + range(50)

        shuffle(df[1])
        shuffle(df[2])
        shuffle(df[3])

        df._build_sqlite3_tbl(df.keys()[:2], [(4, "!=", "bob")])

        df._execute("select * from TBL")
        for i, (a, b) in enumerate(df.cur):
            self.assertEqual(a, df[1][i + 50])
            self.assertEqual(b, df[2][i + 50])
Ejemplo n.º 13
0
    def test3(self):
        """test with string keys and tuple where condition"""
        df = DataFrame()
        df[1] = list(range(100))
        df[2] = ['bob' for i in range(100)]
        df[3] = [i * 1.234232 for i in range(100)]
        df[4] = ['bob' for i in range(50)] + list(range(50))

        shuffle(df[1])
        shuffle(df[2])
        shuffle(df[3])

        df._build_sqlite3_tbl(list(df.keys())[:2], [(4, '!=', 'bob')])

        df._execute('select * from TBL')
        for i, (a, b) in enumerate(df.cur):
            self.assertEqual(a, df[1][i + 50])
            self.assertEqual(b, df[2][i + 50])
Ejemplo n.º 14
0
    def test1(self):
        """test with integer keys subset of table"""
        df = DataFrame()
        df[1] = range(100)
        df[2] = ["bob" for i in range(100)]
        df[3] = [i * 1.234232 for i in range(100)]
        df[4] = ["bob" for i in range(50)] + range(50)

        shuffle(df[1])
        shuffle(df[2])
        shuffle(df[3])
        shuffle(df[4])

        df._build_sqlite3_tbl(df.keys()[:2])

        df._execute("select * from TBL")
        for i, (a, b) in enumerate(df.cur):
            self.assertEqual(a, df[1][i])
            self.assertEqual(b, df[2][i])
Ejemplo n.º 15
0
    def test1(self):
        """test with integer keys subset of table"""
        df = DataFrame()
        df[1] = list(range(100))
        df[2] = ['bob' for i in range(100)]
        df[3] = [i * 1.234232 for i in range(100)]
        df[4] = ['bob' for i in range(50)] + list(range(50))

        shuffle(df[1])
        shuffle(df[2])
        shuffle(df[3])
        shuffle(df[4])

        df._build_sqlite3_tbl(list(df.keys())[:2])

        df._execute('select * from TBL')
        for i, (a, b) in enumerate(df.cur):
            self.assertEqual(a, df[1][i])
            self.assertEqual(b, df[2][i])
Ejemplo n.º 16
0
    def test2(self):
        df1=DataFrame()
        df2=DataFrame()
        df1.read_tbl('data/words~ageXcondition.csv')
        df2.read_tbl('data/words~ageXcondition.csv')

        M=df1.shape()[1]

        # this should work
        df1.attach(df2)

        # df1 should have twice as many rows now
        self.assertEqual(df1.shape()[1]/2,df2.shape()[1])

        # go through and check data
        for i in range(M):
            for n in df1.keys():
                if _isfloat(df1[n][i]):
                    self.assertAlmostEqual(df1[n][i],df1[n][M+i])
                else:
                    self.assertEqual(df1[n][i],df1[n][M+i])
Ejemplo n.º 17
0
    def test01(self):
        """test with integer keys"""
        df = DataFrame()
        df[1] = range(100)
        df[2] = ['bob' for i in range(100)]
        df[3] = [i * 1.234232 for i in range(100)]
        df[4] = ['bob' for i in range(50)] + range(50)

        shuffle(df[1])
        shuffle(df[2])
        shuffle(df[3])
        shuffle(df[4])

        df._build_sqlite3_tbl(df.keys())

        df._execute('select * from TBL')
        for i, (a, b, c, d) in enumerate(df.cur):
            self.assertEqual(a, df[1][i])
            self.assertEqual(b, df[2][i])
            self.assertEqual(c, df[3][i])
            self.assertEqual(d, str(df[4][i]))
Ejemplo n.º 18
0
    def test2(self):
        df1 = DataFrame()
        df2 = DataFrame()
        df1.read_tbl('data/words~ageXcondition.csv')
        df2.read_tbl('data/words~ageXcondition.csv')

        M = df1.shape()[1]

        # this should work
        df1.attach(df2)

        # df1 should have twice as many rows now
        self.assertEqual(df1.shape()[1] / 2, df2.shape()[1])

        # go through and check data
        for i in range(M):
            for n in list(df1.keys()):
                if _isfloat(df1[n][i]):
                    self.assertAlmostEqual(df1[n][i], df1[n][M + i])
                else:
                    self.assertEqual(df1[n][i], df1[n][M + i])
Ejemplo n.º 19
0
    def test02(self):
        """test with tuple keys"""
        df = DataFrame()
        ##        df.PRINTQUERIES = True
        df[(1,)] = range(100)
        df[(2,)] = ["bob" for i in range(100)]
        df[(3,)] = [i * 1.234232 for i in range(100)]
        df[(4,)] = ["bob" for i in range(50)] + range(50)

        shuffle(df[(1,)])
        shuffle(df[(2,)])
        shuffle(df[(3,)])
        shuffle(df[(4,)])

        df._build_sqlite3_tbl(df.keys())

        df._execute("select * from TBL")
        for i, (a, b, c, d) in enumerate(df.cur):
            self.assertEqual(a, df[(1,)][i])
            self.assertEqual(b, df[(2,)][i])
            self.assertEqual(c, df[(3,)][i])
            self.assertEqual(d, str(df[(4,)][i]))
Ejemplo n.º 20
0
    def test02(self):
        """test with tuple keys"""
        df = DataFrame()
        ##        df.PRINTQUERIES = True
        df[(1, )] = list(range(100))
        df[(2, )] = ['bob' for i in range(100)]
        df[(3, )] = [i * 1.234232 for i in range(100)]
        df[(4, )] = ['bob' for i in range(50)] + list(range(50))

        shuffle(df[(1, )])
        shuffle(df[(2, )])
        shuffle(df[(3, )])
        shuffle(df[(4, )])

        df._build_sqlite3_tbl(list(df.keys()))

        df._execute('select * from TBL')
        for i, (a, b, c, d) in enumerate(df.cur):
            self.assertEqual(a, df[(1, )][i])
            self.assertEqual(b, df[(2, )][i])
            self.assertEqual(c, df[(3, )][i])
            self.assertEqual(d, str(df[(4, )][i]))
Ejemplo n.º 21
0
    def test00(self):
        """test with string keys"""
        df = DataFrame()
        ##        df.PRINTQUERIES=True
        df["1"] = range(100)
        df["2"] = ["bob" for i in range(100)]
        df["3"] = [i * 1.234232 for i in range(100)]
        df["4"] = ["bob" for i in range(50)] + range(50)

        df["5"] = np.sqrt(df["3"] * 100.0)
        ##        print(df)

        shuffle(df["1"])
        shuffle(df["2"])
        shuffle(df["3"])

        df._build_sqlite3_tbl(df.keys())

        df._execute("select * from TBL")
        for i, (a, b, c, d, e) in enumerate(df.cur):
            self.assertEqual(a, df["1"][i])
            self.assertEqual(b, df["2"][i])
            self.assertEqual(c, df["3"][i])
            self.assertEqual(d, str(df["4"][i]))
Ejemplo n.º 22
0
    def test00(self):
        """test with string keys"""
        df = DataFrame()
        ##        df.PRINTQUERIES=True
        df['1'] = list(range(100))
        df['2'] = ['bob' for i in range(100)]
        df['3'] = [i * 1.234232 for i in range(100)]
        df['4'] = ['bob' for i in range(50)] + list(range(50))

        df['5'] = np.sqrt(df['3'] * 100.)
        ##        print(df)

        shuffle(df['1'])
        shuffle(df['2'])
        shuffle(df['3'])

        df._build_sqlite3_tbl(list(df.keys()))

        df._execute('select * from TBL')
        for i, (a, b, c, d, e) in enumerate(df.cur):
            self.assertEqual(a, df['1'][i])
            self.assertEqual(b, df['2'][i])
            self.assertEqual(c, df['3'][i])
            self.assertEqual(d, str(df['4'][i]))
Ejemplo n.º 23
0
 def test2(self):
     df = DataFrame()
     df.read_tbl('data/iqbrainsize.txt', delimiter='\t')
     cor = df.correlation(df.keys())
Ejemplo n.º 24
0
 def test11(self):
     df=DataFrame()
     df['DUM']=range(48) # Shouldn't complain
     self.assertEqual(df.keys(),['DUM'])
Ejemplo n.º 25
0
 def test21(self):
     df=DataFrame()
     df[1]=range(48)
     df[2]=['A' for i in range(48)]
     self.assertEqual(df.keys(),[1,2])
Ejemplo n.º 26
0
 def test2(self):
     df = DataFrame()
     df.read_tbl('data/iqbrainsize.txt', delimiter='\t')
     cor = df.correlation(list(df.keys()))