Skip to content

Restore ResampledTSDF intermediate object to prevent invalid post-resample operations#461

Open
R7L208 wants to merge 7 commits intov0.2-integrationfrom
issue-458-resampled-tsdf
Open

Restore ResampledTSDF intermediate object to prevent invalid post-resample operations#461
R7L208 wants to merge 7 commits intov0.2-integrationfrom
issue-458-resampled-tsdf

Conversation

@R7L208
Copy link
Collaborator

@R7L208 R7L208 commented Mar 4, 2026

Changes

Introduces a ResampledTSDF composition-based wrapper (like Spark's GroupedData) that only exposes valid post-resample operations (interpolate, as_tsdf, show). This prevents chained operations like .filter() after .resample() from silently invalidating resample context while metadata travels forward to .interpolate(), producing wrong results.

Key changes:

  • New ResampledTSDF class (tempo/resampled.py): read-only wrapper with interpolate(), as_tsdf(), show(), and __repr__
  • TSDF.__init__/__withTransformedDF: removed mutable resample_freq/resample_func attributes
  • TSDF.resample() and resample.resample(): now return ResampledTSDF instead of TSDF
  • TSDF.interpolate(): simplified to delegate through self.resample(...).interpolate(...)
  • calc_bars() in both tsdf.py and stats.py: calls .as_tsdf() after each resample()
  • __init__.py: exports ResampledTSDF

Linked issues

Resolves #458

Functionality

  • added a new Class method
  • modified existing Class method: TSDF.__init__, TSDF.__withTransformedDF, TSDF.resample, TSDF.interpolate, TSDF.calc_bars
  • modified existing function: resample.resample, stats.calc_bars
  • added a new test
  • added a new utility

Tests

  • manually tested
  • added unit tests
    • test_resample_returns_resampled_tsdf — verifies return type and as_tsdf() escape hatch
    • test_tsdf_resample_returns_resampled_tsdf — verifies TSDF.resample() return type
    • test_resampled_tsdf_blocks_invalid_operations — verifies AttributeError on .filter(), .withColumn(), etc.
    • test_resampled_tsdf_repr — verifies descriptive __repr__
    • test_resample_then_interpolate_chain — verifies tsdf.resample(freq, func).interpolate(method) works end-to-end

R7L208 and others added 4 commits March 3, 2026 22:36
…ample operations (#458)

Introduces a ResampledTSDF composition-based wrapper (like Spark's GroupedData)
that only exposes valid post-resample operations (interpolate, as_tsdf, show),
preventing chained operations like .filter() from silently invalidating resample
context. Removes mutable resample_freq/resample_func attributes from TSDF.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add TYPE_CHECKING import for TSDF in resampled.py to resolve
forward-reference lint errors, and apply black formatting to 30 files.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Fix mypy no-untyped-def errors for df and ts_schema properties.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@R7L208 R7L208 requested a review from tnixon March 4, 2026 16:13
@codecov
Copy link

codecov bot commented Mar 4, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 78.55%. Comparing base (f022563) to head (93955c3).
⚠️ Report is 152 commits behind head on v0.2-integration.

Additional details and impacted files
@@                 Coverage Diff                  @@
##           v0.2-integration     #461      +/-   ##
====================================================
- Coverage             85.46%   78.55%   -6.92%     
====================================================
  Files                     6       31      +25     
  Lines                   757     2840    +2083     
  Branches                156      469     +313     
====================================================
+ Hits                    647     2231    +1584     
- Misses                   92      450     +358     
- Partials                 18      159     +141     

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

R7L208 and others added 3 commits March 4, 2026 09:17
Disambiguate the confusingly similar resample.py and resampled.py
file names by renaming the wrapper class module to resample_result.py.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Cover property accessors, show(), repr completeness, interpolate
branches (zero, ffill, bfill, null, target_cols, show_interpolated
warning), and as_tsdf() usability. Adds shared interpolation test
data to resample_tests.json.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Covers the method="linear" branch (line 103) and the else fallback
for unknown method strings (line 113) in resample_result.py.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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