Skip to content

Preserve signal crop origins with nested segmentation - #210

Open
antonsoo wants to merge 1 commit into
audeering:mainfrom
antonsoo:fix/segment-signal-time-levels
Open

antonsoo wants to merge 1 commit into
audeering:mainfrom
antonsoo:fix/segment-signal-time-levels

Conversation

@antonsoo

Copy link
Copy Markdown

Segment.process_signal() converts the requested start again after the underlying Process has already normalized it. This second conversion loses the sampling rate for sample-count strings and propagates NaT instead of the normalized zero origin. It also assumes the callback result has only two levels: a nested Segment.process_signal callback receives the file argument and returns a file/start/end index, so offsetting level 0 raises on the filename strings.

Use the normalized origin from the Process result and shift only the named start/end levels. Preserve row order and any file metadata. The regression covers direct/nested callbacks, tagged/untagged signals, missing starts, sample strings and nanosecond precision, with deliberately non-monotonic end times.

Related to #117; its original file-index example already works on current main. This change repairs the remaining in-memory crop path and is independent of #209's file-input correction.

Validation:

  • Full pytest: 696 passed, 54 xfailed, 100% coverage.
  • All configured pre-commit checks pass.
  • 44 recorded-speech configurations match independent sample/timestamp and mean-square references. All 16 failing calls are restored, and all 28 working control records remain identical.

Use the normalized Process result origin and shift only the named time levels. This handles missing and sample-count starts and preserves file metadata returned by nested process_signal callbacks.
@sourcery-ai

sourcery-ai Bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Repairs signal cropping so nested and direct segmentation callbacks use the Process-normalized origin, correctly offset only start/end timestamp levels, and preserve file metadata and result ordering across supported start formats.

Sequence diagram for normalized signal crop offsets

sequenceDiagram
    participant Caller
    participant Segment
    participant Process
    participant Callback

    Caller->>Segment: process_signal(signal, sampling_rate, start, end)
    Segment->>Process: process_signal(signal, sampling_rate, start, end)
    Process->>Callback: process_func(signal)
    Callback-->>Process: index with start/end levels
    Process-->>Segment: y with normalized start origin
    Segment->>Segment: shift start and end levels by y.index start
    Segment-->>Caller: indexed result preserving file metadata and row order
Loading

File-Level Changes

Change Details Files
Use the normalized crop origin returned by the underlying process and apply it only to the named time levels.
  • Retain the full process result before extracting its index.
  • Derive the effective start from the normalized result, avoiding a second conversion of sample-count strings and missing values.
  • Shift named start/end levels rather than assuming they occupy levels 0 and 1.
  • Preserve row order and any file metadata while offsetting timestamps.
audinterface/core/segment.py
Add regression coverage for normalized starts and nested callback index structures.
  • Cover direct and nested callbacks with tagged and untagged results.
  • Validate missing, numeric, sample-string, timedelata, and nanosecond-precision starts.
  • Verify file metadata and non-monotonic end-time row order are preserved.
tests/test_segment.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hey - I've reviewed your changes and they look great!

Sourcery assessment

Approved.


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

This branch has not been deployed

No deployments
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.

1 participant