Cannot convert non-finite values (NA or inf)
Describe bug
Other versions:
numpy==2.4.6 pandas==3.0.3 yfinance==1.4.1
Error logs:
File "venv/lib/python3.12/site-packages/yfinance/utils.py", line 123, in wrapper result = func(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^ File "venv/lib/python3.12/site-packages/yfinance/base.py", line 129, in history return self._lazy_load_price_history().history(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "venv/lib/python3.12/site-packages/yfinance/utils.py", line 123, in wrapper result = func(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^ File "venv/lib/python3.12/site-packages/yfinance/scrapers/history.py", line 484, in history df = self._fix_bad_stock_splits(df, interval, tz_exchange) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "venv/lib/python3.12/site-packages/yfinance/utils.py", line 123, in wrapper result = func(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^ File "venv/lib/python3.12/site-packages/yfinance/scrapers/history.py", line 2646, in _fix_bad_stock_splits df_pre_split_repaired = self._fix_prices_sudden_change(df_pre_split, interval, tz_exchange, split, correct_volume=True, correct_dividend=True) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "venv/lib/python3.12/site-packages/yfinance/utils.py", line 123, in wrapper result = func(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^ File "venv/lib/python3.12/site-packages/yfinance/scrapers/history.py", line 3303, in _fix_prices_sudden_change df2.iloc[r[0]:r[1], col_loc] = (df2.iloc[r[0]:r[1], col_loc] * m_rcp).round().astype('int') ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "venv/lib/python3.12/site-packages/pandas/core/generic.py", line 6541, in astype new_data = self._mgr.astype(dtype=dtype, errors=errors) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "venv/lib/python3.12/site-packages/pandas/core/internals/managers.py", line 614, in astype return self.apply("astype", dtype=dtype, errors=errors) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "venv/lib/python3.12/site-packages/pandas/core/internals/managers.py", line 445, in apply applied = getattr(b, f)(**kwargs) ^^^^^^^^^^^^^^^^^^^^^^^ File "venv/lib/python3.12/site-packages/pandas/core/internals/blocks.py", line 607, in astype new_values = astype_array_safe(values, dtype, errors=errors) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "venv/lib/python3.12/site-packages/pandas/core/dtypes/astype.py", line 240, in astype_array_safe new_values = astype_array(values, dtype, copy=copy) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "venv/lib/python3.12/site-packages/pandas/core/dtypes/astype.py", line 185, in astype_array values = _astype_nansafe(values, dtype, copy=copy) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "venv/lib/python3.12/site-packages/pandas/core/dtypes/astype.py", line 102, in _astype_nansafe return _astype_float_to_int_nansafe(arr, dtype, copy) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "venv/lib/python3.12/site-packages/pandas/core/dtypes/astype.py", line 146, in _astype_float_to_int_nansafe raise IntCastingNaNError( pandas.errors.IntCastingNaNError: Cannot convert non-finite values (NA or inf) to integer.Replace or remove non-finite values or cast to an integer typethat supports these values (e.g. 'Int64')
Simple code that reproduces your problem
import yfinance as yf
ticker = "MERKO.IS" stock = yf.Ticker(ticker) stock.history(period="max", interval="1d", auto_adjust=False, actions=True, rounding=False, repair=True)
Debug log with debug logging enabled
DEBUG MERKO.IS: Yahoo GET parameters: {'period1': '1927-07-06 11:16:22+02:00', 'period2': '2026-06-11 12:16:17+03:00', 'interval': '1d', 'includePrePost': False, 'events': 'div,splits,capitalGains'} DEBUG Entering get() DEBUG Entering _make_request() DEBUG url=https://query2.finance.yahoo.com/v8/finance/chart/MERKO.IS DEBUG params={'period1': -1340894618, 'period2': 1781169377, '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 Entering _get_cookie_basic() DEBUG Entering _load_cookie_curlCffi() DEBUG Exiting _load_cookie_curlCffi() DEBUG reusing persistent cookie DEBUG Exiting _get_cookie_basic() DEBUG Entering _get_crumb_basic() DEBUG Entering _get_cookie_basic() DEBUG reusing cookie DEBUG Exiting _get_cookie_basic() DEBUG crumb = 'KbpyZydpuOB' DEBUG Exiting _get_crumb_basic() DEBUG Exiting _get_cookie_and_crumb_basic() DEBUG Exiting _get_cookie_and_crumb() DEBUG response code=200 DEBUG Exiting _make_request() DEBUG Exiting get() DEBUG MERKO.IS: yfinance received OHLC data: 2000-05-10 06:30:00 -> 2026-06-11 06:30:00 DEBUG MERKO.IS: OHLC after cleaning: 2000-05-10 09:30:00+03:00 -> 2026-06-11 09:30:00+03:00 DEBUG MERKO.IS: OHLC after combining events: 2000-05-10 00:00:00+03:00 -> 2026-06-11 00:00:00+03:00 DEBUG MERKO.IS: checking OHLC for repairs ... DEBUG Entering _fix_bad_div_adjust() DEBUG No dividends to check DEBUG Exiting _fix_bad_div_adjust() DEBUG Entering _fix_zeroes() DEBUG No price=0 errors to repair DEBUG Exiting _fix_zeroes() DEBUG Entering _fix_unit_mixups() DEBUG Entering _fix_unit_switch() DEBUG Entering _fix_prices_sudden_change() DEBUG start_min=None change=100.0000 (rcp=0.0100) DEBUG appears_suspended=False, idx_latest_active=0 (2026-06-11) DEBUG No 100x errors detected DEBUG Exiting _fix_prices_sudden_change() DEBUG Exiting _fix_unit_switch() DEBUG Entering _fix_unit_random_mixups() DEBUG No sporadic 100x errors DEBUG Exiting _fix_unit_random_mixups() DEBUG Exiting _fix_unit_mixups() DEBUG Entering _fix_bad_stock_splits() DEBUG Splits: {Timestamp('2003-08-11 00:00:00+0300', tz='Europe/Istanbul'): 2.0, Timestamp('2005-01-03 00:00:00+0200', tz='Europe/Istanbul'): 0.001, Timestamp('2020-12-21 00:00:00+0300', tz='Europe/Istanbul'): 0.1017516, Timestamp('2021-01-04 00:00:00+0300', tz='Europe/Istanbul'): 0.1017516, Timestamp('2026-05-05 00:00:00+0300', tz='Europe/Istanbul'): 7.383383} DEBUG split_idx=853 split_dt=2003-08-11 split=2.0000 DEBUG df dt range: 2000-05-10 -> 2003-08-18 DEBUG Entering _fix_prices_sudden_change() DEBUG start_min=2002-08-11 change=2.0000 (rcp=0.5000) DEBUG appears_suspended=False, idx_latest_active=0 (2003-08-18) DEBUG Estimation of true 1D change stats: mean = 1.00, StdDev = 0.0271 (2.7% of mean) DEBUG split_max=2.000 largest_change_pct=0.1354 DEBUG threshold=1.568, threshold_rcp=0.638 DEBUG price-repair-split: my workings: Close Vol 1D % r down up f i i_rev 2000-06-21 00:00:00+03:00 2.754589 0m 1.016 2.03 False False False 823 30 2000-06-20 00:00:00+03:00 3.021163 0m 1.115 2.23 False False False 824 29 2000-06-19 00:00:00+03:00 1.700000 0m 0.563 1.13 True False True 825 28 2000-06-16 00:00:00+03:00 1.800000 0m 1.059 2.12 False False False 826 27 2000-06-15 00:00:00+03:00 1.950000 0m 1.083 2.17 False False False 827 26 DEBUG idx_latest_active=0, idx_rev_latest_active=853 DEBUG Pruning range 2000-06-19 00:00:00+03:00->2000-05-10 00:00:00+03:00 because too old. INFO Corrected: DEBUG Exiting _fix_prices_sudden_change() DEBUG split_idx=1218 split_dt=2005-01-03 split=0.0010 DEBUG df dt range: 2000-05-10 -> 2005-01-10 DEBUG Entering _fix_prices_sudden_change() DEBUG start_min=2002-08-11 change=0.0010 (rcp=1000.0000) DEBUG appears_suspended=False, idx_latest_active=0 (2005-01-10) DEBUG No bad splits detected DEBUG Exiting _fix_prices_sudden_change() DEBUG split_idx=5344 split_dt=2020-12-21 split=0.1018 DEBUG df dt range: 2000-05-10 -> 2020-12-28 DEBUG Entering _fix_prices_sudden_change() DEBUG start_min=2002-08-11 change=0.1018 (rcp=9.8279) DEBUG appears_suspended=False, idx_latest_active=0 (2020-12-28) DEBUG No bad splits detected DEBUG Exiting _fix_prices_sudden_change() DEBUG split_idx=5353 split_dt=2021-01-04 split=0.1018 DEBUG df dt range: 2000-05-10 -> 2021-01-11 DEBUG Entering _fix_prices_sudden_change() DEBUG start_min=2002-08-11 change=0.1018 (rcp=9.8279) DEBUG appears_suspended=False, idx_latest_active=0 (2021-01-11) DEBUG No bad splits detected DEBUG Exiting _fix_prices_sudden_change() DEBUG split_idx=6690 split_dt=2026-05-05 split=7.3834 DEBUG df dt range: 2000-05-10 -> 2026-05-12 DEBUG Entering _fix_prices_sudden_change() DEBUG start_min=2002-08-11 change=7.3834 (rcp=0.1354) DEBUG appears_suspended=False, idx_latest_active=0 (2026-05-12) DEBUG Estimation of true 1D change stats: mean = 1.00, StdDev = 0.0185 (1.8% of mean) DEBUG split_max=7.383 largest_change_pct=0.0923 DEBUG threshold=4.238, threshold_rcp=0.236 DEBUG - vol_change_pct = 0.0000 DEBUG price-repair-split: my workings: Close Vol VolStr 1D % r down up f i i_rev 2026-05-04 00:00:00+03:00 2.092536 99m 99m 0.998 7.37 False False False 6 6684 2026-05-01 00:00:00+03:00 2.093890 0m 0m 0.988 7.29 False False False 7 6683 2026-04-30 00:00:00+03:00 15.460000 6m 6m 7.429 54.85 False True True 8 6682 2026-04-29 00:00:00+03:00 15.600000 7m 7m 1.017 7.51 False False False 9 6681 2026-04-28 00:00:00+03:00 15.800000 7m 7m 1.005 7.42 False False False 10 6680 DEBUG idx_latest_active=0, idx_rev_latest_active=6690 DEBUG range=(np.int64(8), 6691, '1.0/split') m=0.13543926950559113
Bad data proof
No response
yfinance version
1.4.1
Python version
3.12.3
Operating system
Linux Mint 22.3
Source: ranaroussi/yfinance