Skip to content

Commit

Permalink
use sqlalchemy.text for queries
Browse files Browse the repository at this point in the history
  • Loading branch information
d33bs committed Nov 2, 2024
1 parent 1366cfe commit 6beee5f
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions pycytominer/cyto_utils/cells.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
output,
provide_linking_cols_feature_name_update,
)
from sqlalchemy import create_engine
from sqlalchemy import create_engine, text

default_compartments = get_default_compartments()
default_linking_cols = get_default_linking_cols()
Expand Down Expand Up @@ -420,12 +420,12 @@ def get_subsample(self, df=None, compartment="cells", rename_col=True):

def count_sql_table_rows(self, table):
"""Count total number of rows for a table."""
(num_rows,) = next(self.conn.execute(f"SELECT COUNT(*) FROM {table}"))
(num_rows,) = next(self.conn.execute(text(f"SELECT COUNT(*) FROM {table}")))
return num_rows

def get_sql_table_col_names(self, table):
"""Get column names from the database."""
ptr = self.conn.execute(f"SELECT * FROM {table} LIMIT 1").cursor
ptr = self.conn.execute(text(f"SELECT * FROM {table} LIMIT 1")).cursor
col_names = [obj[0] for obj in ptr.description]

return col_names
Expand Down Expand Up @@ -476,8 +476,7 @@ def load_compartment(self, compartment):

# Query database for selected columns of chosen compartment
columns = ", ".join(meta_cols + feat_cols)
query = f"select {columns} from {compartment}"
query_result = self.conn.execute(query)
query_result = self.conn.execute(text(f"select {columns} from {compartment}"))

# Load data row by row for both meta information and features
for i, row in enumerate(query_result):
Expand Down

0 comments on commit 6beee5f

Please sign in to comment.