Skip to content

docs(tsal): add UDF correctness rules and prefer native functionality over UDFs - #133

Merged
tombonfert merged 4 commits into
mainfrom
feature/tsal-skill-update
Oct 23, 2026
Merged

tombonfert merged 4 commits into
mainfrom
feature/tsal-skill-update

Conversation

@tombonfert

Copy link
Copy Markdown
Collaborator

Summary

Adds guidance to help users and agents write correct UDFs, and to avoid UDFs when Impulse's native functionality is enough.

Changes

  • UDF rules for UDFs that take a SampleSeries input, added to the impulse-tsal skill and to defining_expressions.md:
    • Handle empty inputs: UDFs run once at planning time, with every series input empty.
    • Return the same type on every path: the planning result fixes the output column type.
    • Respect gaps: compute logic that compares neighbouring samples per contiguous segment, using continuous_interval_indices.
    • Synchronize before combining raw arrays: use synchronized() / synchronized_all() when working on the arrays of several series.
  • Prefer native functionality: a new rule in the impulse and impulse-tsal skills. Agents should first check whether a request can be built from TSAL operators and methods, event types, aggregation classes or calculated channels, and use a UDF only for the part native functionality cannot express.
  • Example: a short magnitude(x, y) UDF showing synchronization. It also works on empty inputs.

…d return types

Document the rules users must follow when writing TSAL UDFs that accept
`SampleSeries`: handle empty planning-time inputs, return a consistent
type on every branch, respect gaps via `continuous_interval_indices`, and
synchronize series before element-wise numpy operations. Include a
`magnitude` example using `synchronized()`. Update both the defining
expressions reference and the impulse-tsal skill.
Add a "Prefer native functionality" section to the impulse and impulse-tsal
skills advising users to exhaust native operators, signal methods, Intervals
methods, event types, and aggregation classes before falling back to UDFs.
Highlight that native operations handle empty inputs, gaps, and unaligned
channels and remain optimizable by the engine.
@tombonfert
tombonfert requested a review from a team as a code owner October 23, 2026 15:48
Update the TSAL UDF empty-input guidance in both the defining expressions
reference and the impulse-tsal skill to say that scalar-returning UDFs
should return `np.nan` (not `SampleSeries.empty()`), and that built-in
reducers already return NaN for empty series.
…ocks

Update the "Prefer native functionality" guidance in the impulse-tsal skill to include calculated channels (`impulse-channels`) alongside existing native options.
@codecov

codecov Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.30%. Comparing base (e3daaa4) to head (7f25044).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #133   +/-   ##
=======================================
  Coverage   90.30%   90.30%           
=======================================
  Files          68       68           
  Lines        6068     6068           
  Branches      758      758           
=======================================
  Hits         5480     5480           
  Misses        466      466           
  Partials      122      122           
Flag Coverage Δ
query_engine 86.80% <ø> (ø)
reporting 94.92% <ø> (ø)

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@tombonfert
tombonfert merged commit b032a71 into main Oct 23, 2026
6 checks passed
@tombonfert
tombonfert deleted the feature/tsal-skill-update branch October 23, 2026 17:39
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