Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Heuristic:1kbgz Tributary Window Negative Size Infinite

From Leeroopedia
Knowledge Sources
Domains Streaming, Optimization
Last Updated 2026-10-14 09:15 GMT

Overview

A `Window` with `size=-1` (or any negative value) creates an unbounded accumulator that retains all values; `size=0` passes values through without accumulation.

Description

The `Window` streaming transform in tributary uses a size parameter with special semantics:

  • `size=0`: No windowing — values pass through directly (`return val`).
  • `size=-1` (negative): Unbounded window — all values are accumulated in a list and returned each tick. The list grows indefinitely.
  • `size>0`: Bounded window — only the last `size` values are kept (`ret._accum[-size:]`).

When combined with `full_only=True`, the window only returns a value when the accumulator has exactly `size` elements; otherwise it returns `StreamNone()`. This is critical for indicators like SMA and EMA that require a full window before producing valid output.

Usage

Use this heuristic when:

  • Building rolling window transforms — use positive `size` for fixed-width windows.
  • Creating cumulative aggregates — use `size=-1` for running totals/averages.
  • Debugging indicators that return `StreamNone` — check if `full_only=True` and the window hasn't filled yet.
  • Understanding the `Window[size=∞]` label in graph visualizations (negative size displays as infinity).

The Insight (Rule of Thumb)

  • Action: Set `size=-1` for unbounded accumulation (all history), `size>0` for sliding windows, `size=0` for pass-through.
  • Value: Negative = infinite window; zero = no window; positive = sliding window of N elements.
  • Trade-off: Negative size windows grow unboundedly in memory; use positive size for memory-bounded streaming.
  • Compatibility: The `Window` transform is composed by `SMA`, `EMA`, and other rolling calculations via `node.window(size, full_only).apply(func)`.

Reasoning

The window size determines the memory and computation characteristics of the transform. A bounded window (`size>0`) trims the accumulator list to the last N elements, keeping memory constant. An unbounded window (`size=-1`) keeps all history, which is useful for running aggregates like `RollingSum` and `RollingAverage` but dangerous for long-running streams. The `full_only` flag gates output until the window is complete, preventing partial/invalid indicator values from propagating downstream.

The window name in graph visualization shows `Window[∞]` for negative sizes, making unbounded windows visible in debugging.

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment