コード例 #1
0
ファイル: test_imstat.py プロジェクト: jlwalke2/python-swat
    def setUp(self):
        swat.reset_option()
        swat.options.cas.print_messages = False
        swat.options.interactive_mode = False

        self.s = swat.CAS(HOST, PORT, USER, PASSWD, protocol=PROTOCOL)

        if TestIMStat.server_type is None:
            # Set once per class and have every test use it.
            # No need to change between tests.
            TestIMStat.server_type = tm.get_cas_host_type(self.s)

        self.srcLib = tm.get_casout_lib(self.server_type)

        r = self.s.loadactionset(actionset='table')
        self.assertEqual(r, {'actionset': 'table'})

        r = self.s.loadactionset(actionset='simple')
        self.assertEqual(r, {'actionset': 'simple'})

        r = tm.load_data(self.s, 'datasources/cars_single.sashdat',
                         self.server_type)

        self.tablename = r['tableName']
        self.assertNotEqual(self.tablename, None)
コード例 #2
0
    def test_alltypes(self):
        srcLib = tm.get_casout_lib(self.server_type)
        out = self.s.loadactionset(actionset='actionTest')
        if out.severity != 0:
            self.skipTest("actionTest failed to load")

        out = self.s.alltypes(casout=dict(caslib=srcLib, name='typestable'))
        out = self.s.fetch(table=self.s.CASTable('typestable', caslib=srcLib),
                           sastypes=False)

        data = out['Fetch']

        self.assertEqual(data['Double'].iloc[0], 42.42)
        self.assertEqual(type(data['Double'].iloc[0]), np.float64)

        self.assertEqual(data['Char'].iloc[0], u'AbC\u2782\u2781\u2780')
        self.assertTrue(isinstance(data['Char'].iloc[0], text_types))

        self.assertEqual(data['Varchar'].iloc[0],
                         u'This is a test of the Emergency Broadcast System. '
                         u'This is only a test. BEEEEEEEEEEEEEEEEEEP WHAAAA '
                         u'SCREEEEEEEEEEEECH. \u2789\u2788\u2787\u2786\u2785'
                         u'\u2784\u2783\u2782\u2781\u2780 Blastoff!')
        self.assertTrue(isinstance(data['Varchar'].iloc[0], text_types))

        self.assertEqual(data['Int32'].iloc[0], 42)
        self.assertIn(type(data['Int32'].iloc[0]), [np.int32, np.int64])

        # REST interface can sometimes overflow the JSON float
        if np.isnan(data['Int64'].iloc[0]):
            self.assertEqual(type(data['Int64'].iloc[0]), np.float64)
        else:
            self.assertEqual(data['Int64'].iloc[0], 9223372036854775807)
            self.assertEqual(type(data['Int64'].iloc[0]), np.int64)

        self.assertEqual(data['Date'].iloc[0], datetime.date(1963, 5, 19))
        self.assertEqual(type(data['Date'].iloc[0]), datetime.date)
        # self.assertEqual(type(data['Date'].iloc[0]), datetime.Date)

        self.assertEqual(data['Time'].iloc[0], datetime.time(11, 12, 13, 141516))
        self.assertEqual(type(data['Time'].iloc[0]), datetime.time)
        # self.assertEqual(type(data['Time'].iloc[0]), datetime.Time)

        self.assertEqual(data['Datetime'].iloc[0],
                         pandas.to_datetime('1963-05-19 11:12:13.141516'))
        self.assertEqual(type(data['Datetime'].iloc[0]), pandas.Timestamp)
        # self.assertEqual(type(data['Datetime'].iloc[0]), datetime.Datetime)

        self.assertEqual(data['DecSext'].iloc[0], '12345678901234567890.123456789')
        self.assertTrue(isinstance(data['DecSext'].iloc[0], text_types))
        # self.assertEqual(type(data['DecSext'].iloc[0]), Decimal)

        self.assertEqual(type(data['Binary'].iloc[0]), bytes)
        self.assertTrue(len(data['Binary'].iloc[0]) > 0)

        self.assertEqual(type(data['Varbinary'].iloc[0]), bytes)
        # import binascii
        # print(len(data['Varbinary'].iloc[0]))
        # print(binascii.hexlify(data['Varbinary'].iloc[0]))
        self.assertTrue(len(data['Varbinary'].iloc[0]) > 0)
コード例 #3
0
ファイル: test_datetime.py プロジェクト: jlwalke2/python-swat
    def setUp(self):
        swat.reset_option()
        swat.options.cas.print_messages = False
        swat.options.interactive_mode = True
        swat.options.cas.missing.int64 = -999999

        self.s = swat.CAS(HOST, PORT, USER, PASSWD, protocol=PROTOCOL)

        if type(self).server_type is None:
            type(self).server_type = get_cas_host_type(self.s)

        self.srcLib = tm.get_casout_lib(self.server_type)

        self.dates = load_data(
            self.s,
            'datasources/dates.csv',
            self.server_type,
            importoptions=dict(
                vars=dict(Region=dict(), Date=dict(
                    format='DATE'))))['casTable']
        self.dates = self.dates.to_frame().set_index('Region')

        self.datetimes = load_data(
            self.s,
            'datasources/datetimes.csv',
            self.server_type,
            importoptions=dict(
                vars=dict(Region=dict(), Datetime=dict(
                    format='DATETIME'))))['casTable']
        self.datetimes = self.datetimes.to_frame().set_index('Region')
コード例 #4
0
    def test_alltypes(self):
        srcLib = tm.get_casout_lib(self.server_type)
        out = self.s.loadactionset(actionset='actionTest')
        out = self.s.alltypes(casout=dict(caslib=srcLib, name='typestable'))
        out = self.s.fetch(table=self.s.CASTable('typestable', caslib=srcLib), sastypes=False)

        data = out['Fetch']

        self.assertEqual(data.ix[:,'Double'][0], 42.42)
        self.assertEqual(type(data.ix[:,'Double'][0]), np.float64)

        self.assertEqual(data.ix[:,'Char'][0], u'AbC\u2782\u2781\u2780')
        if (sys.version_info >= (3, 0)):
            self.assertEqual(type(data.ix[:,'Char'][0]), type('aString'))
        else:
            self.assertEqual(type(data.ix[:,'Char'][0]), unicode)

        self.assertEqual(data.ix[:,'Varchar'][0],
                         u'This is a test of the Emergency Broadcast System. This is only a test. BEEEEEEEEEEEEEEEEEEP WHAAAA SCREEEEEEEEEEEECH. \u2789\u2788\u2787\u2786\u2785\u2784\u2783\u2782\u2781\u2780 Blastoff!')
        if (sys.version_info >= (3, 0)):
            self.assertEqual(type(data.ix[:,'Varchar'][0]), type('aString'))
        else:
            self.assertEqual(type(data.ix[:,'Varchar'][0]), unicode)

        self.assertEqual(data.ix[:,'Int32'][0], 42)
        self.assertIn(type(data.ix[:,'Int32'][0]), [np.int32, np.int64])

        self.assertEqual(data.ix[:,'Int64'][0], 9223372036854775807)
        self.assertEqual(type(data.ix[:,'Int64'][0]), np.int64)

        self.assertEqual(data.ix[:,'Date'][0], datetime.date(1963, 5, 19))
        self.assertEqual(type(data.ix[:,'Date'][0]), datetime.date)
        #self.assertEqual(type(data.ix[:,'Date'][0]), datetime.Date)

        self.assertEqual(data.ix[:,'Time'][0], datetime.time(11, 12, 13, 141516))
        self.assertEqual(type(data.ix[:,'Time'][0]), datetime.time)
        #self.assertEqual(type(data.ix[:,'Time'][0]), datetime.Time)

        self.assertEqual(data.ix[:,'Datetime'][0], pandas.to_datetime('1963-05-19 11:12:13.141516'))
        self.assertEqual(type(data.ix[:,'Datetime'][0]), pandas.Timestamp)
        #self.assertEqual(type(data.ix[:,'Datetime'][0]), datetime.Datetime)

        self.assertEqual(data.ix[:,'DecSext'][0], '12345678901234567890.123456789')
        if (sys.version_info >= (3, 0)):
            self.assertEqual(type(data.ix[:,'DecSext'][0]), type('aString'))
        else:
            self.assertEqual(type(data.ix[:,'DecSext'][0]), unicode)
        #self.assertEqual(type(data.ix[:,'DecSext'][0]), Decimal)

        self.assertEqual(type(data.ix[:,'Binary'][0]), bytes)
        self.assertTrue(len(data.ix[:,'Binary'][0]) > 0)

        self.assertEqual(type(data.ix[:,'Varbinary'][0]), bytes)
        #import binascii
        #print(len(data.ix[:,'Varbinary'][0]))
        #print(binascii.hexlify(data.ix[:,'Varbinary'][0]))
        self.assertTrue(len(data.ix[:,'Varbinary'][0]) > 0)
コード例 #5
0
    def setUp(self):
        swat.reset_option()
        swat.options.cas.print_messages = False
        swat.options.interactive_mode = True
        swat.options.cas.missing.int64 = -999999

        self.s = swat.CAS(HOST, PORT, USER, PASSWD, protocol=PROTOCOL)

        if type(self).server_type is None:
            type(self).server_type = get_cas_host_type(self.s)

        self.srcLib = tm.get_casout_lib(self.server_type)
コード例 #6
0
    def setUp(self):
        swat.reset_option()
        swat.options.cas.print_messages = False
        swat.options.interactive_mode = False

        self.s = swat.CAS(HOST, PORT, USER, PASSWD, protocol=PROTOCOL)

        self.s.loadactionset(actionset='actionTest')
        self.s.loadactionset(actionset='simple')

        server_type = tm.get_cas_host_type(self.s)

        self.trgLib = tm.get_casout_lib(server_type)
コード例 #7
0
    def test_alltypes_html(self):       
        srcLib = tm.get_casout_lib(self.server_type)

        out = self.s.loadactionset(actionset='actionTest')
        out = self.s.alltypes(casout=dict(caslib=srcLib, name='typestable'))
        out = self.s.fetch(table=self.s.CASTable('typestable', caslib=srcLib,
                                 varlist=['Double', 'Char', 'Varchar', 'Int32',
                                          'Int64', 'Date', 'Time', 'Datetime',
                                          'DecSext']), sastypes=False)

        data = out['Fetch']

        html = data._repr_html_()
コード例 #8
0
    def setUp(self):
        swat.reset_option()

        self.s = swat.CAS(HOST, PORT, USER, PASSWD, protocol=PROTOCOL)

        if type(self).server_type is None:
            type(self).server_type = get_cas_host_type(self.s)

        self.srcLib = tm.get_casout_lib(self.server_type)

        r = tm.load_data(self.s, 'datasources/cars_single.sashdat',
                         self.server_type)

        self.table = r['casTable']
コード例 #9
0
ファイル: test_unicode.py プロジェクト: Qvl22/tsne
    def test_alltypes(self):
        srcLib = tm.get_casout_lib(self.server_type)
        out = self.s.loadactionset(actionset='actionTest')
        out = self.s.alltypes(casout=dict(caslib=srcLib, name='typestable'))
        out = self.s.fetch(table=self.s.CASTable('typestable', caslib=srcLib),
                           sastypes=False)

        data = out['Fetch']

        self.assertEqual(data['Double'].iloc[0], 42.42)
        self.assertEqual(type(data['Double'].iloc[0]), np.float64)

        self.assertEqual(data['Char'].iloc[0], u'AbC\u2782\u2781\u2780')
        self.assertTrue(isinstance(data['Char'].iloc[0], unicode))

        self.assertEqual(
            data['Varchar'].iloc[0],
            u'This is a test of the Emergency Broadcast System. This is only a test. BEEEEEEEEEEEEEEEEEEP WHAAAA SCREEEEEEEEEEEECH. \u2789\u2788\u2787\u2786\u2785\u2784\u2783\u2782\u2781\u2780 Blastoff!'
        )
        self.assertTrue(isinstance(data['Varchar'].iloc[0], unicode))

        self.assertEqual(data['Int32'].iloc[0], 42)
        self.assertIn(type(data['Int32'].iloc[0]), [np.int32, np.int64])

        # REST interface can sometimes overflow the JSON float
        if np.isnan(data['Int64'].iloc[0]):
            self.assertEqual(type(data['Int64'].iloc[0]), np.float64)
        else:
            self.assertEqual(data['Int64'].iloc[0], 9223372036854775807)
            self.assertEqual(type(data['Int64'].iloc[0]), np.int64)

        self.assertEqual(data['Date'].iloc[0], datetime.date(1963, 5, 19))
        self.assertEqual(type(data['Date'].iloc[0]), datetime.date)
        #self.assertEqual(type(data['Date'].iloc[0]), datetime.Date)

        self.assertEqual(data['Time'].iloc[0],
                         datetime.time(11, 12, 13, 141516))
        self.assertTrue(isinstance(data['Time'].iloc[0], datetime.time))
        #self.assertEqual(type(data['Time'].iloc[0]), datetime.Time)

        self.assertEqual(data['Datetime'].iloc[0],
                         pd.to_datetime('1963-05-19 11:12:13.141516'))
        self.assertTrue(isinstance(data['Datetime'].iloc[0], pd.Timestamp))
        #self.assertEqual(type(data['Datetime'].iloc[0]), datetime.Datetime)

        self.assertEqual(data['DecSext'].iloc[0],
                         '12345678901234567890.123456789')
        self.assertTrue(isinstance(data['DecSext'].iloc[0], unicode))
コード例 #10
0
ファイル: test_basics.py プロジェクト: gwfrere/python-swat
    def setUp(self):
        swat.reset_option()
        swat.options.cas.print_messages = False
        swat.options.interactive_mode = True

        self.s = swat.CAS(HOST, PORT, USER, PASSWD, protocol=PROTOCOL)

        if type(self).server_type is None:
            type(self).server_type = get_cas_host_type(self.s)

        self.srcLib = tm.get_casout_lib(self.server_type)

        r = load_data(self.s, 'datasources/cars_single.sashdat',
                      self.server_type)

        self.tablename = r['tableName']
        self.assertNotEqual(self.tablename, None)
コード例 #11
0
    def setUp(self):
        swat.reset_option()
        swat.options.cas.print_messages = False
        swat.options.interactive_mode = False

        self.s = swat.CAS(HOST, PORT, USER, PASSWD, protocol=PROTOCOL)

        if type(self).server_type is None:
            type(self).server_type = get_cas_host_type(self.s)

        self.srcLib = tm.get_casout_lib(self.server_type)

        self.s.table.droptable('datasources.cars_single',
                               caslib=self.srcLib,
                               _messagelevel='none')
        r = tm.load_data(self.s, 'datasources/cars_single.sashdat',
                         self.server_type)

        self.table = r['casTable']
コード例 #12
0
    def setUp(self):
        swat.reset_option()
        swat.options.cas.print_messages = False
        swat.options.interactive_mode = False

        self.s = swat.CAS(HOST, PORT, USER, PASSWD, protocol=PROTOCOL)

        if type(self).server_type is None:
            # Set once per class and have every test use it. No need to change between tests.
            type(self).server_type = tm.get_cas_host_type(self.s)

        self.srcLib = tm.get_casout_lib(self.server_type)
        filename = os.path.join(os.path.dirname(__file__), 'datasources',
                                'ImageData.sashdat')
        r = tm.load_data(self.s, filename, self.server_type)

        self.tablename = r['tableName']
        self.assertNotEqual(self.tablename, None)
        self.table = ImageTable.from_table(r['casTable'])
コード例 #13
0
ファイル: test_datamsg.py プロジェクト: Micseb/python-swat
    def setUp(self):
        swat.reset_option()
        swat.options.cas.print_messages = False
        swat.options.interactive_mode = False

        self.s = swat.CAS(HOST, PORT, USER, PASSWD, protocol=PROTOCOL)

        if self.s._protocol in ['http', 'https']:
            tm.TestCase.skipTest(self, 'REST does not support data messages')        

        if type(self).server_type is None: 
            # Set once per class and have every test use it. No need to change between tests.    
            type(self).server_type = tm.get_cas_host_type(self.s)        

        self.srcLib = tm.get_casout_lib(self.server_type)
        
        r = tm.load_data(self.s, 'datasources/cars_single.sashdat', self.server_type)

        self.tablename = r['tableName']
        self.assertNotEqual(self.tablename, None)
        self.table = r['casTable']
コード例 #14
0
    def setUp(self):
        swat.reset_option()
        swat.options.cas.print_messages = False
        swat.options.interactive_mode = False

        self.s = swat.CAS(HOST, PORT, USER, PASSWD, protocol=PROTOCOL)

        if type(self).server_type is None:
            type(self).server_type = get_cas_host_type(self.s)

        self.srcLib = tm.get_casout_lib(self.server_type)

        self.df = pd.DataFrame(
            [[1, 2, 3, 4, 5, 'a', 'b', 'c'],
             [6, np.nan, 8, 9, np.nan, 'd', 'e', 'f'],
             [11, np.nan, 13, 14, np.nan, np.nan, 'h', 'i'],
             [16, 17, 18, np.nan, 20, 'j', np.nan, 'l'],
             [np.nan, 22, 23, 24, np.nan, np.nan, 'n', 'o']],
            columns=['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'])

        self.table = self.s.upload_frame(self.df)
コード例 #15
0
    def setUp(self):
        swat.reset_option()
        swat.options.cas.print_messages = False
        swat.options.interactive_mode = False

        self.s = swat.CAS(HOST, PORT, USER, PASSWD, protocol=PROTOCOL)

        if type(self).server_type is None:
            # Set once per class and have every test use it. No need to change between tests.
            type(self).server_type = tm.get_cas_host_type(self.s)

        self.srcLib = tm.get_casout_lib(self.server_type)

        # Define the model
        model = Sequential(self.s, model_table='test_model')
        model.add(InputLayer(3, 224, 224, offsets=(0, 0, 0)))
        model.add(Conv2d(8, 7))
        model.add(Pooling(2))
        model.add(Conv2d(8, 7))
        model.add(Pooling(2))
        model.add(Dense(16))
        model.add(OutputLayer(act='softmax', n=2))

        self.model = model
コード例 #16
0
ファイル: test_dataframe.py プロジェクト: kybowm/python-swat
    def test_alltypes(self):             
        from swat.dataframe import dtype_from_var

        srcLib = tm.get_casout_lib(self.server_type)

        out = self.s.loadactionset(actionset='actionTest')
        if out.severity != 0:
            self.skipTest("actionTest failed to load")

        out = self.s.alltypes(casout=dict(caslib=srcLib, name='typestable'))
        out = self.s.fetch(table=self.s.CASTable('typestable', caslib=srcLib), sastypes=False)

        data = out['Fetch']

        self.assertEqual(data['Double'].iloc[0], 42.42)
        self.assertEqual(type(data['Double'].iloc[0]), np.float64)
        self.assertEqual(dtype_from_var(data.Double.iloc[0]), 'double')

        self.assertEqual(data['Char'].iloc[0], u'AbC\u2782\u2781\u2780')
        if six.PY3:
            self.assertEqual(type(data['Char'].iloc[0]), str)
        else:
            self.assertEqual(type(data['Char'].iloc[0]), unicode)
        self.assertEqual(dtype_from_var(data.Char.iloc[0]), 'varchar')

        self.assertEqual(data['Varchar'].iloc[0], u'This is a test of the Emergency Broadcast System. This is only a test. BEEEEEEEEEEEEEEEEEEP WHAAAA SCREEEEEEEEEEEECH. \u2789\u2788\u2787\u2786\u2785\u2784\u2783\u2782\u2781\u2780 Blastoff!')
        if six.PY3:
            self.assertEqual(type(data['Varchar'].iloc[0]), str)
        else:
            self.assertEqual(type(data['Varchar'].iloc[0]), unicode)
        self.assertEqual(dtype_from_var(data.Varchar.iloc[0]), 'varchar')

        self.assertEqual(data['Int32'].iloc[0], 42)
        self.assertIn(type(data['Int32'].iloc[0]), [np.int32, np.int64])
        self.assertIn(dtype_from_var(data.Int32.iloc[0]), ['int32', 'int64'])

        # REST interface can sometimes overflow the JSON float
        if np.isnan(data['Int64'].iloc[0]):
            self.assertEqual(type(data['Int64'].iloc[0]), np.float64)
        else:
            self.assertEqual(data['Int64'].iloc[0], 9223372036854775807)
            self.assertEqual(type(data['Int64'].iloc[0]), np.int64)

        self.assertEqual(data['Date'].iloc[0], datetime.date(1963, 5, 19))
        self.assertEqual(type(data['Date'].iloc[0]), datetime.date)
        #self.assertEqual(type(data['Date'].iloc[0]), datetime.Date)
        self.assertEqual(dtype_from_var(data.Date.iloc[0]), 'date')

        self.assertEqual(data['Time'].iloc[0], datetime.time(11, 12, 13, 141516))
        self.assertEqual(type(data['Time'].iloc[0]), datetime.time)
        #self.assertEqual(type(data['Time'].iloc[0]), datetime.Time)
        self.assertEqual(dtype_from_var(data.Time.iloc[0]), 'time')

        self.assertEqual(data['Datetime'].iloc[0], pd.to_datetime('1963-05-19 11:12:13.141516'))
        self.assertEqual(type(data['Datetime'].iloc[0]), pd.Timestamp)
        #self.assertEqual(type(data['Datetime'].iloc[0]), datetime.Datetime)
        self.assertEqual(dtype_from_var(data.Datetime.iloc[0]), 'datetime')

        self.assertEqual(data['DecSext'].iloc[0], '12345678901234567890.123456789')
        if six.PY3:
            self.assertEqual(type(data['DecSext'].iloc[0]), str)
        else:
            self.assertEqual(type(data['DecSext'].iloc[0]), unicode)
        #self.assertEqual(type(data['DecSext'].iloc[0]), Decimal)

        #self.assertEqual(data['Varbinary'].iloc[0], '???')
        #self.assertEqual(type(data['Varbinary'].iloc[0]), bytes)

        #self.assertEqual(data['Binary'].iloc[0], '???')
        #self.assertEqual(type(data['Binary'].iloc[0]), bytes)

        self.assertEqual(dtype_from_var(b''), 'varbinary')

        with self.assertRaises(TypeError):
            dtype_from_var(None)