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
{{ message }}
Repository navigation
Exception in data module when using DataFrames with MultiIndex columns #5414
The data module appears to fail when working with DataFrames that use a MultiIndex for columns. This can be easily demonstrated in statsmodels.base.tests.test_data.TestDataFrames by changing the creation of a DataFrame from
Using MultiIndexes for DataFrame columns then propagates itself to other places because using the DataFrame.columns value as a simple list doesn't work (in a MultiIndex, DataFrame.columns is exposed as an iterable of tuples). The specific issue I ran into was when using a MultiIndex DataFrame with exponential smoothing, resulting in the following stack trace:
Traceback (most recent call last):
File "xxx/__init__.py", line 451, in do_algorithm_usecase
if af.compute():
File "xxx/algorithms/es.py", line 153, in compute
preds = self.fitted_model.predict(predict_from, predict_until)
File "xxx/myenv/lib/python3.7/site-packages/statsmodels/base/wrapper.py", line 95, in wrapper
obj = data.wrap_output(func(results, *args, **kwargs), how)
File "xxx/myenv/lib/python3.7/site-packages/statsmodels/base/data.py", line 416, in wrap_output
return self.attach_dates(obj)
File "xxx/myenv/lib/python3.7/site-packages/statsmodels/base/data.py", line 563, in attach_dates
columns=self.ynames)
File "xxx/myenv/lib/python3.7/site-packages/pandas/core/frame.py", line 379, in __init__
copy=copy)
File "xxx/myenv/lib/python3.7/site-packages/pandas/core/frame.py", line 536, in _init_ndarray
return create_block_manager_from_blocks([values], [columns, index])
File "xxx/myenv/lib/python3.7/site-packages/pandas/core/internals.py", line 4866, in create_block_manager_from_blocks
construction_error(tot_items, blocks[0].shape[1:], axes, e)
File "xxx/myenv/lib/python3.7/site-packages/pandas/core/internals.py", line 4843, in construction_error
passed, implied))
ValueError: Shape of passed values is (1, 3), indices imply (3, 3)
Activity
BUG: Flatten pandas MultiIndexes
gabrielreid commentedon Dec 10, 2018
Forgot to mention this previously, but this is with version 0.9.0 (and also verified it's still a problem in the master branch in Git).
gabrielreid commentedon Dec 10, 2018
I've opened PR #5415 to resolve this issue.
BUG: Flatten pandas MultiIndexes
BUG: Flatten pandas MultiIndexes