-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
throw exception when calling history() on a vietnamese stock which contains dividend record #2270
Comments
Might be worth comparing div currency against price currency in metadata, sometimes Yahoo mixes currencies. |
Hello Team, I am getting the same error when trying to get UAE stock price history. test = yf.Ticker("ADCB.AB") yfinance version 0.2.54 ValueError Traceback (most recent call last) 8 frames /usr/local/lib/python3.11/dist-packages/yfinance/base.py in history(self, *args, **kwargs) /usr/local/lib/python3.11/dist-packages/yfinance/utils.py in wrapper(*args, **kwargs) /usr/local/lib/python3.11/dist-packages/yfinance/scrapers/history.py in history(self, period, interval, start, end, prepost, actions, auto_adjust, back_adjust, repair, keepna, proxy, rounding, timeout, raise_errors) /usr/local/lib/python3.11/dist-packages/yfinance/utils.py in parse_actions(data) /usr/local/lib/python3.11/dist-packages/pandas/core/generic.py in setattr(self, name, value) properties.pyx in pandas._libs.properties.AxisProperty.set() /usr/local/lib/python3.11/dist-packages/pandas/core/generic.py in _set_axis(self, axis, labels) /usr/local/lib/python3.11/dist-packages/pandas/core/internals/managers.py in set_axis(self, axis, new_labels) /usr/local/lib/python3.11/dist-packages/pandas/core/internals/base.py in _validate_set_axis(self, axis, new_labels) ValueError: Length mismatch: Expected axis has 2 elements, new values have 1 elements |
Describe bug
When calling history() for Vietnamese stocks, if it contains dividend records, the dividend records will have a currency field, causing an exception. For example:
will cause:
Simple code that reproduces your problem
Debug log
DEBUG Entering history()
DEBUG Entering history()
DEBUG PNJ.VN: Yahoo GET parameters: {'period1': '2024-11-01 00:00:00+07:00', 'period2': '2025-02-17 14:10:03+07: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/PNJ.VN
DEBUG params={'period1': 1730394000, 'period2': 1739776203, '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 = 'vsEB7v4e5NI'
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 PNJ.VN: yfinance received OHLC data: 2024-11-01 02:00:00 -> 2025-02-17 06:54:51
DEBUG PNJ.VN: OHLC after cleaning: 2024-11-01 09:00:00+07:00 -> 2025-02-17 13:54:51+07:00
Traceback (most recent call last):
File "/Users/alai04/projects/python/yfinance/history.py", line 6, in
hist = tk.history(start='2024-11-01')
File "/Users/alai04/.virtualenvs/stock/lib/python3.13/site-packages/yfinance/utils.py", line 104, in wrapper
result = func(*args, **kwargs)
File "/Users/alai04/.virtualenvs/stock/lib/python3.13/site-packages/yfinance/base.py", line 80, in history
return self._lazy_load_price_history().history(*args, **kwargs)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
File "/Users/alai04/.virtualenvs/stock/lib/python3.13/site-packages/yfinance/utils.py", line 104, in wrapper
result = func(*args, **kwargs)
File "/Users/alai04/.virtualenvs/stock/lib/python3.13/site-packages/yfinance/scrapers/history.py", line 318, in history
dividends, splits, capital_gains = utils.parse_actions(data["chart"]["result"][0])
~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/alai04/.virtualenvs/stock/lib/python3.13/site-packages/yfinance/utils.py", line 535, in parse_actions
dividends.columns = ["Dividends"]
^^^^^^^^^^^^^^^^^
File "/Users/alai04/.virtualenvs/stock/lib/python3.13/site-packages/pandas/core/generic.py", line 6313, in setattr
return object.setattr(self, name, value)
~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^
File "properties.pyx", line 69, in pandas._libs.properties.AxisProperty.set
File "/Users/alai04/.virtualenvs/stock/lib/python3.13/site-packages/pandas/core/generic.py", line 814, in _set_axis
self._mgr.set_axis(axis, labels)
~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
File "/Users/alai04/.virtualenvs/stock/lib/python3.13/site-packages/pandas/core/internals/managers.py", line 238, in set_axis
self._validate_set_axis(axis, new_labels)
~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^
File "/Users/alai04/.virtualenvs/stock/lib/python3.13/site-packages/pandas/core/internals/base.py", line 98, in _validate_set_axis
raise ValueError(
...<2 lines>...
)
ValueError: Length mismatch: Expected axis has 2 elements, new values have 1 elements
Bad data proof
No response
yfinance
version0.2.53
Python version
3.13.2
Operating system
macOS 15.3
The text was updated successfully, but these errors were encountered: