Skip to content

Use strict index hash for caching - #204

Merged
audeerington merged 8 commits into
mainfrom
use_strict_hash
Jul 24, 2026
Merged

Use strict index hash for caching#204
audeerington merged 8 commits into
mainfrom
use_strict_hash

Conversation

@audeerington

@audeerington audeerington commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Closes #203

Switch to using audformat.utils.hash(index, strict=True) for storing process results in a cache file.

This also adds a test that checks whether the returned index is as expected when the same index but with different order has already been cached.

@sourcery-ai

sourcery-ai Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Switches cache key generation for process_index to use a strict audformat index hash and adds regression coverage to ensure index ordering and cache reuse behave correctly when processing indices in different orders.

Sequence diagram for process_index caching with strict index hash

sequenceDiagram
    participant Caller
    participant process_index
    participant audformat_utils as audformat.utils
    participant CacheFile

    Caller->>process_index: process_index(index, cache_root)
    alt cache_root is not None
        process_index->>audformat_utils: hash(index, strict=True)
        audformat_utils-->>process_index: hash
        process_index->>CacheFile: check os.path.exists(cache_path)
        alt cache file exists
            process_index->>CacheFile: load cached result
            CacheFile-->>process_index: cached result
        else cache file missing
            process_index->>process_index: compute result
            process_index->>CacheFile: save result
        end
    else cache_root is None
        process_index->>process_index: compute result without cache
    end
    process_index-->>Caller: result
Loading

File-Level Changes

Change Details Files
Use strict audformat index hashing for cache file naming in process_index.
  • Change process_index to compute cache hash with audformat.utils.hash(index, strict=True) instead of the default non-strict hash.
  • Keep cache_root creation and cache_path naming logic the same aside from the stricter hash call.
audinterface/core/process.py
Add regression test to validate cache behavior and index preservation when processing the same index in different orders.
  • Introduce an index_durations helper to compute durations for index elements using audformat segmented indices.
  • Add test_process_index_order to pre-generate audio files, run process_index twice (original and reversed index), and assert that the returned index and signals match expectations with and without preserve_index for filewise and segmented indices.
  • Use parametrization over index types, durations, and preserve_index to cover multiple cache and index-order scenarios.
  • Minorly adjust some existing pytest parametrize argument strings for formatting consistency.
tests/test_process.py

Assessment against linked issues

Issue Objective Addressed Explanation
#203 Use a strict index hash (audformat.utils.hash(index, strict=True)) for cache file naming so that index order changes result in different cache files.
#203 Add test coverage to ensure that when an index with the same elements but different order is processed with caching, the returned index and corresponding features are in the expected order.

Possibly linked issues


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

@codecov

codecov Bot commented Jul 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.0%. Comparing base (8264e46) to head (6f288da).

Additional details and impacted files
Files with missing lines Coverage Δ
audinterface/core/feature.py 100.0% <100.0%> (ø)
audinterface/core/process.py 100.0% <100.0%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@audeerington
audeerington marked this pull request as ready for review July 23, 2026 13:51

@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 is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@audeerington
audeerington requested a review from hagenw July 23, 2026 13:54
@hagenw

hagenw commented Jul 23, 2026

Copy link
Copy Markdown
Member

Unfortunately, audinterface.Features does not simply inherit everything from audinterface.Process, but has it's own code for certain things as the hashing at

hash = audformat.utils.hash(index)

There you have to change it as well and add an extra test for audinterface.Feature.process_index().

Comment thread tests/test_process.py
@audeerington

Copy link
Copy Markdown
Contributor Author

Unfortunately, audinterface.Features does not simply inherit everything from audinterface.Process, but has it's own code for certain things as the hashing at

hash = audformat.utils.hash(index)

There you have to change it as well and add an extra test for audinterface.Feature.process_index().

Thanks, that would have been bad to miss! I now added a test and change for audinterface.Feature as well.

@audeerington
audeerington merged commit 64f94a3 into main Jul 24, 2026
20 checks passed
@audeerington
audeerington deleted the use_strict_hash branch July 24, 2026 07:26
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.

Use strict hash for caching

2 participants