Skip to content

Conversation

@d-chambers
Copy link
Contributor

@d-chambers d-chambers commented Nov 23, 2025

Description

This PR makes it so align_to_coord can, when using mode='full' allow for a patch where there is no overlap between all traces.

Checklist

I have (if applicable):

  • referenced the GitHub issue this PR closes.
  • documented the new feature with docstrings and/or appropriate doc page.
  • included tests. See testing guidelines.
  • added the "ready_for_review" tag once the PR is ready to be reviewed.

Summary by CodeRabbit

  • Improvements

    • Alignment behavior now supports a "full" mode for non-overlapping traces and gives clearer, mode-aware error messages when overlaps are required but missing.
    • Documentation and validation messages updated for readability and to reflect mode-specific behavior.
  • Tests

    • Added tests that verify behavior with non-overlapping shifts across modes, ensuring "full" succeeds while stricter modes report errors.

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

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 23, 2025

Walkthrough

Add a mode parameter to _get_shift_indices and propagate it through align_to_coord; allow out-of-bounds shifts when mode == "full", and raise ParameterError for missing overlaps in other modes. Add tests covering non-overlapping-shift behavior.

Changes

Cohort / File(s) Summary
Alignment function updates
dascore/proc/align.py
Add mode parameter to _get_shift_indices(coord_vals, dim, reverse, samples, mode); pass allow_out_of_bounds=mode == "full" to dim.get_next_index; catch ValueError and raise ParameterError when overlaps are missing for non-"full" modes; propagate mode through align_to_coord; update docstring and error text.
Tests for non-overlapping shifts
tests/test_proc/test_align.py
Add patch_non_overlapping_shifts fixture and test_align_no_overlap to assert ParameterError is raised for modes "valid" and "same" when traces do not overlap, and that mode == "full" succeeds (producing empty/dropped time-dimension after NaN removal).

Possibly related PRs

  • #582: Modifies dascore/proc/align.py and updates _get_shift_indices/align_to_coord behavior and signatures—direct overlap with these changes.
  • #561: Updates _get_shift_indices signature and shift-handling logic used by align_to_coord, affecting the same alignment code paths.

Pre-merge checks and finishing touches

❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Description check ❓ Inconclusive The description provides the core purpose but lacks issue reference, documentation confirmation, and test confirmation despite changes to code and tests. Check the GitHub issue checkbox if applicable, and verify that docstrings and tests were actually included in the changeset.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: enabling align_to_coord to handle non-overlapping traces.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch oob_align

Tip

📝 Customizable high-level summaries are now available in beta!

You can now customize how CodeRabbit generates the high-level summary in your pull requests — including its content, structure, tone, and formatting.

  • Provide your own instructions using the high_level_summary_instructions setting.
  • Format the summary however you like (bullet lists, tables, multi-section layouts, contributor stats, etc.).
  • Use high_level_summary_in_walkthrough to move the summary from the description to the walkthrough section.

Example instruction:

"Divide the high-level summary into five sections:

  1. 📝 Description — Summarize the main change in 50–60 words, explaining what was done.
  2. 📓 References — List relevant issues, discussions, documentation, or related PRs.
  3. 📦 Dependencies & Requirements — Mention any new/updated dependencies, environment variable changes, or configuration updates.
  4. 📊 Contributor Summary — Include a Markdown table showing contributions:
    | Contributor | Lines Added | Lines Removed | Files Changed |
  5. ✔️ Additional Notes — Add any extra reviewer context.
    Keep each section concise (under 200 words) and use bullet or numbered lists for clarity."

Note: This feature is currently in beta for Pro-tier users, and pricing will be announced later.


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.

@coderabbitai coderabbitai bot added the proc Related to processing module label Nov 23, 2025
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)
dascore/proc/align.py (1)

203-215: Add exception chaining for better error context.

The error handling logic is correct, but the re-raised exception should use exception chaining to preserve the original traceback and distinguish it from errors in exception handling.

Apply this diff:

-    except ValueError:
+    except ValueError as err:
         msg = (
             f"Trace shift with align_to_coord results in some traces with no "
             f"overlaps. This is only possible with mode = 'full' not {mode}."
         )
-        raise ParameterError(msg)
+        raise ParameterError(msg) from err

Based on static analysis hints (Ruff B904).

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5326c3e and 9a01cf1.

