Skip to content
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

Fix FutureWarnings for Pandas Compatibility and Chained Assignment #273

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

SauersML
Copy link

@SauersML SauersML commented Apr 2, 2024

Changes Made:

  1. Pandas Timedelta Deprecation Warning:

    • Updated the use of "S" to "s" in pd.Timedelta to conform to the upcoming deprecation in pandas. This change fixes the FutureWarning regarding the deprecation of 'S' in favor of 's' for specifying seconds in pd.Timedelta.
    # Before:
    has_live_indice = index_utc[-1] >= last_trade - pd.Timedelta(2, "S")
    
    # After:
    has_live_indice = index_utc[-1] >= last_trade - pd.Timedelta(2, "s")
  2. Chained Assignment Warning:

    • Altered the approach to setting values in the DataFrame to avoid chained assignment, which is not recommended due to its unclear behavior in certain contexts (operations that behave as if they were on a copy.). This adjustment is in response to pandas' future change in how inplace=True will function.
    # Before:
    df["dividends"].fillna(0, inplace=True)

...
df["splits"].fillna(0, inplace=True)

After:

df["dividends"] = df["dividends"].fillna(0)
...
df["splits"] = df["splits"].fillna(0)

@SauersML SauersML mentioned this pull request Apr 2, 2024
@maread99
Copy link
Contributor

maread99 commented Apr 2, 2024

I believe this is a duplicate of #262, only difference being that this overwrites the 'dividends' and 'split' columns as opposed to undertaking the fillna operation in place. Changes in #262 are in line with the advices offered in the deprecation warning, although seems this PR would also do the trick.

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