当前位置: 首页>>代码示例>>Python>>正文


Python table.SqlTable类代码示例

本文整理汇总了Python中Orange.data.sql.table.SqlTable的典型用法代码示例。如果您正苦于以下问题:Python SqlTable类的具体用法?Python SqlTable怎么用?Python SqlTable使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了SqlTable类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_contingencies

    def test_contingencies(self):
        iris = SqlTable(self.conn, self.iris, inspect_values=True)
        iris.domain = Domain(iris.domain[:2] + (EqualWidth()(iris, iris.domain['sepal width']),),
                             iris.domain['iris'])

        conts = get_contingencies(iris)
        self.assertEqual(len(conts), 3)
        self.assertIsInstance(conts[0], Continuous)
        self.assertIsInstance(conts[1], Continuous)
        self.assertIsInstance(conts[2], Discrete)
开发者ID:675801717,项目名称:orange3,代码行数:10,代码来源:test_sql_table.py

示例2: setUp

 def setUp(self):
     self.data = [
         [1, 2, 3, None, 'm'],
         [2, 3, 1, 4, 'f'],
         [None, None, None, None, None],
         [7, None, 3, None, 'f'],
     ]
     self.table_uri = self.create_sql_table(self.data)
     table = SqlTable(self.table_uri, guess_values=True)
     variables = table.domain.variables
     new_table = table.copy()
     new_table.domain = domain.Domain(variables[:-1], variables[-1:])
     self.table = new_table
开发者ID:vishnu-locket,项目名称:orange3,代码行数:13,代码来源:test_filter.py

示例3: open_table

    def open_table(self):
        if self.tablecombo.currentIndex() <= 0:
            return

        if self.tablecombo.currentIndex() < self.tablecombo.count() - 1:
            self.table = self.tablecombo.currentText()
        else:
            self.table = self.sqltext.toPlainText()

        table = SqlTable(dict(host=self.host,
                              port=self.port,
                              database=self.database,
                              user=self.username,
                              password=self.password),
                         self.table,
                         inspect_values=False)
        sample = False
        if table.approx_len() > LARGE_TABLE and self.guess_values:
            confirm = QMessageBox(self)
            confirm.setIcon(QMessageBox.Warning)
            confirm.setText("Attribute discovery might take "
                            "a long time on large tables.\n"
                            "Do you want to auto discover attributes?")
            confirm.addButton("Yes", QMessageBox.YesRole)
            no_button = confirm.addButton("No", QMessageBox.NoRole)
            sample_button = confirm.addButton("Yes, on a sample",
                                              QMessageBox.YesRole)
            confirm.exec()
            if confirm.clickedButton() == no_button:
                self.guess_values = False
            elif confirm.clickedButton() == sample_button:
                sample = True

        self.information(1)
        if self.guess_values:
            QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
            if sample:
                s = table.sample_time(1)
                domain = s.get_domain(guess_values=True)
                self.information(
                    1, "Domain was generated from a sample of the table.")
            else:
                domain = table.get_domain(guess_values=True)
            QApplication.restoreOverrideCursor()
            table.domain = domain

        self.send("Data", table)
开发者ID:hugobuddel,项目名称:orange3,代码行数:47,代码来源:owsql.py

示例4: execute_sql

 def execute_sql(self):
     self.sql = self.sqltext.toPlainText()
     table = SqlTable.from_sql(
         host=self.host,
         database=self.database,
         user=self.username,
         password=self.password,
         sql=self.sql)
     self.send("Data", table)
开发者ID:CHANAYA,项目名称:orange3,代码行数:9,代码来源:owsql.py

示例5: test_recovers_connection_after_sql_error

    def test_recovers_connection_after_sql_error(self):
        import psycopg2

        conn, table_name = self.create_sql_table(
            np.arange(25).reshape((-1, 1)))
        sql_table = SqlTable(conn, table_name)

        try:
            broken_query = "SELECT 1/%s FROM %s" % (
                sql_table.domain.attributes[0].to_sql(), sql_table.table_name)
            with sql_table._execute_sql_query(broken_query) as cur:
                cur.fetchall()
        except psycopg2.DataError:
            pass

        working_query = "SELECT %s FROM %s" % (
            sql_table.domain.attributes[0].to_sql(), sql_table.table_name)
        with sql_table._execute_sql_query(working_query) as cur:
            cur.fetchall()
开发者ID:675801717,项目名称:orange3,代码行数:19,代码来源:test_sql_table.py

示例6: test_query_subset_of_attributes

    def test_query_subset_of_attributes(self):
        table = SqlTable(self.conn, self.iris)
        attributes = [
            self._mock_attribute("sepal length"),
            self._mock_attribute("sepal width"),
            self._mock_attribute("double width", '2 * "sepal width"')
        ]
        results = list(table._query(
            attributes
        ))

        self.assertSequenceEqual(
            results[:5],
            [(5.1, 3.5, 7.0),
             (4.9, 3.0, 6.0),
             (4.7, 3.2, 6.4),
             (4.6, 3.1, 6.2),
             (5.0, 3.6, 7.2)]
        )
开发者ID:675801717,项目名称:orange3,代码行数:19,代码来源:test_sql_table.py

示例7: test_XY_large

 def test_XY_large(self):
     from Orange.data.sql.table import AUTO_DL_LIMIT as DLL
     mat = np.random.randint(0, 2, (DLL + 100, 3))
     conn, table_name = self.create_sql_table(mat)
     sql_table = SqlTable(conn, table_name,
                          type_hints=Domain([], DiscreteVariable(
                              name='col2', values=['0', '1', '2'])))
     self.assertRaises(ValueError, lambda: sql_table.X)
     self.assertRaises(ValueError, lambda: sql_table.Y)
     with self.assertRaises(ValueError):
         sql_table.download_data(DLL + 10)
     # Download partial data
     sql_table.download_data(DLL + 10, partial=True)
     assert_almost_equal(sql_table.X, mat[:DLL + 10, :2])
     assert_almost_equal(sql_table.Y.flatten()[:DLL + 10], mat[:DLL + 10, 2])
     # Download all data
     sql_table.download_data()
     assert_almost_equal(sql_table.X, mat[:, :2])
     assert_almost_equal(sql_table.Y.flatten(), mat[:, 2])
开发者ID:675801717,项目名称:orange3,代码行数:19,代码来源:test_sql_table.py

示例8: test_query_subset_of_rows

    def test_query_subset_of_rows(self):
        table = SqlTable(self.conn, self.iris)
        all_results = list(table._query())

        results = list(table._query(rows=range(10)))
        self.assertEqual(len(results), 10)
        self.assertSequenceEqual(results, all_results[:10])

        results = list(table._query(rows=range(10)))
        self.assertEqual(len(results), 10)
        self.assertSequenceEqual(results, all_results[:10])

        results = list(table._query(rows=slice(None, 10)))
        self.assertEqual(len(results), 10)
        self.assertSequenceEqual(results, all_results[:10])

        results = list(table._query(rows=slice(10, None)))
        self.assertEqual(len(results), 140)
        self.assertSequenceEqual(results, all_results[10:])
开发者ID:675801717,项目名称:orange3,代码行数:19,代码来源:test_sql_table.py

示例9: open_table

    def open_table(self):
        if self.tablecombo.currentIndex() <= 0:
            return

        if self.tablecombo.currentIndex() < self.tablecombo.count() - 1:
            self.table = self.tablecombo.currentText()
        else:
            self.table = self.sqltext.toPlainText()

        table = SqlTable(dict(host=self.host,
                              port=self.port,
                              database=self.database,
                              user=self.username,
                              password=self.password),
                         self.table,
                         inspect_values=False)
        sample = False
        if table.approx_len() > LARGE_TABLE and self.guess_values:
            confirm = QMessageBox(self)
            confirm.setIcon(QMessageBox.Warning)
            confirm.setText("Attribute discovery might take "
                            "a long time on large tables.\n"
                            "Do you want to auto discover attributes?")
            confirm.addButton("Yes", QMessageBox.YesRole)
            no_button = confirm.addButton("No", QMessageBox.NoRole)
            sample_button = confirm.addButton("Yes, on a sample",
                                              QMessageBox.YesRole)
            confirm.exec()
            if confirm.clickedButton() == no_button:
                self.guess_values = False
            elif confirm.clickedButton() == sample_button:
                sample = True

        self.information(1)
        if self.guess_values:
            QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
            if sample:
                s = table.sample_time(1)
                domain = s.get_domain(guess_values=True)
                self.information(
                    1, "Domain was generated from a sample of the table.")
            else:
                domain = table.get_domain(guess_values=True)
            QApplication.restoreOverrideCursor()
            table.domain = domain

        if self.download:
            if table.approx_len() > MAX_DL_LIMIT:
                QMessageBox.warning(
                    self, 'Warning', "Data is too big to download.\n"
                    "Consider using the Data Sampler widget to download "
                    "a sample instead.")
                self.download = False
            elif table.approx_len() > AUTO_DL_LIMIT:
                confirm = QMessageBox.question(
                    self, 'Question', "Data appears to be big. Do you really "
                                      "want to download it to local memory?",
                    QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
                if confirm == QMessageBox.No:
                    self.download = False
        if self.download:
            table.download_data(MAX_DL_LIMIT)
            table = Table(table)

        self.send("Data", table)
开发者ID:PythonCharmers,项目名称:orange3,代码行数:65,代码来源:owsql.py

示例10: get_table

    def get_table(self):
        curIdx = self.tablecombo.currentIndex()
        if curIdx <= 0:
            if self.database_desc:
                self.database_desc["Table"] = "(None)"
            self.data_desc_table = None
            return

        if self.tablecombo.itemText(curIdx) != "Custom SQL":
            self.table = self.tables[self.tablecombo.currentIndex()]
            self.database_desc["Table"] = self.table
            if "Query" in self.database_desc:
                del self.database_desc["Query"]
            what = self.table
        else:
            what = self.sql = self.sqltext.toPlainText()
            self.table = "Custom SQL"
            if self.materialize:
                import psycopg2  # pylint: disable=import-error
                if not self.materialize_table_name:
                    self.Error.connection(
                        "Specify a table name to materialize the query")
                    return
                try:
                    with self.backend.execute_sql_query("DROP TABLE IF EXISTS " +
                                                        self.materialize_table_name):
                        pass
                    with self.backend.execute_sql_query("CREATE TABLE " +
                                                        self.materialize_table_name +
                                                        " AS " + self.sql):
                        pass
                    with self.backend.execute_sql_query("ANALYZE " + self.materialize_table_name):
                        pass
                except (psycopg2.ProgrammingError, BackendError) as ex:
                    self.Error.connection(str(ex))
                    return

        try:
            table = SqlTable(dict(host=self.host,
                                  port=self.port,
                                  database=self.database,
                                  user=self.username,
                                  password=self.password),
                             what,
                             backend=type(self.backend),
                             inspect_values=False)
        except BackendError as ex:
            self.Error.connection(str(ex))
            return

        self.Error.connection.clear()

        sample = False

        if table.approx_len() > LARGE_TABLE and self.guess_values:
            confirm = QMessageBox(self)
            confirm.setIcon(QMessageBox.Warning)
            confirm.setText("Attribute discovery might take "
                            "a long time on large tables.\n"
                            "Do you want to auto discover attributes?")
            confirm.addButton("Yes", QMessageBox.YesRole)
            no_button = confirm.addButton("No", QMessageBox.NoRole)
            if is_postgres(self.backend):
                sample_button = confirm.addButton("Yes, on a sample",
                                                  QMessageBox.YesRole)
            confirm.exec()
            if confirm.clickedButton() == no_button:
                self.guess_values = False
            elif is_postgres(self.backend) and \
                    confirm.clickedButton() == sample_button:
                sample = True

        self.Information.clear()
        if self.guess_values:
            QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
            if sample:
                s = table.sample_time(1)
                domain = s.get_domain(inspect_values=True)
                self.Information.data_sampled()
            else:
                domain = table.get_domain(inspect_values=True)
            QApplication.restoreOverrideCursor()
            table.domain = domain

        if self.download:
            if table.approx_len() > AUTO_DL_LIMIT:
                if is_postgres(self.backend):
                    confirm = QMessageBox(self)
                    confirm.setIcon(QMessageBox.Warning)
                    confirm.setText("Data appears to be big. Do you really "
                                    "want to download it to local memory?")

                    if table.approx_len() <= MAX_DL_LIMIT:
                        confirm.addButton("Yes", QMessageBox.YesRole)
                    no_button = confirm.addButton("No", QMessageBox.NoRole)
                    sample_button = confirm.addButton("Yes, a sample",
                                                      QMessageBox.YesRole)
                    confirm.exec()
                    if confirm.clickedButton() == no_button:
                        return
#.........这里部分代码省略.........
开发者ID:acopar,项目名称:orange3,代码行数:101,代码来源:owsql.py

示例11: connection_params

def connection_params():
    return SqlTable.parse_uri(get_dburi())
开发者ID:vishnu-locket,项目名称:orange3,代码行数:2,代码来源:base.py


注:本文中的Orange.data.sql.table.SqlTable类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。