Skip to content
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

AttributeError: module 'pandas_datareader.data' has no attribute 'get_data_google' #689

Open
akitxu opened this issue Jun 29, 2022 · 1 comment

Comments

@akitxu
Copy link

akitxu commented Jun 29, 2022

Dear All,
The statement pf.create_simple_tear_sheet(df['strategy_returns'].diff()) returns the error , returns the error.
AttributeError: module 'pandas_datareader.data' has no attribute 'get_data_google'
When importing from yahoo using yfinance or datareader, the DataFrame's index tag is named 'Date'. The problem seems to point to what should be named 'date'.
I have made the modification of this name in the DataFrame and the problem continues. How can I fix this problem?. Thanks in advanced.

Please provide the full traceback:

/home/enri/anaconda3/envs/yfinance1/lib/python3.9/site-packages/empyrical/utils.py:440: UserWarning: Yahoo Finance read failed: 'date', falling back to Google
  warnings.warn(

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
~/anaconda3/envs/yfinance1/lib/python3.9/site-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
   3360             try:
-> 3361                 return self._engine.get_loc(casted_key)
   3362             except KeyError as err:

~/anaconda3/envs/yfinance1/lib/python3.9/site-packages/pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()

~/anaconda3/envs/yfinance1/lib/python3.9/site-packages/pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()

pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()

KeyError: 'date'

The above exception was the direct cause of the following exception:

KeyError                                  Traceback (most recent call last)
~/anaconda3/envs/yfinance1/lib/python3.9/site-packages/empyrical/utils.py in get_symbol_returns_from_yahoo(symbol, start, end)
    435         px = web.get_data_yahoo(symbol, start=start, end=end)
--> 436         px['date'] = pd.to_datetime(px['date'])
    437         px.set_index('date', drop=False, inplace=True)

~/anaconda3/envs/yfinance1/lib/python3.9/site-packages/pandas/core/frame.py in __getitem__(self, key)
   3457                 return self._getitem_multilevel(key)
-> 3458             indexer = self.columns.get_loc(key)
   3459             if is_integer(indexer):

~/anaconda3/envs/yfinance1/lib/python3.9/site-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
   3362             except KeyError as err:
-> 3363                 raise KeyError(key) from err
   3364 

KeyError: 'date'

During handling of the above exception, another exception occurred:

AttributeError                            Traceback (most recent call last)
/tmp/ipykernel_3857/3291042158.py in <module>
      1 import pyfolio as pf
----> 2 pf.create_simple_tear_sheet(df['strategy_returns'].diff())

~/anaconda3/envs/yfinance1/lib/python3.9/site-packages/pyfolio/tears.py in create_simple_tear_sheet(returns, positions, transactions, benchmark_rets, slippage, estimate_intraday, live_start_date)
    291 
    292     if benchmark_rets is None:
--> 293         benchmark_rets = utils.get_symbol_rets('SPY')
    294 
    295     if (slippage is not None) and (transactions is not None):

~/anaconda3/envs/yfinance1/lib/python3.9/site-packages/pyfolio/utils.py in get_symbol_rets(symbol, start, end)
    596     """
    597 
--> 598     return SETTINGS['returns_func'](symbol,
    599                                     start=start,
    600                                     end=end)

~/anaconda3/envs/yfinance1/lib/python3.9/site-packages/pyfolio/deprecate.py in wrapper(*args, **kwargs)
     41                 stacklevel=stacklevel
     42             )
---> 43             return fn(*args, **kwargs)
     44         return wrapper
     45     return deprecated_dec

~/anaconda3/envs/yfinance1/lib/python3.9/site-packages/pyfolio/utils.py in default_returns_func(symbol, start, end)
    399          - See full explanation in tears.create_full_tear_sheet (returns).
    400     """
--> 401     return empyrical.utils.default_returns_func(symbol, start=None, end=None)
    402 
    403 

~/anaconda3/envs/yfinance1/lib/python3.9/site-packages/empyrical/deprecate.py in wrapper(*args, **kwargs)
     41                 stacklevel=stacklevel
     42             )
---> 43             return fn(*args, **kwargs)
     44         return wrapper
     45     return deprecated_dec

~/anaconda3/envs/yfinance1/lib/python3.9/site-packages/empyrical/utils.py in default_returns_func(symbol, start, end)
    483     if symbol == 'SPY':
    484         filepath = data_path('spy.csv')
--> 485         rets = get_returns_cached(filepath,
    486                                   get_symbol_returns_from_yahoo,
    487                                   end,

~/anaconda3/envs/yfinance1/lib/python3.9/site-packages/empyrical/deprecate.py in wrapper(*args, **kwargs)
     41                 stacklevel=stacklevel
     42             )
---> 43             return fn(*args, **kwargs)
     44         return wrapper
     45     return deprecated_dec

~/anaconda3/envs/yfinance1/lib/python3.9/site-packages/empyrical/utils.py in get_returns_cached(filepath, update_func, latest_dt, **kwargs)
    322 
    323     if update_cache:
--> 324         returns = update_func(**kwargs)
    325         try:
    326             ensure_directory(cache_dir())

~/anaconda3/envs/yfinance1/lib/python3.9/site-packages/empyrical/deprecate.py in wrapper(*args, **kwargs)
     41                 stacklevel=stacklevel
     42             )
---> 43             return fn(*args, **kwargs)
     44         return wrapper
     45     return deprecated_dec

~/anaconda3/envs/yfinance1/lib/python3.9/site-packages/empyrical/utils.py in get_symbol_returns_from_yahoo(symbol, start, end)
    441             'Yahoo Finance read failed: {}, falling back to Google'.format(e),
    442             UserWarning)
--> 443         px = web.get_data_google(symbol, start=start, end=end)
    444         rets = px[['Close']].pct_change().dropna()
    445 

AttributeError: module 'pandas_datareader.data' has no attribute 'get_data_google'

Please provide any additional information below:

Versions

  • Pyfolio version: 0.8.0
  • Python version: 3.9.7
  • Pandas version: 1.3.4
  • Matplotlib version: 3.4.3
@RichardDale
Copy link

RichardDale commented Jun 29, 2022

This project is no longer maintained since Quantopian no longer mantains it.

You should try a fork of it, by Stefan Jasen, which is maintained:
https://github.com/stefan-jansen/pyfolio-reloaded

@stefan-jansen and others (especially @MBounouar ) continue to improve this and other related packages like Zipline: https://github.com/stefan-jansen/zipline-reloaded

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants