SHARE
TWEET

Untitled

a guest Jun 16th, 2019 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ```python
  2. import sys
  3. import os.path
  4. import pandas as pd
  5. import sqlite3
  6.  
  7. def compare_causal(c, d, e):
  8.     #Read a tsv file into pandas.dataframe
  9.     os.chdir(c)
  10.     patient_df = pd.read_csv(d, sep='t')
  11.     patient_table = d[0:-4]
  12.     patient_db_path = os.path.join(e, "PID_patients_data.db")
  13.  
  14.     #Build a connection
  15.     pat_connect = sqlite3.connect(patient_db_path, timeout=10.0)
  16.     pat_connect.isolation_level = None
  17.     #Import the pandas.dataframe to sql database
  18.     patient_df.to_sql(name=patient_table, con=pat_connect, if_exists='replace')
  19.  
  20. # There are other subsequent codes but they are all in the definition of the function compare_causal.
  21. ```
  22.      
  23. ```python
  24. import sys
  25. import os.path
  26. import pandas as pd
  27. import apsw
  28.  
  29. def compare_causal(c, d, e):
  30.     #Read a tsv file into pandas.dataframe
  31.     os.chdir(c)
  32.     patient_df = pd.read_csv(d, sep='t')
  33.     patient_table = d[0:-4]
  34.     patient_db_path = os.path.join(e, "PID_patients_data.db")
  35.  
  36.     #Build a connection
  37.     pat_connect = apsw.Connection(patient_db_path)
  38.     pat_connect.setbusytimeout(10000)
  39.     #Import the pandas.dataframe to sql database
  40.     patient_df.to_sql(name=patient_table, con=pat_connect, if_exists='replace')
  41.  
  42. # There are other subsequent codes but they are all in the definition of the function compare_causal.
  43. ```
  44.      
  45. Traceback (most recent call last):
  46.   File "/Users/skyxt/anaconda3/lib/python3.7/site-packages/pandas/io/sql.py", line 1431, in execute
  47.     cur.execute(*args)
  48. sqlite3.OperationalError: database is locked
  49.  
  50. During handling of the above exception, another exception occurred:
  51.  
  52. Traceback (most recent call last):
  53.   File "/Users/skyxt/Google Drive/HKU_YANG_LAB/HKU_Academic_Issue/Python Learning/Python scripts/Database_related scripts/Compare_PID_causal_genes_sqlite.py", line 207, in <module>
  54.     "/Users/skyxt/Google Drive/HKU_YANG_LAB/HKU_Academic_Issue/Project PID WES/Patients_Database")
  55.   File "/Users/skyxt/Google Drive/HKU_YANG_LAB/HKU_Academic_Issue/Python Learning/Python scripts/Database_related scripts/Compare_PID_causal_genes_sqlite.py", line 37, in compare_causal
  56.     patient_df.to_sql(name=patient_table, con=patient_connect, if_exists='replace')
  57.   File "/Users/skyxt/anaconda3/lib/python3.7/site-packages/pandas/core/generic.py", line 2531, in to_sql
  58.     dtype=dtype, method=method)
  59.   File "/Users/skyxt/anaconda3/lib/python3.7/site-packages/pandas/io/sql.py", line 460, in to_sql
  60.     chunksize=chunksize, dtype=dtype, method=method)
  61.   File "/Users/skyxt/anaconda3/lib/python3.7/site-packages/pandas/io/sql.py", line 1546, in to_sql
  62.     table.create()
  63.   File "/Users/skyxt/anaconda3/lib/python3.7/site-packages/pandas/io/sql.py", line 577, in create
  64.     self.pd_sql.drop_table(self.name, self.schema)
  65.   File "/Users/skyxt/anaconda3/lib/python3.7/site-packages/pandas/io/sql.py", line 1566, in drop_table
  66.     self.execute(drop_sql)
  67.   File "/Users/skyxt/anaconda3/lib/python3.7/site-packages/pandas/io/sql.py", line 1445, in execute
  68.     raise_with_traceback(ex)
  69.   File "/Users/skyxt/anaconda3/lib/python3.7/site-packages/pandas/compat/__init__.py", line 420, in raise_with_traceback
  70.     raise exc.with_traceback(traceback)
  71.   File "/Users/skyxt/anaconda3/lib/python3.7/site-packages/pandas/io/sql.py", line 1431, in execute
  72.     cur.execute(*args)
  73. pandas.io.sql.DatabaseError: Execution failed on sql 'DROP TABLE "sorted_A170618_Wang_PathwayCommons11_All_network_search_results"': database is locked
  74.      
  75. Traceback (most recent call last):
  76.   File "/Users/skyxt/anaconda3/lib/python3.7/site-packages/pandas/io/sql.py", line 1431, in execute
  77.     cur.execute(*args)
  78.   File "src/cursor.c", line 236, in resetcursor
  79. apsw.BusyError: BusyError: database is locked
  80.  
  81. During handling of the above exception, another exception occurred:
  82.  
  83. Traceback (most recent call last):
  84.   File "/Users/skyxt/anaconda3/lib/python3.7/site-packages/pandas/io/sql.py", line 1435, in execute
  85.     self.con.rollback()
  86. AttributeError: 'apsw.Connection' object has no attribute 'rollback'
  87.  
  88. During handling of the above exception, another exception occurred:
  89.  
  90. Traceback (most recent call last):
  91.   File "/Users/skyxt/Google Drive/HKU_YANG_LAB/HKU_Academic_Issue/Python Learning/Python scripts/Database_related scripts/Compare_PID_causal_genes_sqlite.py", line 207, in <module>
  92.     "/Users/skyxt/Google Drive/HKU_YANG_LAB/HKU_Academic_Issue/Project PID WES/Patients_Database")
  93.   File "/Users/skyxt/Google Drive/HKU_YANG_LAB/HKU_Academic_Issue/Python Learning/Python scripts/Database_related scripts/Compare_PID_causal_genes_sqlite.py", line 37, in compare_causal
  94.     patient_df.to_sql(name=patient_table, con=patient_connect, if_exists='replace')
  95.   File "/Users/skyxt/anaconda3/lib/python3.7/site-packages/pandas/core/generic.py", line 2531, in to_sql
  96.     dtype=dtype, method=method)
  97.   File "/Users/skyxt/anaconda3/lib/python3.7/site-packages/pandas/io/sql.py", line 460, in to_sql
  98.     chunksize=chunksize, dtype=dtype, method=method)
  99.   File "/Users/skyxt/anaconda3/lib/python3.7/site-packages/pandas/io/sql.py", line 1546, in to_sql
  100.     table.create()
  101.   File "/Users/skyxt/anaconda3/lib/python3.7/site-packages/pandas/io/sql.py", line 577, in create
  102.     self.pd_sql.drop_table(self.name, self.schema)
  103.   File "/Users/skyxt/anaconda3/lib/python3.7/site-packages/pandas/io/sql.py", line 1566, in drop_table
  104.     self.execute(drop_sql)
  105.   File "/Users/skyxt/anaconda3/lib/python3.7/site-packages/pandas/io/sql.py", line 1440, in execute
  106.     raise_with_traceback(ex)
  107.   File "/Users/skyxt/anaconda3/lib/python3.7/site-packages/pandas/compat/__init__.py", line 420, in raise_with_traceback
  108.     raise exc.with_traceback(traceback)
  109.   File "/Users/skyxt/anaconda3/lib/python3.7/site-packages/pandas/io/sql.py", line 1435, in execute
  110.     self.con.rollback()
  111. pandas.io.sql.DatabaseError: Execution failed on sql: DROP TABLE "sorted_A170618_Wang_PathwayCommons11_All_network_search_results"
  112. BusyError: database is locked
  113. unable to rollback
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top