Skip to content

UnboundLocalError in pandas.io.data.get_data_yahoo #9971

Closed
@ElDeveloper

Description

@ElDeveloper
In [1]: %paste
import pandas.io.data as web
all_data = {}
for ticker in ['AAPL', 'GOOG', 'IBM', 'YHOO', 'MSFT']:
    all_data[ticker] = web.get_data_yahoo(ticker, '1/1/2010', '1/1/2013')
price = pd.DataFrame({tic: data['Adj Close']
                      for tic, data in all_data.iteritems()})

## -- End pasted text --

I took the snippet above from vincent's quickstart and found that an UnboundLocalError is being raised (probably pointing to a bug).

---------------------------------------------------------------------------
UnboundLocalError                         Traceback (most recent call last)
<ipython-input-1-c2d08f863001> in <module>()
      2 all_data = {}
      3 for ticker in ['AAPL', 'GOOG', 'IBM', 'YHOO', 'MSFT']:
----> 4     all_data[ticker] = web.get_data_yahoo(ticker, '1/1/2010', '1/1/2013')
      5 price = pd.DataFrame({tic: data['Adj Close']
      6                       for tic, data in all_data.iteritems()})

/Users/yoshikivazquezbaeza/.virtualenvs/ipy/lib/python2.7/site-packages/pandas/io/data.pyc in get_data_yahoo(symbols, start, end, retry_count, pause, adjust_price, ret_index, chunksize, interval)
    418         raise ValueError("Invalid interval: valid values are 'd', 'w', 'm' and 'v'")
    419     return _get_data_from(symbols, start, end, interval, retry_count, pause,
--> 420                           adjust_price, ret_index, chunksize, 'yahoo')
    421 
    422 

/Users/yoshikivazquezbaeza/.virtualenvs/ipy/lib/python2.7/site-packages/pandas/io/data.pyc in _get_data_from(symbols, start, end, interval, retry_count, pause, adjust_price, ret_index, chunksize, source)
    359     # If a single symbol, (e.g., 'GOOG')
    360     if isinstance(symbols, (compat.string_types, int)):
--> 361         hist_data = src_fn(symbols, start, end, interval, retry_count, pause)
    362     # Or multiple symbols, (e.g., ['GOOG', 'AAPL', 'MSFT'])
    363     elif isinstance(symbols, DataFrame):

/Users/yoshikivazquezbaeza/.virtualenvs/ipy/lib/python2.7/site-packages/pandas/io/data.pyc in _get_hist_yahoo(sym, start, end, interval, retry_count, pause)
    206            '&g=%s' % interval +
    207            '&ignore=.csv')
--> 208     return _retry_read_url(url, retry_count, pause, 'Yahoo!')
    209 
    210 

/Users/yoshikivazquezbaeza/.virtualenvs/ipy/lib/python2.7/site-packages/pandas/io/data.pyc in _retry_read_url(url, retry_count, pause, name)
    175     #Get rid of unicode characters in index name.
    176     try:
--> 177         rs.index.name = rs.index.name.decode('unicode_escape').encode('ascii', 'ignore')
    178     except AttributeError:
    179         #Python 3 string has no decode method.

UnboundLocalError: local variable 'rs' referenced before assignment

My installation:

In [5]: pd.show_versions()

INSTALLED VERSIONS
------------------
commit: None
python: 2.7.9.final.0
python-bits: 64
OS: Darwin
OS-release: 14.3.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: en_US.UTF-8
LANG: en_US.UTF-8

pandas: 0.16.0
nose: 1.3.4
Cython: None
numpy: 1.9.2
scipy: 0.14.0
statsmodels: None
IPython: 3.0.0
sphinx: 1.2.2
patsy: None
dateutil: 2.4.2
pytz: 2015.2
bottleneck: None
tables: None
numexpr: None
matplotlib: 1.4.3
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: None
httplib2: None
apiclient: None
sqlalchemy: None
pymysql: None
psycopg2: None

Metadata

Metadata

Assignees

No one assigned

    Labels

    IO DataIO issues that don't fit into a more specific label

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions