ranaroussi / yfinance

Download market data from Yahoo! Finance's API
https://aroussi.com/post/python-yahoo-finance
Apache License 2.0
14.93k stars 2.45k forks source link

[Volume] FutureWarning: Setting an item of incompatible dtype is deprecated and will raise an error in a future version of pandas. #1992

Closed makamto closed 4 months ago

makamto commented 4 months ago

Describe bug

The code can still work, but it shows warning. I used yf.download(), it happens more often if the interval is set to 1d.

Simple code that reproduces your problem

def fetch_stock_data(tickers: List[str]) -> pd.DataFrame:
    """Fetch data of stock list using yfinance"""

    ticker_list = []

    for ticker in tickers:
        df = yf.download(
            ticker,
            interval="1wk",
            start="2020-01-01",
            repair=True,
            session=session,
        )
        df["Ticker"] = ticker
        ticker_list.append(df)
    df = pd.concat(ticker_list)
    df.reset_index(inplace=True)
    return df

Debug log

FutureWarning: Setting an item of incompatible dtype is deprecated and will raise an error in a future version of pandas. Value '[2.10625500e+07 1.67656485e+07 1.34876505e+07 1.91036985e+07 1.26580980e+07 2.04354495e+07 4.59354495e+07 2.04892005e+07 1.96474005e+07 1.06201005e+07 2.06118510e+07 2.38032990e+07 2.66502510e+07 3.82521000e+07 2.42962005e+07 1.75762005e+07 2.26345995e+07 2.45272995e+07 2.20944990e+07 2.21245515e+07 1.53963495e+07 1.66012500e+07 1.30546485e+07 2.24671500e+07 2.24748510e+07 1.81781520e+07 3.77269995e+07 2.00704995e+07 2.05397505e+07 1.92138000e+07 1.45547010e+07 1.88683500e+07 2.93336505e+07 2.48687505e+07 2.60209500e+07 1.76433510e+07 4.97940000e+07 2.67416490e+07 4.11957990e+07 6.77644005e+07 3.63142995e+07 2.85641010e+07 2.41101510e+07 3.59699490e+07 4.66023510e+07 1.34788602e+08 7.43315505e+07 2.90594490e+07 1.69724505e+07 1.22073990e+07 1.75332000e+07 2.39837490e+07 2.08520985e+07 1.79749500e+07 1.30892985e+07 2.40854505e+07 1.46409510e+07 1.74895500e+07 2.80684995e+07 2.67267495e+07 6.70891500e+07 1.44740490e+07 1.57225020e+07 3.29243985e+07 4.40091000e+07 7.04274990e+07 2.26439505e+07 2.02188000e+07 2.65490490e+07 1.70314500e+07 1.99385505e+07 1.75617495e+07 1.07474505e+07 9.58785150e+06 8.79180150e+06 8.72089950e+06 9.78925050e+06 1.28023500e+07 2.11819995e+07 1.25842020e+07 1.08182010e+07 1.12408005e+07 1.11389505e+07 1.49461005e+07 1.92435495e+07 1.72294500e+07 1.62970500e+07 1.30996005e+07 2.47017000e+07 2.27771010e+07 2.64075495e+07 3.45337980e+07 2.08153500e+07 9.64749900e+06 1.80844500e+07 1.62936510e+07 2.01943500e+07 2.01506985e+07 1.74450510e+07 2.05086990e+07 1.99185510e+07 1.18534995e+07 1.71190005e+07 2.08334505e+07 2.63137005e+07 1.67209995e+07 1.10944995e+07 1.80421005e+07 1.31673495e+07 5.68794900e+06 1.71547500e+07 1.70215995e+07 1.44353490e+07 1.15281495e+07 1.03399500e+07 9.25294950e+06 1.27330500e+07 2.78996505e+07 1.23022005e+07 1.18151490e+07 1.04793510e+07 1.53019005e+07 1.17685500e+07 1.38442500e+07 1.43783490e+07 9.61495050e+06 9.68740050e+06 1.27498005e+07 1.30861500e+07 1.37829510e+07 2.48670510e+07 1.52029500e+07 2.00702505e+07 3.11576490e+07 1.09909515e+07 1.12777995e+07 1.77999510e+07 1.03131495e+07 1.19172510e+07 8.99750100e+06 1.57977510e+07 1.74415500e+07 1.71862005e+07 2.22804510e+07 2.48519490e+07 1.28615985e+07 8.97985050e+06 5.81940000e+06 8.87909850e+06 1.41810990e+07 1.00131495e+07 1.29507990e+07 1.62798495e+07 1.61027505e+07 7.68529950e+06 9.64315200e+06 9.96745050e+06 6.41449950e+06 6.03065100e+06 9.69649950e+06 4.84925100e+06 5.90010150e+06 1.19467515e+07 8.69184900e+06 8.56419900e+06 9.26245050e+06 1.07934495e+07 1.07198520e+07 1.73134500e+07 1.00555500e+07 9.74299950e+06 1.03786515e+07 1.15933005e+07 1.06112505e+07 7.96140000e+06 1.03999995e+07 8.41255050e+06 9.77564850e+06 1.12130490e+07 1.01074995e+07 7.18449900e+06 6.75580050e+06 1.00755480e+07 6.85830000e+06 8.58105150e+06 1.08989505e+07 6.68255100e+06 9.43984950e+06 1.16806485e+07 1.44384015e+07 8.86635000e+06 8.25940050e+06 6.67435050e+06 1.02404985e+07 1.02786000e+07 9.32115150e+06 7.34284800e+06 9.19180050e+06 6.21079950e+06 1.30910490e+07 1.65008490e+07 1.57128510e+07 1.87312485e+07 1.93867980e+07 2.24612520e+07 1.28666985e+07 5.65314900e+06 9.18955050e+06 1.64545515e+07 1.14418500e+07 6.39709950e+06 8.57429850e+06 1.04579985e+07]' has dtype incompatible with int64, please explicitly cast to a compatible dtype first. df2.loc[f_open_xor_closed_fixed, "Volume"] = 0.5 m_rcp

Bad data proof

No response

yfinance version

0.2.40

Python version

3.12.2

Operating system

Ubuntu noble 24.04 x86_64

ValueRaider commented 4 months ago

Fixed in dev branch, release imminent #1971.