本文整理匯總了Python中pandas.io.sql.has_table方法的典型用法代碼示例。如果您正苦於以下問題:Python sql.has_table方法的具體用法?Python sql.has_table怎麽用?Python sql.has_table使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pandas.io.sql
的用法示例。
在下文中一共展示了sql.has_table方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _to_sql_append
# 需要導入模塊: from pandas.io import sql [as 別名]
# 或者: from pandas.io.sql import has_table [as 別名]
def _to_sql_append(self):
# Nuke table just in case
self.drop_table('test_frame1')
self.pandasSQL.to_sql(
self.test_frame1, 'test_frame1', if_exists='fail')
# Add to table again
self.pandasSQL.to_sql(
self.test_frame1, 'test_frame1', if_exists='append')
assert self.pandasSQL.has_table('test_frame1')
num_entries = 2 * len(self.test_frame1)
num_rows = self._count_rows('test_frame1')
assert num_rows == num_entries
self.drop_table('test_frame1')
示例2: _to_sql_method_callable
# 需要導入模塊: from pandas.io import sql [as 別名]
# 或者: from pandas.io.sql import has_table [as 別名]
def _to_sql_method_callable(self):
check = [] # used to double check function below is really being used
def sample(pd_table, conn, keys, data_iter):
check.append(1)
data = [dict(zip(keys, row)) for row in data_iter]
conn.execute(pd_table.table.insert(), data)
self.drop_table('test_frame1')
self.pandasSQL.to_sql(self.test_frame1, 'test_frame1', method=sample)
assert self.pandasSQL.has_table('test_frame1')
assert check == [1]
num_entries = len(self.test_frame1)
num_rows = self._count_rows('test_frame1')
assert num_rows == num_entries
# Nuke table
self.drop_table('test_frame1')
示例3: _to_sql
# 需要導入模塊: from pandas.io import sql [as 別名]
# 或者: from pandas.io.sql import has_table [as 別名]
def _to_sql(self, method=None):
self.drop_table('test_frame1')
self.pandasSQL.to_sql(self.test_frame1, 'test_frame1', method=method)
assert self.pandasSQL.has_table('test_frame1')
num_entries = len(self.test_frame1)
num_rows = self._count_rows('test_frame1')
assert num_rows == num_entries
# Nuke table
self.drop_table('test_frame1')
示例4: _to_sql_fail
# 需要導入模塊: from pandas.io import sql [as 別名]
# 或者: from pandas.io.sql import has_table [as 別名]
def _to_sql_fail(self):
self.drop_table('test_frame1')
self.pandasSQL.to_sql(
self.test_frame1, 'test_frame1', if_exists='fail')
assert self.pandasSQL.has_table('test_frame1')
pytest.raises(ValueError, self.pandasSQL.to_sql,
self.test_frame1, 'test_frame1', if_exists='fail')
self.drop_table('test_frame1')
示例5: _to_sql_replace
# 需要導入模塊: from pandas.io import sql [as 別名]
# 或者: from pandas.io.sql import has_table [as 別名]
def _to_sql_replace(self):
self.drop_table('test_frame1')
self.pandasSQL.to_sql(
self.test_frame1, 'test_frame1', if_exists='fail')
# Add to table again
self.pandasSQL.to_sql(
self.test_frame1, 'test_frame1', if_exists='replace')
assert self.pandasSQL.has_table('test_frame1')
num_entries = len(self.test_frame1)
num_rows = self._count_rows('test_frame1')
assert num_rows == num_entries
self.drop_table('test_frame1')
示例6: test_to_sql_fail
# 需要導入模塊: from pandas.io import sql [as 別名]
# 或者: from pandas.io.sql import has_table [as 別名]
def test_to_sql_fail(self):
sql.to_sql(self.test_frame1, 'test_frame2',
self.conn, if_exists='fail')
assert sql.has_table('test_frame2', self.conn)
pytest.raises(ValueError, sql.to_sql, self.test_frame1,
'test_frame2', self.conn, if_exists='fail')
示例7: test_to_sql_replace
# 需要導入模塊: from pandas.io import sql [as 別名]
# 或者: from pandas.io.sql import has_table [as 別名]
def test_to_sql_replace(self):
sql.to_sql(self.test_frame1, 'test_frame3',
self.conn, if_exists='fail')
# Add to table again
sql.to_sql(self.test_frame1, 'test_frame3',
self.conn, if_exists='replace')
assert sql.has_table('test_frame3', self.conn)
num_entries = len(self.test_frame1)
num_rows = self._count_rows('test_frame3')
assert num_rows == num_entries
示例8: test_to_sql_append
# 需要導入模塊: from pandas.io import sql [as 別名]
# 或者: from pandas.io.sql import has_table [as 別名]
def test_to_sql_append(self):
sql.to_sql(self.test_frame1, 'test_frame4',
self.conn, if_exists='fail')
# Add to table again
sql.to_sql(self.test_frame1, 'test_frame4',
self.conn, if_exists='append')
assert sql.has_table('test_frame4', self.conn)
num_entries = 2 * len(self.test_frame1)
num_rows = self._count_rows('test_frame4')
assert num_rows == num_entries
示例9: test_create_table
# 需要導入模塊: from pandas.io import sql [as 別名]
# 或者: from pandas.io.sql import has_table [as 別名]
def test_create_table(self):
temp_conn = self.connect()
temp_frame = DataFrame(
{'one': [1., 2., 3., 4.], 'two': [4., 3., 2., 1.]})
pandasSQL = sql.SQLDatabase(temp_conn)
pandasSQL.to_sql(temp_frame, 'temp_frame')
assert temp_conn.has_table('temp_frame')
示例10: test_drop_table
# 需要導入模塊: from pandas.io import sql [as 別名]
# 或者: from pandas.io.sql import has_table [as 別名]
def test_drop_table(self):
temp_conn = self.connect()
temp_frame = DataFrame(
{'one': [1., 2., 3., 4.], 'two': [4., 3., 2., 1.]})
pandasSQL = sql.SQLDatabase(temp_conn)
pandasSQL.to_sql(temp_frame, 'temp_frame')
assert temp_conn.has_table('temp_frame')
pandasSQL.drop_table('temp_frame')
assert not temp_conn.has_table('temp_frame')
示例11: _to_sql
# 需要導入模塊: from pandas.io import sql [as 別名]
# 或者: from pandas.io.sql import has_table [as 別名]
def _to_sql(self):
self.drop_table('test_frame1')
self.pandasSQL.to_sql(self.test_frame1, 'test_frame1')
assert self.pandasSQL.has_table('test_frame1')
# Nuke table
self.drop_table('test_frame1')
示例12: test_to_sql
# 需要導入模塊: from pandas.io import sql [as 別名]
# 或者: from pandas.io.sql import has_table [as 別名]
def test_to_sql(self):
sql.to_sql(self.test_frame1, 'test_frame1', self.conn)
assert sql.has_table('test_frame1', self.conn)
示例13: test_create_and_drop_table
# 需要導入模塊: from pandas.io import sql [as 別名]
# 或者: from pandas.io.sql import has_table [as 別名]
def test_create_and_drop_table(self):
temp_frame = DataFrame(
{'one': [1., 2., 3., 4.], 'two': [4., 3., 2., 1.]})
self.pandasSQL.to_sql(temp_frame, 'drop_test_frame')
assert self.pandasSQL.has_table('drop_test_frame')
self.pandasSQL.drop_table('drop_test_frame')
assert not self.pandasSQL.has_table('drop_test_frame')