Skip to content

Conversation

@hagenw
Copy link
Member

@hagenw hagenw commented Jan 24, 2026

As we require start and end values of a segmented index to be of type timedelta64[ns] we update audformat.assert_index() to not allow timedelta[s].

Summary by Sourcery

Require segmented index start and end levels to use nanosecond-resolution timedeltas and adjust tests accordingly.

Enhancements:

  • Tighten index validation to only accept 'timedelta64[ns]' for segmented index start and end levels.

Tests:

  • Update existing index tests to use nanosecond timedelta dtypes and add an expected-failure case for invalid timedelta units.

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Jan 24, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Tightens audformat.assert_index() to only accept segmented indices with timedelta64[ns]-typed start and end levels, and adjusts/extends tests to use and validate the stricter dtype requirement.

Flow diagram for stricter timedelta64_ns validation in assert_index

flowchart TD
    A[Call assert_index with index obj] --> B{Has level file, start, end?}
    B -- No --> Z[Raise ValueError: missing required levels]
    B -- Yes --> C{Is dtype of level file string?}
    C -- No --> D[Raise ValueError: Level file must contain values of type string]
    C -- Yes --> E{Is dtype of level start timedelta64_ns?}
    E -- No --> F[Raise ValueError: Level start must contain values of type timedelta64_ns]
    E -- Yes --> G{Is dtype of level end timedelta64_ns?}
    G -- No --> H[Raise ValueError: Level end must contain values of type timedelta64_ns]
    G -- Yes --> I[Index conforms to audformat]
Loading

File-Level Changes

Change Details Files
Restrict segmented index validation to require timedelta64[ns] for start and end levels.
  • Replace generic timedelta dtype checks with is_timedelta64_ns_dtype for the start and end levels of segmented indices.
  • Keep error messages explicit that start and end must be of type timedelta64[ns].
audformat/core/index.py
Align tests with the new timedelta64[ns] requirement and add a regression case for invalid units.
  • Cast pd.to_timedelta(..., unit='s') outputs used in test indices to timedelta64[ns] where they should be valid.
  • Add an xfail test case where start and end levels use timedelta64[s] to assert that such indices are rejected with ValueError.
  • Retain an existing xfail case where end is not a timedelta to ensure non-timedelta end continues to fail.
tests/test_index.py

Possibly linked issues

  • #Pand as 3.0.0 breaks timedelta precision: PR enforces timedelta64[ns] for segmented indices, directly addressing Pandas 3.0.0 timedelta precision changes mentioned in issue.

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

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • The new failing test only covers the case where both start and end are timedelta64[s]; consider adding a mixed-unit case (e.g., start as timedelta64[ns] and end as timedelta64[s]) to ensure the validation logic rejects partially valid indices as well.
  • Instead of chaining pd.to_timedelta(..., unit="s").astype("timedelta64[ns]") in multiple places, consider using a small helper or a direct TimedeltaIndex constructor to reduce repetition and make the intended dtype conversion clearer.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The new failing test only covers the case where both `start` and `end` are `timedelta64[s]`; consider adding a mixed-unit case (e.g., `start` as `timedelta64[ns]` and `end` as `timedelta64[s]`) to ensure the validation logic rejects partially valid indices as well.
- Instead of chaining `pd.to_timedelta(..., unit="s").astype("timedelta64[ns]")` in multiple places, consider using a small helper or a direct `TimedeltaIndex` constructor to reduce repetition and make the intended dtype conversion clearer.

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.

@codecov
Copy link

codecov bot commented Jan 24, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.0%. Comparing base (1fb9889) to head (47a5524).
⚠️ Report is 1 commits behind head on dev.

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

@hagenw hagenw merged commit a7fc80d into dev Jan 24, 2026
13 checks passed
@hagenw hagenw deleted the fix-assert-index branch January 24, 2026 09:48
hagenw added a commit that referenced this pull request Jan 24, 2026
* Require timedelta64[ns] in assert_index()

* Add tests for mixed cases
hagenw added a commit that referenced this pull request Jan 24, 2026
* pandas 3.0: segmented_index() and set_index_dtypes() (#490)

* Add failing test

* Make test pandas 3.0.0 compatible

* Fix set_index_dtypes() for pandas 3.0

* Add comment

* Fix doctests

* Update segmented_index()

* Use segmented_index in test

* Add test for segmented_index

* Avoid warning in testing.add_table() (#491)

* pandas 3.0: fix utils.hash() (#492)

* pandas 3.0: fix utils.hash()

* Fix comment

* Remove unneeded code

* Add more tests

* Preserve ordered setting

* Update comment

* Fix categorical dtype with Database.get() (#493)

* Fix categorical dtype with Database.get()

* Update tests

* Add additional test

* Improve code

* Clean up comment

* We converted to categorical data

* Simplify test

* Simplify string test

* Require timedelta64[ns] in assert_index() (#494)

* Require timedelta64[ns] in assert_index()

* Add tests for mixed cases

* pandas 3.0: fix doctests output
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