yahooquery icon indicating copy to clipboard operation
yahooquery copied to clipboard

Fix FutureWarnings for Pandas Compatibility and Chained Assignment

Open ScottSauers opened this issue 1 year ago • 1 comments

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)

ScottSauers avatar Apr 02 '24 18:04 ScottSauers

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.

maread99 avatar Apr 02 '24 18:04 maread99