Repository navigation
BUG: Flatten pandas MultiIndexes - #5415
gabrielreid wants to merge 1 commit into
Conversation
Flatten pandas MultiIndexes when extracting column names in the data module. Prior to this commit, the MultiIndexes would be exposed as a list of tuples, which would then result in the DataFrame being treated as having more than 2 dimensions. Fixes statsmodels#5414.
28e6b8f to
d28bc8a
Compare
| return list(arr.columns) | ||
| if isinstance(arr.columns, MultiIndex): | ||
| # Flatten MultiIndexes into "simple" column names | ||
| return [".".join((level for level in c if level)) for c in arr.columns] |
There was a problem hiding this comment.
wouldn't underline instead of a dot be better as joining character?
I usually use underline to keep it as valid python name (if it already is), but I don't know of any conventions for this.
There was a problem hiding this comment.
Pandas uses underscore for these scenarios. Like Groupby('z').describe() would create 'x_mean' or when you merge/join it can create x_left and x_right for example.
|
unit tests fail in statsmodels.iolib.tests.test_table.TestSimpleTable I don't know what that test is supposed to be doing, but this needs more investigation. |
|
@gabrielreid Thanks for the report and the PR. It looks good to me, but given that there is a failing unit test, we need to check whether flattening is the correct fix for this. |
|
temporarily prio-high |
|
Note: this is if the column names are a multi-index, not for observations The failing unit test is for multi-index endog. |
|
MNLogit wrapping is hit or miss isn’t it? And lots of VAR just doesn’t wrap at all. I’m pretty sure pandas recently added a MultiIndex.to_flat method (or something like that). It’ll be a few years before statsmodels requires pandas >=0.24.0 though |
|
MNLogit has problems in post estimation, but has special code to handle the multivariate endog. |
Use _ to make a python name Clean up for flake compliance closes statsmodels#5415
Use _ to make a python name Clean up for flake compliance closes statsmodels#5415
Flatten pandas MultiIndexes when extracting column names in the
data module. Prior to this commit, the MultiIndexes would be
exposed as a list of tuples, which would then result in the
DataFrame being treated as having more than 2 dimensions.
closes #5414