quantopian / alphalens

Performance analysis of predictive (alpha) stock factors
http://quantopian.github.io/alphalens
Apache License 2.0
3.18k stars 1.12k forks source link

Cannot set name on a level of a MultiIndex. Use 'MultiIndex.set_names' instead. #359

Closed stin7 closed 4 years ago

stin7 commented 4 years ago

Problem Description

Pandas 1.0 does not allow setting names directly.

Please provide a minimal, self-contained, and reproducible example: Run https://github.com/quantopian/alphalens/blob/master/alphalens/examples/daily_factor_synthetic_data.ipynb after upgrading to Pandas 1.0+

Please provide the full traceback:

Traceback (most recent call last):
  File "<stdin>", line 7, in <module>
  File "/usr/local/lib/python3.7/site-packages/alphalens/utils.py", line 793, in get_clean_factor_and_forward_returns
    cumulative_returns)
  File "/usr/local/lib/python3.7/site-packages/alphalens/utils.py", line 342, in compute_forward_returns
    df.index.levels[0].name = "date"
  File "/usr/local/lib/python3.7/site-packages/pandas/core/indexes/base.py", line 1191, in name
    "Cannot set name on a level of a MultiIndex. Use "
RuntimeError: Cannot set name on a level of a MultiIndex. Use 'MultiIndex.set_names' instead.

Please provide any additional information below:

Versions

dmichalowicz commented 4 years ago

Hi @stin7, thanks for filing an issue. It looks like we'll need to make changes for the pandas 1.0 release, but I'm not yet sure of the scope/impact of those changes elsewhere in the repo. For now, if this is a blocker, is downgrading pandas a feasible option for you?

altquant commented 4 years ago

I opened a pr with a fix, tested and works with Pandas 1.0 - https://github.com/quantopian/alphalens/pull/364