<p dir="auto">When using DataFrame.loc with a list of indices, the index name is missing from the resultant DataFrame unless the list of indices includes all of the indices in the original DataFrame.</p>
<p dir="auto">Example:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import pandas as pd
d=pd.DataFrame(
    [
        [1,2,3],
        [4,5,6],
        [7,8,9]
    ], 
    columns=['i','j','k']
).set_index('i')"><pre class="notranslate"><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">d</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">2</span>,<span class="pl-c1">3</span>],
        [<span class="pl-c1">4</span>,<span class="pl-c1">5</span>,<span class="pl-c1">6</span>],
        [<span class="pl-c1">7</span>,<span class="pl-c1">8</span>,<span class="pl-c1">9</span>]
    ], 
    <span class="pl-s1">columns</span><span class="pl-c1">=</span>[<span class="pl-s">'i'</span>,<span class="pl-s">'j'</span>,<span class="pl-s">'k'</span>]
).<span class="pl-en">set_index</span>(<span class="pl-s">'i'</span>)</pre></div>
<p dir="auto">When I use .loc and ask for all of the rows, I get (as desired) the correct, named index out the other end:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="d.loc[[1,4,7]]
#    j  k
# i      
#1  2  3
#4  5  6
#7  8  9

d.loc[[1,4,7]].index.name
# 'i'"><pre class="notranslate"><span class="pl-s1">d</span>.<span class="pl-s1">loc</span>[[<span class="pl-c1">1</span>,<span class="pl-c1">4</span>,<span class="pl-c1">7</span>]]
<span class="pl-c">#    j  k</span>
<span class="pl-c"># i      </span>
<span class="pl-c">#1  2  3</span>
<span class="pl-c">#4  5  6</span>
<span class="pl-c">#7  8  9</span>

<span class="pl-s1">d</span>.<span class="pl-s1">loc</span>[[<span class="pl-c1">1</span>,<span class="pl-c1">4</span>,<span class="pl-c1">7</span>]].<span class="pl-s1">index</span>.<span class="pl-s1">name</span>
<span class="pl-c"># 'i'</span></pre></div>
<p dir="auto">When I ask for a list of indices that is not all of them, I also expect to get a named index out the other end. However, the index values are preserved but the index name is lost:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="d.loc[[1,4]]
#    j  k
#1  2  3
#4  5  6

d.loc[[1,4]].index.name
# None"><pre class="notranslate"><span class="pl-s1">d</span>.<span class="pl-s1">loc</span>[[<span class="pl-c1">1</span>,<span class="pl-c1">4</span>]]
<span class="pl-c">#    j  k</span>
<span class="pl-c">#1  2  3</span>
<span class="pl-c">#4  5  6</span>

<span class="pl-s1">d</span>.<span class="pl-s1">loc</span>[[<span class="pl-c1">1</span>,<span class="pl-c1">4</span>]].<span class="pl-s1">index</span>.<span class="pl-s1">name</span>
<span class="pl-c"># None</span></pre></div>
<p dir="auto">Suggesting that this is a bug because the index naming should be the same no matter whether I <code class="notranslate">.loc</code> for for all of the rows or just some of them.</p>
<p dir="auto">This issue was encountered when fixing <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="28705875" data-permission-text="Title is private" data-url="https://github.com/pandas-dev/pandas/issues/6536" data-hovercard-type="issue" data-hovercard-url="/pandas-dev/pandas/issues/6536/hovercard" href="https://github.com/pandas-dev/pandas/issues/6536">#6536</a>. It seems that <code class="notranslate">.loc</code> indexer with empty list key seems to lose names of respective axes:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="
In [2]: pd.DataFrame(np.arange(9).reshape(3,3), columns=pd.Series(list('abc'), name='foobar'))
Out[2]: 
foobar  a  b  c
0       0  1  2
1       3  4  5
2       6  7  8

[3 rows x 3 columns]

In [3]: _2.iloc[:,[]]
Out[3]: 
Empty DataFrame
Columns: []
Index: [0, 1, 2]

[3 rows x 0 columns]

In [4]: _2.iloc[:,[]].columns.names
Out[4]: FrozenList([u'foobar'])

In [5]: _2.loc[:,[]].columns.names
Out[5]: FrozenList([None])
"><pre class="notranslate"><span class="pl-v">In</span> [<span class="pl-c1">2</span>]: <span class="pl-s1">pd</span>.<span class="pl-v">DataFrame</span>(<span class="pl-s1">np</span>.<span class="pl-en">arange</span>(<span class="pl-c1">9</span>).<span class="pl-en">reshape</span>(<span class="pl-c1">3</span>,<span class="pl-c1">3</span>), <span class="pl-s1">columns</span><span class="pl-c1">=</span><span class="pl-s1">pd</span>.<span class="pl-v">Series</span>(<span class="pl-en">list</span>(<span class="pl-s">'abc'</span>), <span class="pl-s1">name</span><span class="pl-c1">=</span><span class="pl-s">'foobar'</span>))
<span class="pl-v">Out</span>[<span class="pl-c1">2</span>]: 
<span class="pl-s1">foobar</span>  <span class="pl-s1">a</span>  <span class="pl-s1">b</span>  <span class="pl-s1">c</span>
<span class="pl-c1">0</span>       <span class="pl-c1">0</span>  <span class="pl-c1">1</span>  <span class="pl-c1">2</span>
<span class="pl-c1">1</span>       <span class="pl-c1">3</span>  <span class="pl-c1">4</span>  <span class="pl-c1">5</span>
<span class="pl-c1">2</span>       <span class="pl-c1">6</span>  <span class="pl-c1">7</span>  <span class="pl-c1">8</span>

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

<span class="pl-v">In</span> [<span class="pl-c1">3</span>]: <span class="pl-s1">_2</span>.<span class="pl-s1">iloc</span>[:,[]]
<span class="pl-v">Out</span>[<span class="pl-c1">3</span>]: 
<span class="pl-v">Empty</span> <span class="pl-v">DataFrame</span>
<span class="pl-v">Columns</span>: []
<span class="pl-v">Index</span>: [<span class="pl-c1">0</span>, <span class="pl-c1">1</span>, <span class="pl-c1">2</span>]

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

<span class="pl-v">In</span> [<span class="pl-c1">4</span>]: <span class="pl-s1">_2</span>.<span class="pl-s1">iloc</span>[:,[]].<span class="pl-s1">columns</span>.<span class="pl-s1">names</span>
<span class="pl-v">Out</span>[<span class="pl-c1">4</span>]: <span class="pl-v">FrozenList</span>([<span class="pl-s">u'foobar'</span>])

<span class="pl-v">In</span> [<span class="pl-c1">5</span>]: <span class="pl-s1">_2</span>.<span class="pl-s1">loc</span>[:,[]].<span class="pl-s1">columns</span>.<span class="pl-s1">names</span>
<span class="pl-v">Out</span>[<span class="pl-c1">5</span>]: <span class="pl-v">FrozenList</span>([<span class="pl-c1">None</span>])</pre></div>
<p dir="auto">It's not important, but currently <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="28784702" data-permission-text="Title is private" data-url="https://github.com/pandas-dev/pandas/issues/6551" data-hovercard-type="pull_request" data-hovercard-url="/pandas-dev/pandas/pull/6551/hovercard" href="https://github.com/pandas-dev/pandas/pull/6551">#6551</a> has two tests skipped because of this bug.</p>