Skip to content

Conversation

@strixy16
Copy link
Collaborator

@strixy16 strixy16 commented Jan 13, 2026

Summary by CodeRabbit

  • Bug Fixes
    • Scan handling improved so scans with undefined or non-numeric slice-spacing metadata are safely skipped from spacing corrections, preventing incorrect direction adjustments and related image-processing errors.

✏️ Tip: You can customize this high-level summary in your review settings.

@strixy16 strixy16 requested a review from JoshuaSiraj January 13, 2026 15:28
@strixy16 strixy16 linked an issue Jan 13, 2026 that may be closed by this pull request
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 13, 2026

📝 Walkthrough

Walkthrough

Guard added to Scan._fix_direction to skip numeric parsing and subsequent negative-spacing correction when metadata SpacingBetweenSlices is missing or non-numeric; the method now retrieves the raw value, attempts float conversion, and returns early on absence or failed conversion.

Changes

Cohort / File(s) Summary
Metadata spacing guard
src/imgtools/coretypes/imagetypes/scan.py
_fix_direction now retrieves SpacingBetweenSlices as raw_spacing, attempts float() conversion only if present, and returns early on missing or non-numeric values, avoiding previous unconditional parsing and negative-spacing handling. Area to review: consistent normalization of undefined (None) vs string values (e.g., "None") and whether a centralized metadata-normalization helper is warranted for maintainability.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: handling an undefined SpacingBetweenSlices tag in the _fix_direction method.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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

🧹 Nitpick comments (1)
src/imgtools/coretypes/imagetypes/scan.py (1)

71-75: Consider a more robust check for non-numeric values.

The guard for string 'None' addresses the immediate issue, but other non-numeric string values could still cause a ValueError on line 76. A try-except approach would be more defensive:

Also, minor nit: there's trailing whitespace on line 74.

♻️ Suggested improvement for robustness
         # Check if "SpacingBetweenSlices" is undefined - it's an optional tag so this is possible
         # https://dicom.innolitics.com/ciods/ct-image/image-plane/00180088
-        if self.metadata.get('SpacingBetweenSlices') == 'None':
-            return 
-        
-        slice_spacing = float(self.metadata.get("SpacingBetweenSlices") or 0)
+        raw_spacing = self.metadata.get("SpacingBetweenSlices")
+        try:
+            slice_spacing = float(raw_spacing) if raw_spacing else 0.0
+        except (ValueError, TypeError):
+            # SpacingBetweenSlices is undefined or not a valid numeric value
+            return
+
         if (not slice_spacing) or (slice_spacing >= 0):
             return

This handles any non-numeric value (not just 'None') and removes the trailing whitespace.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6def068 and 47cc736.

📒 Files selected for processing (1)
  • src/imgtools/coretypes/imagetypes/scan.py
🧰 Additional context used
📓 Path-based instructions (1)
src/**/*.py

⚙️ CodeRabbit configuration file

Review the Python code for compliance with PEP 8 and PEP 257 (docstring conventions). Ensure the following: - Variables and functions follow meaningful naming conventions. - Docstrings are present, accurate, and align with the implementation. - Code is efficient and avoids redundancy while adhering to DRY principles. - Consider suggestions to enhance readability and maintainability. - Highlight any potential performance issues, edge cases, or logical errors. - Ensure all imported libraries are used and necessary.

Files:

  • src/imgtools/coretypes/imagetypes/scan.py
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Build-Docs (ubuntu-latest, docs)

@codecov
Copy link

codecov bot commented Jan 13, 2026

Codecov Report

❌ Patch coverage is 0% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 54.60%. Comparing base (ee4d7c7) to head (d60dac0).
⚠️ Report is 10 commits behind head on main.

Files with missing lines Patch % Lines
src/imgtools/coretypes/imagetypes/scan.py 0.00% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #435      +/-   ##
==========================================
- Coverage   54.65%   54.60%   -0.06%     
==========================================
  Files          66       66              
  Lines        4314     4318       +4     
==========================================
  Hits         2358     2358              
- Misses       1956     1960       +4     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@strixy16 strixy16 merged commit 9e73f82 into main Jan 29, 2026
26 of 28 checks passed
@strixy16 strixy16 deleted the katys/fix-spacingbetweenslices-undefined branch January 29, 2026 17:27
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.

Scan fails to load when SpacingBetweenSlices is undefined

3 participants