pydata/pandas — pull request #8480 by behzadnouri (2014-10-06 03:31:45+00:00)
Title: sub-frame assignment of a multi-index frame breaks alignment

closes https://github.com/pydata/pandas/issues/7655

In [72]: df
Out[72]:
jim joe jolie
first last first last first last
left center right left center right left center right left center right left center right left center right
2000-01-03 49 15 82 80 47 68 86 84 84 17 10 78 49 15 82 80 47 68
2000-01-04 30 83 49 85 71 27 12 20 11 61 58 93 30 83 49 85 71 27
2000-01-05 3 57 5 46 67 23 18 34 35 70 84 20 3 57 5 46 67 23

In [73]: i, j = df.index.values.copy(), it[-1][:]

In [74]: np.random.shuffle(i)

In [75]: df['jim'] = df['jolie'].loc[i, ::-1]

In [76]: df.loc[:, ['jim', 'jolie']]
Out[76]:
jim jolie
first last first last
left center right left center right left center right left center right
2000-01-03 49 15 82 80 47 68 49 15 82 80 47 68
2000-01-04 30 83 49 85 71 27 30 83 49 85 71 27
2000-01-05 3 57 5 46 67 23 3 57 5 46 67 23

In [77]: np.random.shuffle(j)

In [78]: df[('joe', 'first')] = df[('jolie', 'last')].loc[i, j]

In [79]: np.random.shuffle(j)

In [80]: df[('joe', 'last')] = df[('jolie', 'first')].loc[i, j]

In [81]: df.loc[:, ['joe', 'jolie']]
Out[81]:
joe jolie
first last first last
left center right left center right left center right left center right
2000-01-03 80 47 68 49 15 82 49 15 82 80 47 68
2000-01-04 85 71 27 30 83 49 30 83 49 85 71 27
2000-01-05 46 67 23 3 57 5 3 57 5 46 67 23