Conversation
…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]>
This was referenced Mar 9, 2026
Member
|
/repo-assist check the documentation change has been made per above discussion, I don't see it in the merged PR |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖 Repo Assist — automated AI improvement.
Summary
Adds
Series.pctChangeandFrame.pctChangefunctions that compute the relative (percentage) change between each value and the value at a given 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 becausediffgives the absolute change and dividing bydfgives something subtly different from(df - shift(df,1)) / shift(df,1). A dedicatedpctChangefunction removes this confusion and simplifies the idiomatic usage.Before (current — from homepage docs):
After:
Changes
src/Deedle/SeriesModule.fsSeries.pctChangeinline function (SRTP, likeSeries.diff)src/Deedle/FrameModule.fsFrame.pctChangefunction (float columns only, likeFrame.diff); update module doc examplesrc/Deedle/SeriesExtensions.fsPctChangeC# extension methods forfloat,float32,decimalsrc/Deedle/FrameExtensions.fsPctChangeC# extension methodtests/Deedle.Tests/Series.fstests/Deedle.Tests/Frame.fsTest Status
✅ All 498 existing tests pass
✅ All 5 new
pctChangetests passBuild: no new warnings introduced by these changes