📒 Files selected for processing (2)
  • dascore/proc/align.py (4 hunks)
  • tests/test_proc/test_align.py (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
dascore/proc/align.py (2)
dascore/core/coords.py (1)
  • get_next_index (795-873)
dascore/exceptions.py (1)
  • ParameterError (26-27)
tests/test_proc/test_align.py (4)
dascore/proc/coords.py (1)
  • update_coords (228-253)
dascore/exceptions.py (1)
  • ParameterError (26-27)
dascore/proc/align.py (1)
  • align_to_coord (253-391)
dascore/proc/basic.py (1)
  • dropna (438-494)
🪛 Ruff (0.14.5)
dascore/proc/align.py

215-215: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling

(B904)

⏰ 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). (18)
  • GitHub Check: test_code_min_deps (ubuntu-latest, 3.13)
  • GitHub Check: test_code_min_deps (windows-latest, 3.12)
  • GitHub Check: test_code_min_deps (macos-latest, 3.13)
  • GitHub Check: test_code_min_deps (windows-latest, 3.13)
  • GitHub Check: test_code_min_deps (ubuntu-latest, 3.12)
  • GitHub Check: test_code (windows-latest, 3.11)
  • GitHub Check: test_code (windows-latest, 3.13)
  • GitHub Check: test_code (ubuntu-latest, 3.12)
  • GitHub Check: test_code (macos-latest, 3.12)
  • GitHub Check: test_code (ubuntu-latest, 3.13)
  • GitHub Check: test_code (windows-latest, 3.12)
  • GitHub Check: test_code (macos-latest, 3.13)
  • GitHub Check: test_code (ubuntu-latest, 3.10)
  • GitHub Check: test_code (macos-latest, 3.11)
  • GitHub Check: test_code (macos-latest, 3.10)
  • GitHub Check: test_code (windows-latest, 3.10)
  • GitHub Check: test_code (ubuntu-latest, 3.11)
  • GitHub Check: Run benchmarks
🔇 Additional comments (5)
dascore/proc/align.py (3)

192-192: LGTM! Function signature correctly extended.

The addition of the mode parameter enables mode-aware behavior as described in the PR objectives.


274-275: LGTM! Documentation clearly describes the new behavior.

The docstring update accurately reflects that mode "full" can handle non-overlapping traces, which is the core objective of this PR.


382-382: LGTM! Mode parameter correctly propagated.

The mode parameter is properly passed to _get_shift_indices, completing the mode-aware implementation.

tests/test_proc/test_align.py (2)

116-124: LGTM! Fixture correctly creates non-overlapping scenario.

The fixture effectively sets up a test case with shifts [0, 8, 16] on a 10-sample time dimension, ensuring the third trace is shifted beyond the available data range. This provides appropriate test coverage for the new mode='full' behavior.


390-401: LGTM! Comprehensive test coverage for non-overlapping traces.

The test correctly validates that:

  1. Modes "valid" and "same" raise ParameterError for non-overlapping traces
  2. Mode "full" succeeds even with non-overlapping traces
  3. The result contains no valid data after dropping NaNs

This aligns perfectly with the PR objectives.

@codecov
Copy link

codecov bot commented Nov 23, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.92%. Comparing base (5326c3e) to head (f2f11e1).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #585   +/-   ##
=======================================
  Coverage   99.92%   99.92%           
=======================================
  Files         129      129           
  Lines       11233    11237    +4     
=======================================
+ Hits        11225    11229    +4     
  Misses          8        8           
Flag Coverage Δ
unittests 99.92% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ 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.

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: 1

🧹 Nitpick comments (1)
dascore/proc/align.py (1)

192-192: Consider adding type annotation for consistency.

The mode parameter lacks a type annotation. For consistency with align_to_coord (line 255), consider adding Literal["full", "valid", "same"] to improve type safety.

Apply this diff to add type annotation:

-def _get_shift_indices(coord_vals, dim, reverse, samples, mode):
+def _get_shift_indices(coord_vals, dim, reverse, samples, mode: Literal["full", "valid", "same"]):
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9a01cf1 and 4a09d83.

📒 Files selected for processing (1)
  • dascore/proc/align.py (4 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
dascore/proc/align.py (2)
dascore/core/coords.py (1)
  • get_next_index (795-873)
dascore/exceptions.py (1)
  • ParameterError (26-27)
⏰ 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). (18)
  • GitHub Check: test_code_min_deps (windows-latest, 3.13)
  • GitHub Check: test_code_min_deps (windows-latest, 3.12)
  • GitHub Check: test_code_min_deps (macos-latest, 3.12)
  • GitHub Check: test_code_min_deps (ubuntu-latest, 3.13)
  • GitHub Check: test_code_min_deps (ubuntu-latest, 3.12)
  • GitHub Check: test_code (macos-latest, 3.13)
  • GitHub Check: test_code (windows-latest, 3.12)
  • GitHub Check: test_code (windows-latest, 3.13)
  • GitHub Check: test_code (windows-latest, 3.11)
  • GitHub Check: test_code (macos-latest, 3.12)
  • GitHub Check: test_code (ubuntu-latest, 3.13)
  • GitHub Check: test_code (macos-latest, 3.11)
  • GitHub Check: test_code (macos-latest, 3.10)
  • GitHub Check: test_code (ubuntu-latest, 3.12)
  • GitHub Check: test_code (windows-latest, 3.10)
  • GitHub Check: test_code (ubuntu-latest, 3.11)
  • GitHub Check: test_code (ubuntu-latest, 3.10)
  • GitHub Check: Run benchmarks
