Fix resampler chaining issue for compound returns in core.py #402
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.
Bug Fix: Resample Operation in quantstats/_plotting/core.py
Description
This PR fixes a small bug in
quantstats/_plotting/core.py
(lines 292–298), where resample operations were separated into two statements. That caused aDatetimeIndexResampler
object to be stored inreturns
orbenchmark
, triggering the error:What Changed
Before:
The
returns
andbenchmark
were first assigned to a resampler object and then incorrectly processed. This resulted in an error when attempting NumPy operations on the resampler object.Updated Implementation:
The resample and aggregation calls are now correctly chained. This approach ensures that
returns
andbenchmark
remain valid DataFrame/Series objects after resampling.Motivation for the Change
compound = True
,.last()
is applied to capture the final value for each resampled periodcompound = False
,.sum()
is applied to aggregate the values within each resampled periodBenefits
df.resample(...).sum()
Please review this PR and let me know if you have any feedback or suggestions! I am happy to make further improvements if needed.