<p dir="auto">pandas 0.14 <a href="http://pandas.pydata.org/pandas-docs/version/0.15.0/whatsnew.html#whatsnew-0140-api" rel="nofollow">changed <code class="notranslate">.iloc</code></a> to accept out-of-bounds indexers for slices. I think we should do the same for <code class="notranslate">.loc</code>, for similar reasons of consistency and efficiency.</p>
<p dir="auto">Note that this is already currently inconsistent for int and float indexes (not entirely sure why):</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&gt;&gt;&gt; pd.Series(range(5), np.arange(5)).loc[-1:]
KeyError
&gt;&gt;&gt; pd.Series(range(5), np.arange(5.0)).loc[-1:]
0    0
1    1
2    2
3    3
4    4
dtype: int64"><pre class="notranslate"><code class="notranslate">&gt;&gt;&gt; pd.Series(range(5), np.arange(5)).loc[-1:]
KeyError
&gt;&gt;&gt; pd.Series(range(5), np.arange(5.0)).loc[-1:]
0    0
1    1
2    2
3    3
4    4
dtype: int64
</code></pre></div>
<p dir="auto">I didn't directly find an issue about it, or an explanation in the docs, but I stumbled today on the following, which did surprise me a bit:</p>
<p dir="auto">Considering the following dataframe:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="In [18]: df = pd.DataFrame(np.random.randn(5,2), index=pd.date_range('2012-01-01', periods=5))

In [19]: df
Out[19]:
                   0         1
2012-01-01  2.511337 -0.776326
2012-01-02  0.133589  0.441911
2012-01-03  0.348167  1.285188
2012-01-04  1.075843  1.282131
2012-01-05  0.683006  0.558459"><pre class="notranslate"><code class="notranslate">In [18]: df = pd.DataFrame(np.random.randn(5,2), index=pd.date_range('2012-01-01', periods=5))

In [19]: df
Out[19]:
                   0         1
2012-01-01  2.511337 -0.776326
2012-01-02  0.133589  0.441911
2012-01-03  0.348167  1.285188
2012-01-04  1.075843  1.282131
2012-01-05  0.683006  0.558459
</code></pre></div>
<p dir="auto">Slicing with a label that is not included in the index works with <code class="notranslate">.ix</code>, but not with <code class="notranslate">.loc</code>:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="In [20]: df.ix['2012-01-03':'2012-01-31']
Out[20]:
                   0         1
2012-01-03  0.348167  1.285188
2012-01-04  1.075843  1.282131
2012-01-05  0.683006  0.558459

In [21]: df.loc['2012-01-03':'2012-01-31']
...
KeyError: 'stop bound [2012-01-31] is not in the [index]'"><pre class="notranslate"><code class="notranslate">In [20]: df.ix['2012-01-03':'2012-01-31']
Out[20]:
                   0         1
2012-01-03  0.348167  1.285188
2012-01-04  1.075843  1.282131
2012-01-05  0.683006  0.558459

In [21]: df.loc['2012-01-03':'2012-01-31']
...
KeyError: 'stop bound [2012-01-31] is not in the [index]'
</code></pre></div>
<p dir="auto">Context: I was updating some older code, and I wanted to replace <code class="notranslate">.ix</code> with <code class="notranslate">.loc</code> (as this is what we recommend if it is purely label based to prevent confusion).</p>
<p dir="auto">Some things:</p>
<ul dir="auto">
<li>If this is intended, I don't find this stated somewhere in the docs. So the docs are at least lacking at this point.</li>
<li>the inconsistency between <code class="notranslate">[]</code>, <code class="notranslate">.ix[]</code> and <code class="notranslate">.loc[]</code> is a bit surprising here</li>
<li>it is also inconsistent with <code class="notranslate">iloc</code> -&gt; that behaviour was changed in 0.14 to allow out of bound slicing (<a href="http://pandas.pydata.org/pandas-docs/stable/whatsnew.html#whatsnew-0140-api" rel="nofollow">http://pandas.pydata.org/pandas-docs/stable/whatsnew.html#whatsnew-0140-api</a>)</li>
<li>Specifically for datetime-line indexing, it is also inconsistent with the feature of partial string indexing: <code class="notranslate">df.loc['2012-01-03':'2012-01']</code> will work and do the expected while <code class="notranslate">df.loc['2012-01-03':'2012-01-31']</code> fails</li>
</ul>