-
Notifications
You must be signed in to change notification settings - Fork 0
feat: fix loaders some more #98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
f300b6e
2841929
4c58b7f
1d84838
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -47,6 +47,7 @@ def loadFeatureFilesFromImageTypes(extracted_feature_dir:Union[Path|str], # noqa | |||||||||||||
logger.error(f"Extracted feature directory {extracted_feature_dir} does not exist.") | ||||||||||||||
raise FileNotFoundError() | ||||||||||||||
|
||||||||||||||
# Get list of all the csv files in the directory with their full paths | ||||||||||||||
feature_file_list = sorted(extracted_feature_dir.glob("*.csv")) | ||||||||||||||
|
||||||||||||||
# Loop through all the files in the directory | ||||||||||||||
|
@@ -69,17 +70,13 @@ def loadFeatureFilesFromImageTypes(extracted_feature_dir:Union[Path|str], # noqa | |||||||||||||
msg = f"Multiple {image_type} feature csv files found in {extracted_feature_dir}. First one will be used." | ||||||||||||||
logger.warning(msg) | ||||||||||||||
|
||||||||||||||
image_type_feature_file = matching_files[0] | ||||||||||||||
feature_file_path = matching_files[0] | ||||||||||||||
# Remove the image type file from the list of feature files | ||||||||||||||
feature_file_list.remove(image_type_feature_file) | ||||||||||||||
feature_file_list.remove(feature_file_path) | ||||||||||||||
|
||||||||||||||
except Exception as e: | ||||||||||||||
logger.warning(f"Error loading {image_type} feature csv files from {extracted_feature_dir}: {e}") | ||||||||||||||
raise e | ||||||||||||||
Comment on lines
77
to
79
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Improve error handling consistency The current error handling logs a warning and then raises the exception. This is inconsistent with other error handling in the function. Consider either:
- except Exception as e:
- logger.warning(f"Error loading {image_type} feature csv files from {extracted_feature_dir}: {e}")
- raise e
+ except Exception as e:
+ logger.error(f"Failed to process {image_type} feature files: {e}")
+ raise ValueError(f"Error processing {image_type} feature files: {e}") from e 📝 Committable suggestion
Suggested change
|
||||||||||||||
|
||||||||||||||
|
||||||||||||||
# Get the full path to the feature file | ||||||||||||||
feature_file_path = extracted_feature_dir / image_type_feature_file | ||||||||||||||
|
||||||||||||||
# Load the feature data into a pandas dataframe | ||||||||||||||
raw_feature_data = loadFileToDataFrame(feature_file_path) | ||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import pytest | ||
|
||
from pathlib import Path | ||
from readii.io.loaders.features import loadFeatureFilesFromImageTypes | ||
|
||
|
||
@pytest.fixture | ||
def extracted_feature_4D_lung(): | ||
return Path("tests/4D-lung/results/features/") | ||
|
||
def test_loadFeatureFilesFromImageTypes(extracted_feature_4D_lung): | ||
feature_sets = loadFeatureFilesFromImageTypes(extracted_feature_4D_lung, image_types=["original"], drop_labels=False) | ||
assert isinstance(feature_sets, dict), "Return should be a dictionary." | ||
assert len(feature_sets) == 1, "Should only have one feature file per image type." | ||
assert "original" in feature_sets, "Not finding the specified image type feature file (original) or keys are not correctly named." | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid modifying the feature_file_list during iteration
Modifying the list while processing it could lead to race conditions or missed files. Consider using a set or maintaining a separate list of processed files.
Also, consider adding this at the beginning of the function: