Skip to content

Commit

Permalink
🐛 Fix PLC0206 (#907)
Browse files Browse the repository at this point in the history
* 🐛 Fix PLC0206
- Fix PLC0206 Extracting value from dictionary without calling `.items()`
  • Loading branch information
shaneahmed authored Jan 24, 2025
1 parent 3d84a43 commit e93d98a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
8 changes: 3 additions & 5 deletions tiatoolbox/models/engine/engine_abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,13 +505,11 @@ def get_dataloader(
@staticmethod
def _update_model_output(raw_predictions: dict, raw_output: dict) -> dict:
"""Helper function to append raw output during inference."""
for key in raw_output:
for key, value in raw_output.items():
if raw_predictions[key] is None:
raw_predictions[key] = raw_output[key]
raw_predictions[key] = value
else:
raw_predictions[key] = np.append(
raw_predictions[key], raw_output[key], axis=0
)
raw_predictions[key] = np.append(raw_predictions[key], value, axis=0)

return raw_predictions

Expand Down
11 changes: 5 additions & 6 deletions tiatoolbox/utils/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1490,20 +1490,19 @@ def write_to_zarr_in_cache_mode(

# case 1 - new zarr group
if not zarr_group:
for key in output_data_to_save:
data_to_save = output_data_to_save[key]
for key, value in output_data_to_save.items():
# populate the zarr group for the first time
zarr_dataset = zarr_group.create_dataset(
name=key,
shape=data_to_save.shape,
shape=value.shape,
compressor=compressor,
)
zarr_dataset[:] = data_to_save
zarr_dataset[:] = value

return zarr_group

# case 2 - append to existing zarr group
for key in output_data_to_save:
zarr_group[key].append(output_data_to_save[key])
for key, value in output_data_to_save.items():
zarr_group[key].append(value)

return zarr_group

0 comments on commit e93d98a

Please sign in to comment.