<h4 dir="auto">Code Sample, a copy-pastable example if possible</h4>
<h4 dir="auto">Problem description</h4>
<p dir="auto">I find a bug when using panel.apply(), and with some digging, I find an interesting indexing problem caused by multiindex in Panel Object. It is demonstrated below:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="# 
import pandas as pd
pn1 = pd.Panel(pd.np.random.random(size=(3,4,5)),items=['AAA','BBB','CCC'])
print pn1.loc[:,:,1]
pn2 = pn1.copy()
pn2.major_axis = pd.MultiIndex.from_product([list('AB'),list('ab')])
print pn2.loc[:,:,1]
"><pre class="notranslate"><span class="pl-c"># </span>
<span class="pl-k">import</span> <span class="pl-s1">pandas</span> <span class="pl-k">as</span> <span class="pl-s1">pd</span>
<span class="pl-s1">pn1</span> <span class="pl-c1">=</span> <span class="pl-s1">pd</span>.<span class="pl-v">Panel</span>(<span class="pl-s1">pd</span>.<span class="pl-s1">np</span>.<span class="pl-s1">random</span>.<span class="pl-en">random</span>(<span class="pl-s1">size</span><span class="pl-c1">=</span>(<span class="pl-c1">3</span>,<span class="pl-c1">4</span>,<span class="pl-c1">5</span>)),<span class="pl-s1">items</span><span class="pl-c1">=</span>[<span class="pl-s">'AAA'</span>,<span class="pl-s">'BBB'</span>,<span class="pl-s">'CCC'</span>])
<span class="pl-k">print</span> <span class="pl-s1">pn1</span>.<span class="pl-s1">loc</span>[:,:,<span class="pl-c1">1</span>]
<span class="pl-s1">pn2</span> <span class="pl-c1">=</span> <span class="pl-s1">pn1</span>.<span class="pl-en">copy</span>()
<span class="pl-s1">pn2</span>.<span class="pl-s1">major_axis</span> <span class="pl-c1">=</span> <span class="pl-s1">pd</span>.<span class="pl-v">MultiIndex</span>.<span class="pl-en">from_product</span>([<span class="pl-en">list</span>(<span class="pl-s">'AB'</span>),<span class="pl-en">list</span>(<span class="pl-s">'ab'</span>)])
<span class="pl-k">print</span> <span class="pl-s1">pn2</span>.<span class="pl-s1">loc</span>[:,:,<span class="pl-c1">1</span>]</pre></div>
<h4 dir="auto">Output:</h4>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="        AAA       BBB       CCC
0  0.182982  0.774812  0.894589
1  0.654716  0.695453  0.790078
2  0.340826  0.941283  0.938544
3  0.351851  0.971896  0.362317
            A                   B          
            a         b         a         b
AAA  0.182982  0.654716  0.340826  0.351851
BBB  0.774812  0.695453  0.941283  0.971896
CCC  0.894589  0.790078  0.938544  0.362317"><pre class="notranslate"><code class="notranslate">        AAA       BBB       CCC
0  0.182982  0.774812  0.894589
1  0.654716  0.695453  0.790078
2  0.340826  0.941283  0.938544
3  0.351851  0.971896  0.362317
            A                   B          
            a         b         a         b
AAA  0.182982  0.654716  0.340826  0.351851
BBB  0.774812  0.695453  0.941283  0.971896
CCC  0.894589  0.790078  0.938544  0.362317
</code></pre></div>
<p dir="auto">With a multiindex as the major_axis of Panel object, the indexing result is transposed. And because of that, when using <code class="notranslate"> pn.apply(func, axis=('items','major'))</code>, it give you the wrong results when the major_axis is a multiindex.<br>
Is this a bug? if not, then what is the purpose that it is designed like this?<br>
Thanks for help.</p>
<p dir="auto">If you have a Panel with a MultiIndex, you can read but not write to it with <code class="notranslate">.ix</code> (same with <code class="notranslate">.loc</code>).</p>
<p dir="auto">Before 0.13 I would normally do something like <code class="notranslate">pn[item].ix[a, b][stuff] = values</code>, surprisingly it used to work (now it spits out a <code class="notranslate">SettingWithCopyWarning</code> but still kinda works).</p>
<p dir="auto">So what are the valid options in 0.13?</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="&gt;&gt;&gt; df = pd.DataFrame([1] * 3, pd.MultiIndex.from_tuples(zip(range(3), range(3))))
&gt;&gt;&gt; df
     0
0 0  1
1 1  1
2 2  1

[3 rows x 1 columns]

&gt;&gt;&gt; pn = pd.Panel(dict((k, df.copy() * k) for k in xrange(2)))
&gt;&gt;&gt; pn
&lt;class 'pandas.core.panel.Panel'&gt;
Dimensions: 2 (items) x 3 (major_axis) x 1 (minor_axis)
Items axis: 0 to 1
Major_axis axis: (0, 0) to (2, 2)
Minor_axis axis: 0 to 0

&gt;&gt;&gt; pn.ix[1, (0, 0), 0]
1

&gt;&gt;&gt; pn.ix[1, (0, 0), 0] = 1
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
&lt;ipython-input-64-f48c3a7f93c3&gt; in &lt;module&gt;()
----&gt; 1 pn.ix[1, (0, 0), 0] = 1

/home/smirnov/anaconda/lib/python2.7/site-packages/pandas-0.13.1-py2.7-linux-x86_64.egg/pandas/core/indexing.pyc in __setitem__(self, key, value)
     96             indexer = self._convert_to_indexer(key, is_setter=True)
     97
---&gt; 98         self._setitem_with_indexer(indexer, value)
     99
    100     def _has_valid_type(self, k, axis):

/home/smirnov/anaconda/lib/python2.7/site-packages/pandas-0.13.1-py2.7-linux-x86_64.egg/pandas/core/indexing.pyc in _setitem_with_indexer(self, indexer, value)
    299                 obj = self.obj[item]
    300                 index = obj.index
--&gt; 301                 idx = indexer[:info_axis][0]
    302                 try:
    303                     if idx in index:

IndexError: tuple index out of range
&gt; /home/smirnov/anaconda/lib/python2.7/site-packages/pandas-0.13.1-py2.7-linux-x86_64.egg/pandas/core/indexing.py(301)_setitem_with_indexer()
    300                 index = obj.index
--&gt; 301                 idx = indexer[:info_axis][0]
    302                 try:"><pre class="notranslate"><span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-s1">df</span> <span class="pl-c1">=</span> <span class="pl-s1">pd</span>.<span class="pl-v">DataFrame</span>([<span class="pl-c1">1</span>] <span class="pl-c1">*</span> <span class="pl-c1">3</span>, <span class="pl-s1">pd</span>.<span class="pl-v">MultiIndex</span>.<span class="pl-en">from_tuples</span>(<span class="pl-en">zip</span>(<span class="pl-en">range</span>(<span class="pl-c1">3</span>), <span class="pl-en">range</span>(<span class="pl-c1">3</span>))))
<span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-s1">df</span>
     <span class="pl-c1">0</span>
<span class="pl-c1">0</span> <span class="pl-c1">0</span>  <span class="pl-c1">1</span>
<span class="pl-c1">1</span> <span class="pl-c1">1</span>  <span class="pl-c1">1</span>
<span class="pl-c1">2</span> <span class="pl-c1">2</span>  <span class="pl-c1">1</span>

[<span class="pl-c1">3</span> <span class="pl-s1">rows</span> <span class="pl-s1">x</span> <span class="pl-c1">1</span> <span class="pl-s1">columns</span>]

<span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-s1">pn</span> <span class="pl-c1">=</span> <span class="pl-s1">pd</span>.<span class="pl-v">Panel</span>(<span class="pl-en">dict</span>((<span class="pl-s1">k</span>, <span class="pl-s1">df</span>.<span class="pl-en">copy</span>() <span class="pl-c1">*</span> <span class="pl-s1">k</span>) <span class="pl-k">for</span> <span class="pl-s1">k</span> <span class="pl-c1">in</span> <span class="pl-en">xrange</span>(<span class="pl-c1">2</span>)))
<span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-s1">pn</span>
<span class="pl-c1">&lt;</span><span class="pl-k">class</span> <span class="pl-s">'pandas.core.panel.Panel'</span><span class="pl-c1">&gt;</span>
<span class="pl-v">Dimensions</span>: <span class="pl-c1">2</span> (<span class="pl-s1">items</span>) <span class="pl-s1">x</span> <span class="pl-c1">3</span> (<span class="pl-s1">major_axis</span>) <span class="pl-s1">x</span> <span class="pl-c1">1</span> (<span class="pl-s1">minor_axis</span>)
<span class="pl-v">Items</span> <span class="pl-s1">axis</span>: <span class="pl-c1">0</span> <span class="pl-s1">to</span> <span class="pl-c1">1</span>
<span class="pl-v">Major_axis</span> <span class="pl-s1">axis</span>: (<span class="pl-c1">0</span>, <span class="pl-c1">0</span>) <span class="pl-s1">to</span> (<span class="pl-c1">2</span>, <span class="pl-c1">2</span>)
<span class="pl-v">Minor_axis</span> <span class="pl-s1">axis</span>: <span class="pl-c1">0</span> <span class="pl-s1">to</span> <span class="pl-c1">0</span>

<span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-s1">pn</span>.<span class="pl-s1">ix</span>[<span class="pl-c1">1</span>, (<span class="pl-c1">0</span>, <span class="pl-c1">0</span>), <span class="pl-c1">0</span>]
<span class="pl-c1">1</span>

<span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-s1">pn</span>.<span class="pl-s1">ix</span>[<span class="pl-c1">1</span>, (<span class="pl-c1">0</span>, <span class="pl-c1">0</span>), <span class="pl-c1">0</span>] <span class="pl-c1">=</span> <span class="pl-c1">1</span>
<span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span>
<span class="pl-v">IndexError</span>                                <span class="pl-v">Traceback</span> (<span class="pl-s1">most</span> <span class="pl-s1">recent</span> <span class="pl-s1">call</span> <span class="pl-s1">last</span>)
<span class="pl-c1">&lt;</span><span class="pl-s1">ipython</span><span class="pl-c1">-</span><span class="pl-s1">input</span><span class="pl-c1">-</span><span class="pl-c1">64</span><span class="pl-c1">-</span><span class="pl-s1">f48c3a7f93c3</span><span class="pl-c1">&gt;</span> <span class="pl-s1">in</span> <span class="pl-c1">&lt;</span><span class="pl-s1">module</span><span class="pl-c1">&gt;</span>()
<span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">&gt;</span> <span class="pl-c1">1</span> <span class="pl-s1">pn</span>.<span class="pl-s1">ix</span>[<span class="pl-c1">1</span>, (<span class="pl-c1">0</span>, <span class="pl-c1">0</span>), <span class="pl-c1">0</span>] <span class="pl-c1">=</span> <span class="pl-c1">1</span>

<span class="pl-c1">/</span><span class="pl-s1">home</span><span class="pl-c1">/</span><span class="pl-s1">smirnov</span><span class="pl-c1">/</span><span class="pl-s1">anaconda</span><span class="pl-c1">/</span><span class="pl-s1">lib</span><span class="pl-c1">/</span><span class="pl-s1">python2</span>.<span class="pl-c1">7</span><span class="pl-c1">/</span><span class="pl-s1">site</span><span class="pl-c1">-</span><span class="pl-s1">packages</span><span class="pl-c1">/</span><span class="pl-s1">pandas</span><span class="pl-c1">-</span><span class="pl-c1">0.13</span>.<span class="pl-c1">1</span><span class="pl-c1">-</span><span class="pl-s1">py2</span>.<span class="pl-c1">7</span><span class="pl-c1">-</span><span class="pl-s1">linux</span><span class="pl-c1">-</span><span class="pl-s1">x86_64</span>.<span class="pl-s1">egg</span><span class="pl-c1">/</span><span class="pl-s1">pandas</span><span class="pl-c1">/</span><span class="pl-s1">core</span><span class="pl-c1">/</span><span class="pl-s1">indexing</span>.<span class="pl-s1">pyc</span> <span class="pl-c1">in</span> <span class="pl-en">__setitem__</span>(<span class="pl-s1">self</span>, <span class="pl-s1">key</span>, <span class="pl-s1">value</span>)
     <span class="pl-c1">96</span>             <span class="pl-s1">indexer</span> <span class="pl-c1">=</span> <span class="pl-s1">self</span>.<span class="pl-en">_convert_to_indexer</span>(<span class="pl-s1">key</span>, <span class="pl-s1">is_setter</span><span class="pl-c1">=</span><span class="pl-c1">True</span>)
     <span class="pl-c1">97</span>
<span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">&gt;</span> <span class="pl-c1">98</span>         <span class="pl-s1">self</span>.<span class="pl-en">_setitem_with_indexer</span>(<span class="pl-s1">indexer</span>, <span class="pl-s1">value</span>)
     <span class="pl-c1">99</span>
    <span class="pl-c1">100</span>     <span class="pl-k">def</span> <span class="pl-en">_has_valid_type</span>(<span class="pl-s1">self</span>, <span class="pl-s1">k</span>, <span class="pl-s1">axis</span>):

<span class="pl-c1">/</span><span class="pl-s1">home</span><span class="pl-c1">/</span><span class="pl-s1">smirnov</span><span class="pl-c1">/</span><span class="pl-s1">anaconda</span><span class="pl-c1">/</span><span class="pl-s1">lib</span><span class="pl-c1">/</span><span class="pl-s1">python2</span>.<span class="pl-c1">7</span><span class="pl-c1">/</span><span class="pl-s1">site</span><span class="pl-c1">-</span><span class="pl-s1">packages</span><span class="pl-c1">/</span><span class="pl-s1">pandas</span><span class="pl-c1">-</span><span class="pl-c1">0.13</span>.<span class="pl-c1">1</span><span class="pl-c1">-</span><span class="pl-s1">py2</span>.<span class="pl-c1">7</span><span class="pl-c1">-</span><span class="pl-s1">linux</span><span class="pl-c1">-</span><span class="pl-s1">x86_64</span>.<span class="pl-s1">egg</span><span class="pl-c1">/</span><span class="pl-s1">pandas</span><span class="pl-c1">/</span><span class="pl-s1">core</span><span class="pl-c1">/</span><span class="pl-s1">indexing</span>.<span class="pl-s1">pyc</span> <span class="pl-c1">in</span> <span class="pl-en">_setitem_with_indexer</span>(<span class="pl-s1">self</span>, <span class="pl-s1">indexer</span>, <span class="pl-s1">value</span>)
    <span class="pl-c1">299</span>                 <span class="pl-s1">obj</span> <span class="pl-c1">=</span> <span class="pl-s1">self</span>.<span class="pl-s1">obj</span>[<span class="pl-s1">item</span>]
    <span class="pl-c1">300</span>                 <span class="pl-s1">index</span> <span class="pl-c1">=</span> <span class="pl-s1">obj</span>.<span class="pl-s1">index</span>
<span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">&gt;</span> <span class="pl-c1">301</span>                 <span class="pl-s1">idx</span> <span class="pl-c1">=</span> <span class="pl-s1">indexer</span>[:<span class="pl-s1">info_axis</span>][<span class="pl-c1">0</span>]
    <span class="pl-c1">302</span>                 <span class="pl-k">try</span>:
    <span class="pl-c1">303</span>                     <span class="pl-k">if</span> <span class="pl-s1">idx</span> <span class="pl-c1">in</span> <span class="pl-s1">index</span>:

<span class="pl-v">IndexError</span>: <span class="pl-s1">tuple</span> <span class="pl-s1">index</span> <span class="pl-s1">out</span> <span class="pl-s1">of</span> <span class="pl-s1">range</span>
<span class="pl-c1">&gt;</span> <span class="pl-c1">/</span><span class="pl-s1">home</span><span class="pl-c1">/</span><span class="pl-s1">smirnov</span><span class="pl-c1">/</span><span class="pl-s1">anaconda</span><span class="pl-c1">/</span><span class="pl-s1">lib</span><span class="pl-c1">/</span><span class="pl-s1">python2</span>.<span class="pl-c1">7</span><span class="pl-c1">/</span><span class="pl-s1">site</span><span class="pl-c1">-</span><span class="pl-s1">packages</span><span class="pl-c1">/</span><span class="pl-s1">pandas</span><span class="pl-c1">-</span><span class="pl-c1">0.13</span>.<span class="pl-c1">1</span><span class="pl-c1">-</span><span class="pl-s1">py2</span>.<span class="pl-c1">7</span><span class="pl-c1">-</span><span class="pl-s1">linux</span><span class="pl-c1">-</span><span class="pl-s1">x86_64</span>.<span class="pl-s1">egg</span><span class="pl-c1">/</span><span class="pl-s1">pandas</span><span class="pl-c1">/</span><span class="pl-s1">core</span><span class="pl-c1">/</span><span class="pl-s1">indexing</span>.<span class="pl-en">py</span>(<span class="pl-c1">301</span>)<span class="pl-s1">_setitem_with_indexer</span>()
    <span class="pl-c1">300</span>                 <span class="pl-s1">index</span> <span class="pl-c1">=</span> <span class="pl-s1">obj</span>.<span class="pl-s1">index</span>
<span class="pl-c1">-</span><span class="pl-c1">-&gt;</span> <span class="pl-c1">301</span>                 <span class="pl-s1">idx</span> <span class="pl-c1">=</span> <span class="pl-s1">indexer</span>[:<span class="pl-s1">info_axis</span>][<span class="pl-c1">0</span>]
    <span class="pl-c1">302</span>                 <span class="pl-k">try</span>:</pre></div>