Skip to content

Return NaN when a rolling window is longer than the series - #846

Merged
xmatthias merged 2 commits into
freqtrade:mainfrom
xvruipeng-cyber:fix/rolling-window-short-series
Oct 27, 2026
Merged

xmatthias merged 2 commits into
freqtrade:mainfrom
xvruipeng-cyber:fix/rolling-window-short-series

Conversation

@xvruipeng-cyber

Copy link
Copy Markdown
Contributor

Fixes #464

numpy_rolling_window built a negative shape when the input was shorter than window, so indicators such as the awesome oscillator crashed instead of warming up. Upstream qtpylib is archived, and this copy is now the one technical.qtpylib exports.

A short series now produces an empty window. The rolling reducer leaves the result as NaN, including the len(calculated) == 0 case where series[-0:] would otherwise replace the whole array. A complete window is unchanged.

Test plan

  • pytest tests/test_rolling_window.py (4 passed)
  • Awesome oscillator on a 3-row frame is all NaN
  • A 3-bar mean of a 4-bar series still returns the two finite values at the end

Made with Cursor

@xmatthias xmatthias added the AI Slop Issue or PR partially or completely generated by AI label Oct 22, 2026

@xmatthias xmatthias left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ci fails ... which is a requirement for obvious reasons.

Your tests are also kindof lacking some quite likely edge-cases - you'll want a test for len==window (essentially the "off by 1" regression test).

Comment thread tests/test_rolling_window.py Resolved
Ruff PLR1730 rejected the negative-count branch, which also failed the
distribution build. Clamp the window count with max, import the public
qtpylib helpers in tests, and lock the len == window off-by-one case.

Co-authored-by: xvruipeng-cyber <xvruipeng-cyber@users.noreply.github.com>
@xmatthias
xmatthias enabled auto-merge October 27, 2026 18:21

@xmatthias xmatthias left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM 👍

@xmatthias
xmatthias merged commit ee9918e into freqtrade:main Oct 27, 2026
63 of 68 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI Slop Issue or PR partially or completely generated by AI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error thrown at numpy_rolling_window

2 participants