🔇 Additional comments (2)
dascore/proc/align.py (2)

203-215: Well-implemented error handling for non-overlapping traces.

The try-except block correctly enables out-of-bounds shifts when mode == "full" and provides clear error messages for other modes. The exception chaining with from err preserves debugging context.


382-382: All call sites correctly updated with the mode parameter.

Verification confirms there is only one call site to _get_shift_indices (line 382), and it correctly passes the mode parameter matching the updated function signature (line 192). No outstanding issues remain.

@codspeed-hq
Copy link

codspeed-hq bot commented Nov 23, 2025

CodSpeed Performance Report

Merging #585 will not alter performance

Comparing oob_align (f2f11e1) with master (5326c3e)

Summary

✅ 54 untouched
⏩ 2 skipped1

Footnotes

  1. 2 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

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 (2)
dascore/proc/align.py (2)

192-192: Add type hint and update docstring for the new mode parameter.

The function signature now includes a mode parameter, but it lacks a type hint and the docstring doesn't document what this parameter does. Adding mode: str (or mode: Literal["full", "valid", "same"]) would improve type safety, and updating the docstring would help future maintainers understand the parameter's purpose.

Apply this diff to add a type hint:

-def _get_shift_indices(coord_vals, dim, reverse, samples, mode):
+def _get_shift_indices(coord_vals, dim, reverse, samples, mode: str):

Consider also updating the docstring to document the mode parameter and its effect on allow_out_of_bounds.


203-215: The error handling logic is correct and aligns with the PR objectives.

The try/except block appropriately catches ValueError when traces don't overlap and allow_out_of_bounds=False, then converts it to a more informative ParameterError. The conditional allow_out_of_bounds=mode == "full" correctly enables out-of-bounds shifts only for mode='full'.

For slightly improved clarity, consider rephrasing the error message:

-        msg = (
-            f"Trace shift with align_to_coord results in some traces with no "
-            f"overlaps. This is only possible with mode = 'full' not {mode}."
-        )
+        msg = (
+            f"Trace shift with align_to_coord results in some traces with no "
+            f"overlaps. This is only possible with mode='full', but mode is '{mode}'."
+        )
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4a09d83 and f2f11e1.

📒 Files selected for processing (1)
  • dascore/proc/align.py (5 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
dascore/proc/align.py (2)
dascore/core/coords.py (1)
  • get_next_index (795-873)
dascore/exceptions.py (1)
  • ParameterError (26-27)
⏰ 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). (18)
  • GitHub Check: test_code_min_deps (macos-latest, 3.13)
  • GitHub Check: test_code_min_deps (ubuntu-latest, 3.12)
  • GitHub Check: test_code_min_deps (ubuntu-latest, 3.13)
  • GitHub Check: test_code_min_deps (windows-latest, 3.13)
  • GitHub Check: test_code_min_deps (macos-latest, 3.12)
  • GitHub Check: test_code_min_deps (windows-latest, 3.12)
  • GitHub Check: test_code (windows-latest, 3.12)
  • GitHub Check: test_code (windows-latest, 3.13)
  • GitHub Check: test_code (windows-latest, 3.11)
  • GitHub Check: test_code (macos-latest, 3.12)
  • GitHub Check: test_code (windows-latest, 3.10)
  • GitHub Check: test_code (ubuntu-latest, 3.12)
  • GitHub Check: test_code (macos-latest, 3.11)
  • GitHub Check: test_code (macos-latest, 3.10)
  • GitHub Check: test_code (ubuntu-latest, 3.11)
  • GitHub Check: test_code (ubuntu-latest, 3.10)
  • GitHub Check: test_code (ubuntu-latest, 3.13)
  • GitHub Check: Run benchmarks
🔇 Additional comments (2)
dascore/proc/align.py (2)

274-275: Docstring accurately reflects the new behavior.

The updated documentation correctly describes that mode='full' allows cases where traces do not overlap at all, which aligns with the functional changes introduced in this PR.


382-382: LGTM! Parameter propagation is correct.

The mode parameter is correctly passed from the align_to_coord function to _get_shift_indices, completing the propagation chain needed for the new functionality.

@d-chambers d-chambers merged commit efca919 into master Nov 25, 2025
24 checks passed
@d-chambers d-chambers deleted the oob_align branch November 25, 2025 01:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

proc Related to processing module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants