ranaroussi / yfinance

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

Error when setting period and enabling 'repair' #2051

Closed LucaGherardini closed 2 months ago

LucaGherardini commented 2 months ago

Describe bug

Hello, I recently started to use yfinance to fetch financial data. I was playing with the options, and I noticed an error happening when I set both repair and period to non-default values. This seems to be because np.bool got deprecated in numpy 1.20 (I am running version 1.23.5 due to compatibility issues with other libraries I want to use with yfinance). I installed yfinance through

conda install yfinance[nospam,repair]

Simple code that reproduces your problem

import yfinance as yf
GetStockInformation = yf.Ticker(
    'META,
)
stock_df = GetStockInformation.history(
    interval='1d',
    period='max',
    # NOTE: if either period or repair is omitted, the call works just fine
    repair=True,
)

Debug log

DEBUG Entering history() DEBUG Entering history() DEBUG META: Yahoo GET parameters: {'period1': '1925-10-03 05:31:05-05:00', 'period2': '2024-09-08 06:31:05-04:00', 'interval': '1d', 'includePrePost': False, 'events': 'div,splits,capitalGains'} DEBUG Entering get() DEBUG url=https://query2.finance.yahoo.com/v8/finance/chart/META DEBUG params={'period1': -1396272535, 'period2': 1725791465, 'interval': '1d', 'includePrePost': False, 'events': 'div,splits,capitalGains'} DEBUG Entering _get_cookie_and_crumb() DEBUG cookie_mode = 'basic' DEBUG Entering _get_cookie_and_crumb_basic() DEBUG loaded persistent cookie DEBUG reusing cookie DEBUG crumb = '9iUyxclmVki' DEBUG Exiting _get_cookie_and_crumb_basic() DEBUG Exiting _get_cookie_and_crumb() DEBUG response code=200 DEBUG Exiting get() DEBUG META: yfinance received OHLC data: 2012-05-18 13:30:00 -> 2024-09-06 20:00:01 DEBUG META: OHLC after cleaning: 2012-05-18 09:30:00-04:00 -> 2024-09-06 16:00:01-04:00 DEBUG META: OHLC after combining events: 2012-05-18 00:00:00-04:00 -> 2024-09-06 00:00:00-04:00 DEBUG META: checking OHLC for repairs ... DEBUG Entering _fix_bad_divadjust() /lib/python3.11/site-packages/yfinance/scrapers/history.py:1530: DeprecationWarning: np.bool is a deprecated alias for the builtin bool. To silence this warning, use bool by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.boolhere. Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations if isinstance(v, (bool, np.bool)): /lib/python3.11/site-packages/yfinance/scrapers/history.py:1530: DeprecationWarning:np.boolis a deprecated alias for the builtinbool. To silence this warning, useboolby itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, usenp.bool_` here. Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations if isinstance(v, (bool, np.bool)): Traceback (most recent call last): File "example_bug_yf.py", line 8, in stock_df = GetStockInformation.history( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/lib/python3.11/site-packages/yfinance/utils.py", line 104, in wrapper result = func(*args, kwargs) ^^^^^^^^^^^^^^^^^^^^^ File "/lib/python3.11/site-packages/yfinance/base.py", line 78, in history return self._lazy_load_price_history().history(*args, *kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/lib/python3.11/site-packages/yfinance/utils.py", line 104, in wrapper result = func(args, kwargs) ^^^^^^^^^^^^^^^^^^^^^ File "/lib/python3.11/site-packages/yfinance/scrapers/history.py", line 373, in history df = self._fix_bad_div_adjust(df, interval, currency) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/lib/python3.11/site-packages/yfinance/utils.py", line 104, in wrapper result = func(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^ File "/lib/python3.11/site-packages/yfinance/scrapers/history.py", line 1537, in _fix_bad_div_adjust raise Exception(k,v,type(v)) Exception: ('adjmissing', False, <class 'numpy.bool'>)

Bad data proof

No response

yfinance version

0.2.43

Python version

3.11.9

Operating system

Linux Ubuntu

ValueRaider commented 2 months ago

duplicate #2049