diff --git a/pycytominer/cyto_utils/cells.py b/pycytominer/cyto_utils/cells.py index d95a1126..0a901f2f 100644 --- a/pycytominer/cyto_utils/cells.py +++ b/pycytominer/cyto_utils/cells.py @@ -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"] @@ -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( diff --git a/tests/test_cyto_utils/test_cells.py b/tests/test_cyto_utils/test_cells.py index 04af8e82..69b7dda1 100644 --- a/tests/test_cyto_utils/test_cells.py +++ b/tests/test_cyto_utils/test_cells.py @@ -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" @@ -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" ) @@ -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" @@ -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" ) @@ -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(