-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed FutureWarning in Series.pct_change by specifying fill_method=None to avoid deprecated default behavior. #54
base: main
Are you sure you want to change the base?
Conversation
…ne to avoid deprecated default behavior.
My review is in progress 📖 - I will have feedback for you in a few minutes! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have reviewed your code and found 2 potential issues. To discuss my individual comments that I have added, tag me in replies using @korbit-ai.
Please react with a 👍 to my comments that you find helpful and a 👎 to those you find unhelpful - this will help me learn and improve as we collaborate.
@@ -208,9 +210,9 @@ def _prepare_returns(data, rf=0.0, nperiods=None): | |||
if isinstance(data, _pd.DataFrame): | |||
for col in data.columns: | |||
if data[col].dropna().min() >= 0 and data[col].dropna().max() > 1: | |||
data[col] = data[col].pct_change() | |||
data[col] = data[col].pct_change(fill_method=None) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change to use pct_change(fill_method=None)
addresses the FutureWarning, but we should consider if this is the optimal approach for all scenarios. In some cases, we might want to fill NaN values differently. Consider adding a parameter to the functions that use pct_change()
to allow customization of the fill_method
when necessary. This would provide more flexibility while still addressing the deprecation warning.
@@ -208,9 +210,9 @@ def _prepare_returns(data, rf=0.0, nperiods=None): | |||
if isinstance(data, _pd.DataFrame): | |||
for col in data.columns: | |||
if data[col].dropna().min() >= 0 and data[col].dropna().max() > 1: | |||
data[col] = data[col].pct_change() | |||
data[col] = data[col].pct_change(fill_method=None) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changes in this pull request involve the use of the 'fill_method' parameter in the 'pct_change()' function. It's important to ensure that the function behaves as expected when different arguments are passed to this parameter. I recommend adding parameterized tests to verify this. These tests should cover all possible values that could be passed to the 'fill_method' parameter.
For both issues, considering the apllication (_prepare_returns function), and considering the code following it modifcations handle missing values adequately, I believe the 'fill_method=None' is appropriate. It wouldn't make sense to pad (or forward-fill) percentage changes. |
Resolved FutureWarning in Series.pct_change in
quantstats_lumi/utils.py
,quantstats_lumi/_plotting/core.py
andquantstats_lumi/_plotting/wrappers.py
by specifying fill_method=None. The default behaviour (fill_method='pad' frompandas.pct_change()
) is deprecated and will be removed in a future version, which could cause issues with NA values. By setting fill_method=None, we ensure that NA values are not filled, avoiding potential errors.Description by Korbit AI
Note
This feature is in early access. You can enable or disable it in the Korbit Console.
What change is being made?
Specify
fill_method=None
inSeries.pct_change
calls to avoid deprecated default behavior and fix FutureWarning.Why are these changes being made?
The default behavior of
Series.pct_change
is deprecated, and specifyingfill_method=None
ensures future compatibility and removes the FutureWarning. This change improves code robustness and clarity by explicitly defining the fill method.