Skip to content

fourier_features discarded the series it was handed - #46

Merged
stefan-jansen merged 1 commit into
mainfrom
fix/fourier-features-ignores-its-argument
Sep 9, 2026
Merged

fourier_features discarded the series it was handed#46
stefan-jansen merged 1 commit into
mainfrom
fix/fourier-features-ignores-its-argument

Conversation

@stefan-jansen

Copy link
Copy Markdown
Contributor

fourier_features(close, ...) evaluated pl.col(close) if isinstance(close, str) else close as a bare statement and threw the result away, then returned sin and cos of the row index. No price or other data has ever entered the output, while the docstring said it captured periodic patterns in price data.

The basis itself is a legitimate feature - Fourier seasonality terms - so the fix makes the function say what it does rather than change what it computes.

  • close is kept for callers that pass it, deprecated, and now warns that it is not read.
  • The basis is keyed on row position, not a timestamp, so it describes the intended cycle only where rows are sorted and regularly spaced. Across a weekend, a holiday or a filtered panel, position and time part company. Stated in the docstring.
  • period is in rows. The 390 default is one US equity session in one-minute bars and describes a 390-session cycle on daily bars, so defaulting it now warns.

The existing test checked feature names and the [-1, 1] bound, both of which hold for a function that ignores its input, which is why it passed throughout. Four tests replace it: output invariant under a reversed close and a rescaled feature column; one full cycle per period rows against a closed-form sine; and the two warnings.

3572 pass, 64 skipped.

Found by the band-c agent reviewing 09_model_based_features/05_spectral_features, whose prose described the function as capturing periodic structure in the price series - false of every version of it.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Sy1WqyZZTXcoyFYAjVbyiu

The function evaluated `pl.col(close) if isinstance(close, str) else close` as a
bare statement and threw the result away, then returned sin and cos of the row
index. No price or other data has ever entered the output, while the docstring
said it captured periodic patterns in price data. A caller reading that gets a
deterministic seasonal basis and believes it is a spectral summary of the series.

The basis itself is a legitimate feature, so the fix is to make the function say
what it does rather than to change what it computes. `close` is kept for callers
that pass it, deprecated, and now warns that it is not read.

Two traps stated rather than left implicit. The basis is keyed on row POSITION,
not on a timestamp, so it describes the intended cycle only where rows are sorted
and regularly spaced; across a weekend or a filtered panel, position and time part
company. And `period` is in rows: the 390 default is one US equity session in
one-minute bars and describes a 390-session cycle on daily bars, so defaulting it
now warns.

The existing test checked feature names and the [-1, 1] bound, both of which hold
for a function that ignores its input, which is why it passed throughout. Four
tests replace that: output invariant under a reversed close and a rescaled
feature column, one full cycle per period rows against a closed-form sine, and the
two warnings. 3572 pass.

Found by the band-c agent reviewing 09_model_based_features/05_spectral_features,
whose prose described the function as capturing periodic structure in the price
series - false of every version of it.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Sy1WqyZZTXcoyFYAjVbyiu
Copilot AI lite review requested due to automatic review settings September 9, 2026 00:08

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@stefan-jansen
stefan-jansen merged commit 8f4dace into main Sep 9, 2026
25 checks passed
@stefan-jansen
stefan-jansen deleted the fix/fourier-features-ignores-its-argument branch September 9, 2026 02:46
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