Skip to content
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

Minor fixes in MIMIC_example #224

Merged
merged 2 commits into from
Nov 12, 2024
Merged

Minor fixes in MIMIC_example #224

merged 2 commits into from
Nov 12, 2024

Conversation

prenc
Copy link
Collaborator

@prenc prenc commented Nov 12, 2024

Summary by CodeRabbit

  • New Features

    • Enhanced file retrieval method to include all subdirectories, improving data access.
    • Updated function calls for reading files to ensure compatibility with various file types.
  • Bug Fixes

    • Streamlined error handling for file reading, ensuring the correct function is used for each file type.
  • Documentation

    • Improved logging for better clarity on operations performed during the data wrangling process.

Copy link
Contributor

coderabbitai bot commented Nov 12, 2024

Walkthrough

The changes in this pull request focus on the pre_MEDS.py script, specifically within the main function responsible for data wrangling for MIMIC-IV. Key modifications include enhancing file retrieval methods to support recursive directory searches, updating function calls to ensure the correct reading functions are used based on file types, streamlining error handling for file reading, and improving the consistency of logging statements to reflect these changes.

Changes

File Path Change Summary
MIMIC-IV_Example/pre_MEDS.py - Updated file retrieval from input_dir.glob("**/*.*") to input_dir.rglob("*/*.*") for recursive search.
- Replaced read_fn with df_to_load_read_fn for specific file types in two instances.
- Streamlined error handling by consistently using appropriate reading functions from get_supported_fp.
- Enhanced logging statements for consistency with new function calls.

Possibly related PRs

  • eICU example #207: Modifications in eICU_Example/pre_MEDS.py related to file path adjustments for loading configurations, which connects to the file handling changes in the pre_MEDS.py script in this PR.

🐇 In the meadow, files do twirl,
With rglob's magic, they unfurl.
Data dances, logs align,
Reading functions, oh so fine!
In the script, a joyful cheer,
MIMIC-IV, we hold you dear! 🌼


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@@ -229,7 +229,7 @@ def main(cfg: DictConfig):
)
exit(0)

all_fps = list(input_dir.glob("**/*.*"))
all_fps = list(input_dir.rglob("*/*.*"))
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Allows to properly find files if subdirs are symbolic links

Copy link

codecov bot commented Nov 12, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.17%. Comparing base (04c82a6) to head (069b2b9).
Report is 4 commits behind head on main.

✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #224   +/-   ##
=======================================
  Coverage   99.17%   99.17%           
=======================================
  Files          27       27           
  Lines        2055     2055           
=======================================
  Hits         2038     2038           
  Misses         17       17           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (2)
MIMIC-IV_Example/pre_MEDS.py (2)

302-304: Consider improving the file reading logic

While the optimization for .csv.gz files is good, consider these improvements:

  1. Apply column selection optimization to other compatible file types
  2. Extract the common read logic to reduce duplication
  3. Add error handling for file read operations

Here's a suggested refactor:

-        if df_to_load_fp.suffix in [".csv.gz"]:
-            df = df_to_load_read_fn(df_to_load_fp, columns=cols)
-        else:
-            df = df_to_load_read_fn(df_to_load_fp)
+        try:
+            read_kwargs = {"columns": cols} if df_to_load_fp.suffix in [".csv", ".csv.gz"] else {}
+            df = df_to_load_read_fn(df_to_load_fp, **read_kwargs)
+        except Exception as e:
+            logger.error(f"Failed to read {df_to_load_fp}: {str(e)}")
+            raise

Line range hint 232-304: Consider adding data validation for medical records

Since this script processes sensitive medical data (ICD codes, diagnoses, procedures), consider adding validation to ensure data integrity:

  1. Validate file checksums against expected values
  2. Add basic sanity checks for medical record formats
  3. Log any data anomalies for review

Would you like me to provide examples of data validation implementations for MIMIC-IV records?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between f38901d and 069b2b9.

📒 Files selected for processing (1)
  • MIMIC-IV_Example/pre_MEDS.py (2 hunks)
🔇 Additional comments (1)
MIMIC-IV_Example/pre_MEDS.py (1)

232-232: Verify the file pattern change doesn't break MIMIC-IV file discovery

The change from glob("**/*.*") to rglob("*/*.*") is more restrictive as it requires files to be in at least one subdirectory. This could potentially miss files placed directly in the input directory.

Let's verify the MIMIC-IV file structure:

✅ Verification successful

Let me generate additional verification scripts to check the actual MIMIC-IV file structure pattern:

This will help us understand the expected MIMIC-IV file structure and verify if the new pattern is compatible.


Based on the search results, I can now generate the final response:

The file pattern change is safe and intentional

The change from glob("**/*.*") to rglob("*/*.*") is actually correct for MIMIC-IV data structure. From the documentation and configuration files, we can see that:

  1. MIMIC-IV raw files are always organized in subdirectories (e.g., 'hosp' and 'icu' subdirectories are required)
  2. The README explicitly states: "there should be a hosp and icu subdirectory of $MIMICIV_RAW_DIR"
  3. The metadata files are also placed in subdirectories as shown by the file structure

The new pattern rglob("*/*.*") correctly enforces this expected directory structure, making the code more robust by failing early if files are not organized as required by MIMIC-IV.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if any MIMIC-IV files exist directly in the input directory
# that would be missed by the new pattern

# Find files directly in input_dir (depth=1)
fd --max-depth 1 --type f . --exec echo "Files that would be missed: {}"

# Compare with files in subdirectories (depth>1)
fd --min-depth 2 --type f . --exec echo "Files that would be found: {}"

Length of output: 9014


Script:

#!/bin/bash
# Search for any references to MIMIC-IV file paths or directory structure
rg -i "mimic.*(csv|file|dir|path)" -A 2

# Check the configuration files for MIMIC-IV
cat MIMIC-IV_Example/configs/extract_MIMIC.yaml

Length of output: 8040

@prenc prenc requested a review from mmcdermott November 12, 2024 00:59
@mmcdermott mmcdermott merged commit 553250e into main Nov 12, 2024
9 checks passed
@mmcdermott mmcdermott deleted the mimic-premeds-minor-fixes branch November 12, 2024 15:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants