Skip to content

BUG: stacking with MultiIndex column with some unused level uniques fail... #3218

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

Merged
merged 2 commits into from
Mar 31, 2013
Merged

BUG: stacking with MultiIndex column with some unused level uniques fail... #3218

merged 2 commits into from
Mar 31, 2013

Conversation

changhiskhan
Copy link
Contributor

...s #3170

@hayd
Copy link
Contributor

hayd commented Mar 29, 2013

Using the example from #3170, seems to be a rogue column: :S ?

In [15]: df.unstack('ID').resample('W-THU').stack('ID')
Out[15]: 
Params        NAME  VAR1
DATE       ID           
2013-01-03 1   NaN  69.0
           2   NaN  69.0
2013-01-10 1   NaN  76.0
           2   NaN  73.5

@changhiskhan
Copy link
Contributor Author

oops you're right. i'll put in a fix

@hayd
Copy link
Contributor

hayd commented Mar 29, 2013

One last thing, ID stack loses the column.name:

In [14]: df.unstack('ID').resample('W-THU').stack('Params')
Out[14]: 
ID                  1     2
DATE       Params          
2013-01-03 VAR1    69  69.0
2013-01-10 VAR1    76  73.5

In [15]: df.unstack('ID').resample('W-THU').stack('ID')
Out[15]: 
               VAR1
DATE       ID      
2013-01-03 1   69.0
           2   69.0
2013-01-10 1   76.0
           2   73.5

I think because:

new_columns = new_columns - drop_cols

drops the column name (i.e. 'Params' in the case of the example). Maybe save it with:

cols_name = new_columns.name
new_columns = new_columns - drop_cols
new_columns.name = cols_name

Will need to add that name to xp in the test, since assert_frame_equal tests column.name now :).

(Probably - should keep the indexes name...)

@hayd
Copy link
Contributor

hayd commented Mar 29, 2013

Also: thanks for fixing this! :)

@changhiskhan
Copy link
Contributor Author

good catch :) thanks!

I'll fix it later today.

@hayd
Copy link
Contributor

hayd commented Mar 30, 2013

I'm going to make include these two commits in a PR with some name functionality of - (for MultiIndex and Index), and will fix the name bit. Hope that's ok :)

@hayd hayd mentioned this pull request Mar 30, 2013
@hayd hayd merged commit 49390b9 into pandas-dev:master Mar 31, 2013
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

Successfully merging this pull request may close these issues.

2 participants