Skip to content

Commit 21331dd

Browse files
fix pandas future warnings
1 parent 3581528 commit 21331dd

File tree

6 files changed

+23
-26
lines changed

6 files changed

+23
-26
lines changed

fractal_tasks_core/cellvoyager/metadata.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,8 @@ def read_mrf_file(mrf_path: str) -> tuple[pd.DataFrame, int]:
207207
meas_df = pd.read_xml(
208208
mrf_path, xpath="//bts:MeasurementDetail", namespaces=ns
209209
)
210-
row_count = int(meas_df["RowCount"])
211-
column_count = int(meas_df["ColumnCount"])
210+
row_count = int(meas_df["RowCount"].iloc[0])
211+
column_count = int(meas_df["ColumnCount"].iloc[0])
212212
plate_type = row_count * column_count
213213
return channel_df, plate_type
214214

@@ -471,7 +471,7 @@ def check_group_consistency(grouped_df: pd.DataFrame, message: str = ""):
471471
# Check consistency in grouped df for multi-index, multi-column dataframes
472472
# raises an exception if there is variability
473473
diff_df = grouped_df.max() - grouped_df.min()
474-
if not np.isclose(np.sum(np.sum(diff_df)), 0.0):
474+
if not np.isclose(diff_df.to_numpy().sum(), 0.0):
475475
raise ValueError(
476476
"During metadata parsing, a consistency check failed: \n"
477477
f"{message}\n"

fractal_tasks_core/masked_loading.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,9 @@ def _preprocess_input(
109109
'In _preprocess_input, "{column_name}" '
110110
f" missing in {ROI_table.obs.columns=}"
111111
)
112-
label_value = int(float(ROI_table.obs[column_name][ROI_positional_index]))
112+
label_value = int(
113+
float(ROI_table.obs[column_name].iloc[ROI_positional_index])
114+
)
113115

114116
# Load masking-label array (lazily)
115117
masking_label_path = str(

fractal_tasks_core/roi/v1_overlaps.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ def get_overlapping_pair(
4545
num_lines = len(tmp_df.index)
4646
for pos_ind_1 in range(num_lines):
4747
for pos_ind_2 in range(pos_ind_1):
48-
if is_overlapping_2D(
49-
tmp_df.iloc[pos_ind_1], tmp_df.iloc[pos_ind_2], tol=tol
50-
):
48+
bbox_1 = tmp_df.iloc[pos_ind_1].to_numpy()
49+
bbox_2 = tmp_df.iloc[pos_ind_2].to_numpy()
50+
if is_overlapping_2D(bbox_1, bbox_2, tol=tol):
5151
return (pos_ind_1, pos_ind_2)
5252
return False
5353

@@ -96,9 +96,9 @@ def get_overlapping_pairs_3D(
9696
overlapping_list = []
9797
for pos_ind_1 in range(num_lines):
9898
for pos_ind_2 in range(pos_ind_1):
99-
overlap = is_overlapping_3D(
100-
new_tmp_df.iloc[pos_ind_1], new_tmp_df.iloc[pos_ind_2], tol=tol
101-
)
99+
bbox_1 = new_tmp_df.iloc[pos_ind_1].to_numpy()
100+
bbox_2 = new_tmp_df.iloc[pos_ind_2].to_numpy()
101+
overlap = is_overlapping_3D(bbox_1, bbox_2, tol=tol)
102102
if overlap:
103103
overlapping_list.append((pos_ind_1, pos_ind_2))
104104
return overlapping_list
@@ -177,7 +177,6 @@ def remove_FOV_overlaps(df: pd.DataFrame):
177177
# Loop over wells
178178
wells = sorted(list(set([ind[0] for ind in df.index])))
179179
for well in wells:
180-
181180
logger.info(f"removing FOV overlaps for {well=}")
182181
df_well = df.loc[well].copy()
183182

fractal_tasks_core/tasks/cellvoyager_to_ome_zarr_init.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -278,10 +278,10 @@ def cellvoyager_to_ome_zarr_init(
278278
site_metadata.set_index(["well_id", "FieldIndex"], inplace=True)
279279

280280
# Extract pixel sizes and bit_depth
281-
pixel_size_z = site_metadata["pixel_size_z"][0]
282-
pixel_size_y = site_metadata["pixel_size_y"][0]
283-
pixel_size_x = site_metadata["pixel_size_x"][0]
284-
bit_depth = site_metadata["bit_depth"][0]
281+
pixel_size_z = site_metadata["pixel_size_z"].iloc[0]
282+
pixel_size_y = site_metadata["pixel_size_y"].iloc[0]
283+
pixel_size_x = site_metadata["pixel_size_x"].iloc[0]
284+
bit_depth = site_metadata["bit_depth"].iloc[0]
285285

286286
if min(pixel_size_z, pixel_size_y, pixel_size_x) < 1e-9:
287287
raise ValueError(pixel_size_z, pixel_size_y, pixel_size_x)

fractal_tasks_core/tasks/cellvoyager_to_ome_zarr_init_multiplex.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -303,10 +303,10 @@ def cellvoyager_to_ome_zarr_init_multiplex(
303303
site_metadata.set_index(["well_id", "FieldIndex"], inplace=True)
304304

305305
# Extract pixel sizes and bit_depth
306-
pixel_size_z = site_metadata["pixel_size_z"][0]
307-
pixel_size_y = site_metadata["pixel_size_y"][0]
308-
pixel_size_x = site_metadata["pixel_size_x"][0]
309-
bit_depth = site_metadata["bit_depth"][0]
306+
pixel_size_z = site_metadata["pixel_size_z"].iloc[0]
307+
pixel_size_y = site_metadata["pixel_size_y"].iloc[0]
308+
pixel_size_x = site_metadata["pixel_size_x"].iloc[0]
309+
bit_depth = site_metadata["bit_depth"].iloc[0]
310310

311311
if min(pixel_size_z, pixel_size_y, pixel_size_x) < 1e-9:
312312
raise ValueError(pixel_size_z, pixel_size_y, pixel_size_x)

tests/test_unit_ROIs.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,6 @@ def get_metadata_dataframe():
135135
"level,coarsening_xy,full_res_pxl_sizes_zyx", list_params
136136
)
137137
def test_ROI_indices_3D(level, coarsening_xy, full_res_pxl_sizes_zyx):
138-
139138
metadata_dataframe = get_metadata_dataframe()
140139
adata = prepare_FOV_ROI_table(metadata_dataframe)
141140
assert list(adata.obs_names) == FOV_NAMES
@@ -193,7 +192,6 @@ def test_ROI_indices_3D(level, coarsening_xy, full_res_pxl_sizes_zyx):
193192
"level,coarsening_xy,full_res_pxl_sizes_zyx", list_params
194193
)
195194
def test_ROI_indices_2D(level, coarsening_xy, full_res_pxl_sizes_zyx):
196-
197195
metadata_dataframe = get_metadata_dataframe()
198196
adata = prepare_FOV_ROI_table(metadata_dataframe)
199197
adata = convert_ROIs_from_3D_to_2D(adata, PIXEL_SIZE_Z)
@@ -238,7 +236,6 @@ def test_prepare_well_ROI_table(testdata_path: Path):
238236

239237

240238
def test_overlaps_in_indices():
241-
242239
list_indices = [
243240
[0, 1, 100, 200, 1000, 2000],
244241
[0, 1, 200, 300, 1000, 2000],
@@ -478,7 +475,6 @@ def test_load_region_fail():
478475

479476

480477
def test_is_ROI_table_valid(tmp_path):
481-
482478
# Write valid table to a zarr group
483479
columns = EXPECTED_COLUMNS.copy()
484480
adata = ad.AnnData(np.ones((1, len(columns))))
@@ -576,9 +572,9 @@ def test_search_first_ROI(testdata_path: Path):
576572
)
577573
)
578574
full_res_pxl_sizes_zyx = [
579-
big_df["pixel_size_z"][0],
580-
big_df["pixel_size_y"][0],
581-
big_df["pixel_size_x"][0],
575+
big_df["pixel_size_z"].iloc[0],
576+
big_df["pixel_size_y"].iloc[0],
577+
big_df["pixel_size_x"].iloc[0],
582578
]
583579

584580
well_ids = big_df.well_id.unique()

0 commit comments

Comments
 (0)