You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Originally posted by Slepetys October 31, 2022
Hi yfinancers,
I would like to report an error and how I fixed it.
In the long cascade of error messages, I found the most informative as: if zone.upper() == 'UTC': AttributeError: 'float' object has no attribute 'upper'
which is caused when a ticker symbol is passed to yfinance, but it does not exist. In most cases, yfinance handles such kind of situations well, but occasionally it returns an error like the message above.
After digging, I found that the exception handler in the base.py module, history function was not dealing well when the timezone is not defined (either Nan or None) in the prior call.
In version 0.1.84 I found such an error, I fixed just adding an additional exceptional handling step specific to such kind of condition:
First line: 153
try:
tz = self._get_ticker_tz(debug_mode, proxy, timeout)
if tz != tz or tz is None:
return utils.empty_df()
except KeyError as e:
...
It is possible to emulate the error through:
# Emulate yFinance error
from datetime import datetime as datetime
import yfinance as yf
print ('yfinance version = '+yf.__version__)
_start = datetime (2022,10,1)
_end = datetime (2022,10,30)
# Ticker Symbol that exists - NO ERROR:
ts_real = 'AAPL'
_OHLC = yf.download (ts_real,start=_start,end=_end,interval='1d')
print (_OHLC) #No error
# Ticker Symbol NOT exists - NO ERROR!
ts_real = 'AACQ'
_OHLC = yf.download (ts_real,start=_start,end=_end,interval='1d')
And the error follows:
Exception in thread Thread-6:
Traceback (most recent call last):
File "C:\Users\Roberto\anaconda3\lib\threading.py", line 932, in _bootstrap_inner
self.run()
File "C:\Users\Roberto\anaconda3\lib\threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\Roberto\anaconda3\lib\site-packages\multitasking\__init__.py", line 102, in _run_via_pool
return callee(*args, **kwargs)
File "C:\Users\Roberto\anaconda3\lib\site-packages\yfinance\multi.py", line 199, in _download_one_threaded
data = _download_one(ticker, start, end, auto_adjust, back_adjust,
File "C:\Users\Roberto\anaconda3\lib\site-packages\yfinance\multi.py", line 213, in _download_one
return Ticker(ticker).history(period=period, interval=interval,
File "C:\Users\Roberto\anaconda3\lib\site-packages\yfinance\base.py", line 171, in history
end = utils._parse_user_dt(end, tz)
File "C:\Users\Roberto\anaconda3\lib\site-packages\yfinance\utils.py", line 157, in _parse_user_dt
dt = _tz.timezone(exchange_tz).localize(dt)
File "C:\Users\Roberto\anaconda3\lib\site-packages\pytz\__init__.py", line 170, in timezone
if zone.upper() == 'UTC':
AttributeError: 'float' object has no attribute 'upper'
I hope this helps future versions.
All the best
Roberto Slepetys
The text was updated successfully, but these errors were encountered:
Discussed in https://github.com/ranaroussi/yfinance/discussions/1134
Originally posted by Slepetys October 31, 2022
Hi yfinancers,
I would like to report an error and how I fixed it.
In the long cascade of error messages, I found the most informative as:
if zone.upper() == 'UTC': AttributeError: 'float' object has no attribute 'upper'
which is caused when a ticker symbol is passed to yfinance, but it does not exist. In most cases, yfinance handles such kind of situations well, but occasionally it returns an error like the message above.
After digging, I found that the exception handler in the base.py module, history function was not dealing well when the timezone is not defined (either Nan or None) in the prior call.
In version 0.1.84 I found such an error, I fixed just adding an additional exceptional handling step specific to such kind of condition:
First line: 153
It is possible to emulate the error through:
And the error follows:
I hope this helps future versions.
All the best
Roberto Slepetys
The text was updated successfully, but these errors were encountered: