Skip to content

Commit

Permalink
linting
Browse files Browse the repository at this point in the history
  • Loading branch information
d33bs committed Nov 3, 2024
1 parent d494167 commit 2cefb81
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
8 changes: 6 additions & 2 deletions pycytominer/cyto_utils/cells.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,9 @@ def count_cells(self, compartment="cells", count_subset=False):
query = f"select {query_cols} from {compartment}"
with self.conn.connect() as conn:
count_df = self.image_df.merge(
pd.read_sql(sql=query, con=conn.connection), how="inner", on=self.merge_cols
pd.read_sql(sql=query, con=conn.connection),
how="inner",
on=self.merge_cols,
)
count_df = (
count_df.groupby(self.strata)["ObjectNumber"]
Expand Down Expand Up @@ -679,7 +681,9 @@ def _compartment_df_generator(
f"select {cols} from {compartment} where {strata_condition}"
)
with self.conn.connect() as conn:
image_df_chunk = pd.read_sql(sql=specific_compartment_query, con=conn.connection)
image_df_chunk = pd.read_sql(
sql=specific_compartment_query, con=conn.connection
)
yield image_df_chunk

def merge_single_cells(
Expand Down
32 changes: 22 additions & 10 deletions tests/test_cyto_utils/test_cells.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,12 @@ def build_random_data(
with TEST_ENGINE.connect() as conn:
IMAGE_DF.to_sql(name="image", con=conn.connection, index=False, if_exists="replace")
CELLS_DF.to_sql(name="cells", con=conn.connection, index=False, if_exists="replace")
CYTOPLASM_DF.to_sql(name="cytoplasm", con=conn.connection, index=False, if_exists="replace")
NUCLEI_DF.to_sql(name="nuclei", con=conn.connection, index=False, if_exists="replace")
CYTOPLASM_DF.to_sql(
name="cytoplasm", con=conn.connection, index=False, if_exists="replace"
)
NUCLEI_DF.to_sql(
name="nuclei", con=conn.connection, index=False, if_exists="replace"
)

# Create a new table with a fourth compartment
NEW_FILE = f"sqlite:///{TMPDIR}/test_new.sqlite"
Expand All @@ -111,7 +115,9 @@ def build_random_data(
NEW_CYTOPLASM_DF.to_sql(
name="cytoplasm", con=conn.connection, index=False, if_exists="replace"
)
NUCLEI_DF.to_sql(name="nuclei", con=conn.connection, index=False, if_exists="replace")
NUCLEI_DF.to_sql(
name="nuclei", con=conn.connection, index=False, if_exists="replace"
)
NEW_COMPARTMENT_DF.to_sql(
name="new", con=conn.connection, index=False, if_exists="replace"
)
Expand All @@ -136,7 +142,9 @@ def build_random_data(
CYTOPLASM_DF.to_sql(
name="cytoplasm", con=conn.connection, index=False, if_exists="replace"
)
NUCLEI_DF.to_sql(name="nuclei", con=conn.connection, index=False, if_exists="replace")
NUCLEI_DF.to_sql(
name="nuclei", con=conn.connection, index=False, if_exists="replace"
)

# Ingest data with different image table name
IMAGE_DIFF_FILE = f"sqlite:///{TMPDIR}/test_image_diff_table_name.sqlite"
Expand All @@ -147,9 +155,7 @@ def build_random_data(
IMAGE_DF.to_sql(
name="Per_Image", con=conn.connection, index=False, if_exists="replace"
)
CELLS_DF.to_sql(
name="cells", con=conn.connection, index=False, if_exists="replace"
)
CELLS_DF.to_sql(name="cells", con=conn.connection, index=False, if_exists="replace")
CYTOPLASM_DF.to_sql(
name="cytoplasm", con=conn.connection, index=False, if_exists="replace"
)
Expand Down Expand Up @@ -892,12 +898,18 @@ def test_aggregate_count_cells_multiple_strata():

# Ingest data into temporary sqlite file
with test_engine.connect() as conn:
image_df.to_sql(name="image", con=conn.connection, index=False, if_exists="replace")
cells_df.to_sql(name="cells", con=conn.connection, index=False, if_exists="replace")
image_df.to_sql(
name="image", con=conn.connection, index=False, if_exists="replace"
)
cells_df.to_sql(
name="cells", con=conn.connection, index=False, if_exists="replace"
)
cytoplasm_df.to_sql(
name="cytoplasm", con=conn.connection, index=False, if_exists="replace"
)
nuclei_df.to_sql(name="nuclei", con=conn.connection, index=False, if_exists="replace")
nuclei_df.to_sql(
name="nuclei", con=conn.connection, index=False, if_exists="replace"
)

# Setup SingleCells Class
ap_strata = SingleCells(
Expand Down

0 comments on commit 2cefb81

Please sign in to comment.