Skip to content

[Repo Assist] Add Series.pctChange and Frame.pctChange for percentage change calculations#610

Merged
dsyme merged 2 commits intomasterfrom
repo-assist/improve-pctchange-series-frame-2026-03-09-bce0ed3790e439ad
Mar 12, 2026
Merged

[Repo Assist] Add Series.pctChange and Frame.pctChange for percentage change calculations#610
dsyme merged 2 commits intomasterfrom
repo-assist/improve-pctchange-series-frame-2026-03-09-bce0ed3790e439ad

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot commented Mar 9, 2026

🤖 Repo Assist — automated AI improvement.

Summary

Adds Series.pctChange and Frame.pctChange functions that compute the relative (percentage) change between each value and the value at a given offset:

result[k] = (series[k] - series[k - offset]) / series[k - offset]

This is the standard way to compute financial returns (e.g. daily stock returns from a price series) and is the F# equivalent of pandas' pct_change.

Motivation

The homepage example (see #517) attempts to calculate daily returns using Frame.diff 1 / df, which is incorrect because diff gives the absolute change and dividing by df gives something subtly different from (df - shift(df,1)) / shift(df,1). A dedicated pctChange function removes this confusion and simplifies the idiomatic usage.

Before (current — from homepage docs):

let past = df |> Frame.diff 1
let rets = past / df * 100.0   // Wrong: divides diff by current, not by previous

After:

let rets = df |> Frame.pctChange 1   // Correct: (curr - prev) / prev

Changes

File Change
src/Deedle/SeriesModule.fs Add Series.pctChange inline function (SRTP, like Series.diff)
src/Deedle/FrameModule.fs Add Frame.pctChange function (float columns only, like Frame.diff); update module doc example
src/Deedle/SeriesExtensions.fs Add PctChange C# extension methods for float, float32, decimal
src/Deedle/FrameExtensions.fs Add PctChange C# extension method
tests/Deedle.Tests/Series.fs 3 new tests: basic, empty/short series, missing value propagation
tests/Deedle.Tests/Frame.fs 2 new tests: basic computation, empty frame

Test Status

✅ All 498 existing tests pass
✅ All 5 new pctChange tests pass
Build: no new warnings introduced by these changes

Generated by Repo Assist ·

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@30f2254f2a7a944da1224df45d181a3f8faefd0d

…ations

Adds Series.pctChange and Frame.pctChange functions that compute the
relative (percentage) change between a value and the value at a given
offset. The formula is:

    result[k] = (series[k] - series[k - offset]) / series[k - offset]

These functions follow the same design as Series.diff / Frame.diff,
and are commonly used in financial analysis to compute returns (e.g.
daily stock returns). C# extension methods PctChange() are also added
to SeriesExtensions and FrameExtensions.

Addresses the use-case raised in issue #517.

Co-authored-by: Copilot <[email protected]>
@dsyme dsyme marked this pull request as ready for review March 12, 2026 02:20
@dsyme dsyme merged commit 1aa0184 into master Mar 12, 2026
2 checks passed
@dsyme dsyme deleted the repo-assist/improve-pctchange-series-frame-2026-03-09-bce0ed3790e439ad branch March 12, 2026 02:20
@dsyme
Copy link
Copy Markdown
Member

dsyme commented Mar 14, 2026

/repo-assist check the documentation change has been made per above discussion, I don't see it in the merged PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant