Assignment of subpart of data frame with multi index yields user surprise

```python
from collections import OrderedDict
import random
import pandas as pd


pd.__version__
```




    '0.20.3'




```python
df = pd.DataFrame.from_dict(OrderedDict(
    [
        ((lv1, lv2, lv3), {'KG': random.randint(0, 100)})
        for lv1 in ['A', 'B']
        for lv2 in ['M', 'N', 'O']
        for lv3 in ['X', 'Y', 'Z']
    ]
))
df     
```




<div>
<table border="1" class="dataframe">
  <thead>
    <tr>
      <th></th>
      <th colspan="9" halign="left">A</th>
      <th colspan="9" halign="left">B</th>
    </tr>
    <tr>
      <th></th>
      <th colspan="3" halign="left">M</th>
      <th colspan="3" halign="left">N</th>
      <th colspan="3" halign="left">O</th>
      <th colspan="3" halign="left">M</th>
      <th colspan="3" halign="left">N</th>
      <th colspan="3" halign="left">O</th>
    </tr>
    <tr>
      <th></th>
      <th>X</th>
      <th>Y</th>
      <th>Z</th>
      <th>X</th>
      <th>Y</th>
      <th>Z</th>
      <th>X</th>
      <th>Y</th>
      <th>Z</th>
      <th>X</th>
      <th>Y</th>
      <th>Z</th>
      <th>X</th>
      <th>Y</th>
      <th>Z</th>
      <th>X</th>
      <th>Y</th>
      <th>Z</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>KG</th>
      <td>16</td>
      <td>71</td>
      <td>27</td>
      <td>8</td>
      <td>83</td>
      <td>0</td>
      <td>100</td>
      <td>72</td>
      <td>100</td>
      <td>42</td>
      <td>26</td>
      <td>21</td>
      <td>91</td>
      <td>5</td>
      <td>36</td>
      <td>98</td>
      <td>96</td>
      <td>52</td>
    </tr>
  </tbody>
</table>
</div>




```python
df.loc[:, idx[:, :, 'X']]
```




<div>
<table border="1" class="dataframe">
  <thead>
    <tr>
      <th></th>
      <th colspan="3" halign="left">A</th>
      <th colspan="3" halign="left">B</th>
    </tr>
    <tr>
      <th></th>
      <th>M</th>
      <th>N</th>
      <th>O</th>
      <th>M</th>
      <th>N</th>
      <th>O</th>
    </tr>
    <tr>
      <th></th>
      <th>X</th>
      <th>X</th>
      <th>X</th>
      <th>X</th>
      <th>X</th>
      <th>X</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>KG</th>
      <td>44</td>
      <td>83</td>
      <td>-28</td>
      <td>5</td>
      <td>-31</td>
      <td>44</td>
    </tr>
  </tbody>
</table>
</div>




```python
df.xs('Y', level=2, axis=1) - df.xs('Z', level=2, axis=1)
```




<div>
<table border="1" class="dataframe">
  <thead>
    <tr>
      <th></th>
      <th colspan="3" halign="left">A</th>
      <th colspan="3" halign="left">B</th>
    </tr>
    <tr>
      <th></th>
      <th>M</th>
      <th>N</th>
      <th>O</th>
      <th>M</th>
      <th>N</th>
      <th>O</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>KG</th>
      <td>44</td>
      <td>83</td>
      <td>-28</td>
      <td>5</td>
      <td>-31</td>
      <td>44</td>
    </tr>
  </tbody>
</table>
</div>




```python
idx = pd.IndexSlice
df.loc[:, idx[:, :, 'X']] = (df.xs('Y', level=2, axis=1) - df.xs('Z', level=2, axis=1))
df
```




<div>
<table border="1" class="dataframe">
  <thead>
    <tr>
      <th></th>
      <th colspan="9" halign="left">A</th>
      <th colspan="9" halign="left">B</th>
    </tr>
    <tr>
      <th></th>
      <th colspan="3" halign="left">M</th>
      <th colspan="3" halign="left">N</th>
      <th colspan="3" halign="left">O</th>
      <th colspan="3" halign="left">M</th>
      <th colspan="3" halign="left">N</th>
      <th colspan="3" halign="left">O</th>
    </tr>
    <tr>
      <th></th>
      <th>X</th>
      <th>Y</th>
      <th>Z</th>
      <th>X</th>
      <th>Y</th>
      <th>Z</th>
      <th>X</th>
      <th>Y</th>
      <th>Z</th>
      <th>X</th>
      <th>Y</th>
      <th>Z</th>
      <th>X</th>
      <th>Y</th>
      <th>Z</th>
      <th>X</th>
      <th>Y</th>
      <th>Z</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>KG</th>
      <td>NaN</td>
      <td>71</td>
      <td>27</td>
      <td>NaN</td>
      <td>83</td>
      <td>0</td>
      <td>NaN</td>
      <td>72</td>
      <td>100</td>
      <td>NaN</td>
      <td>26</td>
      <td>21</td>
      <td>NaN</td>
      <td>5</td>
      <td>36</td>
      <td>NaN</td>
      <td>96</td>
      <td>52</td>
    </tr>
  </tbody>
</table>
</div>



This was unexpected. I realize that the indexes do not match, and hence this behavior, but I expect Pandas to throw an Exception, rather than silently do this


```python
idx = pd.IndexSlice
df.loc[:, idx[:, :, 'X']] = (df.xs('Y', level=2, axis=1) - df.xs('Z', level=2, axis=1)).values
df
```




<div>
<table border="1" class="dataframe">
  <thead>
    <tr>
      <th></th>
      <th colspan="9" halign="left">A</th>
      <th colspan="9" halign="left">B</th>
    </tr>
    <tr>
      <th></th>
      <th colspan="3" halign="left">M</th>
      <th colspan="3" halign="left">N</th>
      <th colspan="3" halign="left">O</th>
      <th colspan="3" halign="left">M</th>
      <th colspan="3" halign="left">N</th>
      <th colspan="3" halign="left">O</th>
    </tr>
    <tr>
      <th></th>
      <th>X</th>
      <th>Y</th>
      <th>Z</th>
      <th>X</th>
      <th>Y</th>
      <th>Z</th>
      <th>X</th>
      <th>Y</th>
      <th>Z</th>
      <th>X</th>
      <th>Y</th>
      <th>Z</th>
      <th>X</th>
      <th>Y</th>
      <th>Z</th>
      <th>X</th>
      <th>Y</th>
      <th>Z</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>KG</th>
      <td>44</td>
      <td>71</td>
      <td>27</td>
      <td>83</td>
      <td>83</td>
      <td>0</td>
      <td>-28</td>
      <td>72</td>
      <td>100</td>
      <td>5</td>
      <td>26</td>
      <td>21</td>
      <td>-31</td>
      <td>5</td>
      <td>36</td>
      <td>44</td>
      <td>96</td>
      <td>52</td>
    </tr>
  </tbody>
</table>
</div>



This was, of course, the behavior I was expecting
