<p dir="auto">Under <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="273440900" data-permission-text="Title is private" data-url="https://github.com/pandas-dev/pandas/issues/18262" data-hovercard-type="issue" data-hovercard-url="/pandas-dev/pandas/issues/18262/hovercard" href="https://github.com/pandas-dev/pandas/issues/18262">#18262</a> a <code class="notranslate">FutureWarning</code> was added suggesting that existing code like this:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="pd.DataFrame.from_items(x)"><pre class="notranslate"><code class="notranslate">pd.DataFrame.from_items(x)
</code></pre></div>
<p dir="auto">Should be changed to this:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="import collections
pd.DataFrame.from_dict(collections.OrderedDict(x))"><pre class="notranslate"><code class="notranslate">import collections
pd.DataFrame.from_dict(collections.OrderedDict(x))
</code></pre></div>
<p dir="auto">The fact that <code class="notranslate">from_items()</code> appeared only 6 times (now 8 times) in a Stack Overflow search was used as partial justification for removing it.  But if you search on GitHub, <a href="https://github.com/search?q=pd.DataFrame.from_items&amp;type=Code"><code class="notranslate">pd.DataFrame.from_items()</code></a> appears more than 15,000 times in Python--almost half as many as <code class="notranslate">from_records()</code>!</p>
<p dir="auto">We should celebrate the fact that this function doesn't cause enough confusion to appear often on Stack Overflow.  But it does occur (a lot!) in real code, and deprecating it is a mistake.</p>
<p dir="auto">If constructing a temporary <code class="notranslate">OrderedDict</code> around items is the best way to construct a DataFrame, Pandas should implement that as a short function called <code class="notranslate">DataFrame.from_items()</code>, rather than asking thousands of people to busy themselves to accommodate this unnecessary API change.</p>
<p dir="auto">I recommend removing the FutureWarning, and retaining this widely-used, longstanding function.</p>
<p dir="auto">For reference, the <code class="notranslate">FutureWarning</code> starts in 0.23 and looks like this:</p>
<blockquote>
<p dir="auto">FutureWarning: from_items is deprecated. Please use DataFrame.from_dict(dict(items), ...) instead. DataFrame.from_dict(OrderedDict(items)) may be used to preserve the key order.</p>
</blockquote>
<p dir="auto">I want to slice log files to extract only values within a certain time range. This works well with all but one log file. <em>"Must be the log file then!"</em>. However, the log file is well-formed like all the others and I don't see the reason my code fails:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import pandas as pan
import datetime as dt

time_f = '%Y-%m-%d %H:%M:%S.%f'

def get_sublog_by_index(log, t_stime, t_etime):
    s_idx, e_idx = log.index.slice_locs(t_stime, t_etime)
    return log.ix[s_idx: e_idx + 1]

if __name__ == '__main__':
    #http://pastebin.com/tQ6MFhgN
    df_good = pan.read_csv('dstat_good', header=True, parse_dates=True, index_col=0)
    #http://pastebin.com/M9r59Seq
    df_bad = pan.read_csv('dstat_bad', header=True, parse_dates=True, index_col=0)
    #manual construction just to be shure; why does pan.tslib.Timestamp.strptime fail?
    s_t_g = pan.tslib.Timestamp(dt.datetime.strptime('2015-04-23 03:46:37.030256', time_f))
    s_e_g = pan.tslib.Timestamp(dt.datetime.strptime('2015-04-23 04:46:40.560409', time_f))
    s_t_b = pan.tslib.Timestamp(dt.datetime.strptime('2015-04-23 02:44:49.310807', time_f))
    s_e_b = pan.tslib.Timestamp(dt.datetime.strptime('2015-04-23 03:44:52.922636', time_f))
    sublog_g = get_sublog_by_index(df_good, s_t_g, s_e_g)
    sublog_b = get_sublog_by_index(df_bad, s_t_b, s_e_b)"><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">pan</span>
<span class="pl-k">import</span> <span class="pl-s1">datetime</span> <span class="pl-k">as</span> <span class="pl-s1">dt</span>

<span class="pl-s1">time_f</span> <span class="pl-c1">=</span> <span class="pl-s">'%Y-%m-%d %H:%M:%S.%f'</span>

<span class="pl-k">def</span> <span class="pl-en">get_sublog_by_index</span>(<span class="pl-s1">log</span>, <span class="pl-s1">t_stime</span>, <span class="pl-s1">t_etime</span>):
    <span class="pl-s1">s_idx</span>, <span class="pl-s1">e_idx</span> <span class="pl-c1">=</span> <span class="pl-s1">log</span>.<span class="pl-s1">index</span>.<span class="pl-en">slice_locs</span>(<span class="pl-s1">t_stime</span>, <span class="pl-s1">t_etime</span>)
    <span class="pl-k">return</span> <span class="pl-s1">log</span>.<span class="pl-s1">ix</span>[<span class="pl-s1">s_idx</span>: <span class="pl-s1">e_idx</span> <span class="pl-c1">+</span> <span class="pl-c1">1</span>]

<span class="pl-k">if</span> <span class="pl-s1">__name__</span> <span class="pl-c1">==</span> <span class="pl-s">'__main__'</span>:
    <span class="pl-c">#http://pastebin.com/tQ6MFhgN</span>
    <span class="pl-s1">df_good</span> <span class="pl-c1">=</span> <span class="pl-s1">pan</span>.<span class="pl-en">read_csv</span>(<span class="pl-s">'dstat_good'</span>, <span class="pl-s1">header</span><span class="pl-c1">=</span><span class="pl-c1">True</span>, <span class="pl-s1">parse_dates</span><span class="pl-c1">=</span><span class="pl-c1">True</span>, <span class="pl-s1">index_col</span><span class="pl-c1">=</span><span class="pl-c1">0</span>)
    <span class="pl-c">#http://pastebin.com/M9r59Seq</span>
    <span class="pl-s1">df_bad</span> <span class="pl-c1">=</span> <span class="pl-s1">pan</span>.<span class="pl-en">read_csv</span>(<span class="pl-s">'dstat_bad'</span>, <span class="pl-s1">header</span><span class="pl-c1">=</span><span class="pl-c1">True</span>, <span class="pl-s1">parse_dates</span><span class="pl-c1">=</span><span class="pl-c1">True</span>, <span class="pl-s1">index_col</span><span class="pl-c1">=</span><span class="pl-c1">0</span>)
    <span class="pl-c">#manual construction just to be shure; why does pan.tslib.Timestamp.strptime fail?</span>
    <span class="pl-s1">s_t_g</span> <span class="pl-c1">=</span> <span class="pl-s1">pan</span>.<span class="pl-s1">tslib</span>.<span class="pl-v">Timestamp</span>(<span class="pl-s1">dt</span>.<span class="pl-s1">datetime</span>.<span class="pl-en">strptime</span>(<span class="pl-s">'2015-04-23 03:46:37.030256'</span>, <span class="pl-s1">time_f</span>))
    <span class="pl-s1">s_e_g</span> <span class="pl-c1">=</span> <span class="pl-s1">pan</span>.<span class="pl-s1">tslib</span>.<span class="pl-v">Timestamp</span>(<span class="pl-s1">dt</span>.<span class="pl-s1">datetime</span>.<span class="pl-en">strptime</span>(<span class="pl-s">'2015-04-23 04:46:40.560409'</span>, <span class="pl-s1">time_f</span>))
    <span class="pl-s1">s_t_b</span> <span class="pl-c1">=</span> <span class="pl-s1">pan</span>.<span class="pl-s1">tslib</span>.<span class="pl-v">Timestamp</span>(<span class="pl-s1">dt</span>.<span class="pl-s1">datetime</span>.<span class="pl-en">strptime</span>(<span class="pl-s">'2015-04-23 02:44:49.310807'</span>, <span class="pl-s1">time_f</span>))
    <span class="pl-s1">s_e_b</span> <span class="pl-c1">=</span> <span class="pl-s1">pan</span>.<span class="pl-s1">tslib</span>.<span class="pl-v">Timestamp</span>(<span class="pl-s1">dt</span>.<span class="pl-s1">datetime</span>.<span class="pl-en">strptime</span>(<span class="pl-s">'2015-04-23 03:44:52.922636'</span>, <span class="pl-s1">time_f</span>))
    <span class="pl-s1">sublog_g</span> <span class="pl-c1">=</span> <span class="pl-en">get_sublog_by_index</span>(<span class="pl-s1">df_good</span>, <span class="pl-s1">s_t_g</span>, <span class="pl-s1">s_e_g</span>)
    <span class="pl-s1">sublog_b</span> <span class="pl-c1">=</span> <span class="pl-en">get_sublog_by_index</span>(<span class="pl-s1">df_bad</span>, <span class="pl-s1">s_t_b</span>, <span class="pl-s1">s_e_b</span>)</pre></div>
<p dir="auto">I have two log files to test, one working, the other not:<br>
<a href="http://pastebin.com/tQ6MFhgN" rel="nofollow">http://pastebin.com/tQ6MFhgN</a> (working)<br>
<a href="http://pastebin.com/M9r59Seq" rel="nofollow">http://pastebin.com/M9r59Seq</a> (not working)</p>
<p dir="auto">At closer inspection you will notice that the start and end times (<code class="notranslate">s_t*</code> and <code class="notranslate">s_e*</code>) are within the range of the logs' timestamps. You will also notice that the <em>bad</em> log has no odd data or anything else that gives a hint why the code is not working in that case. This is truly odd and seems to origin from the deep. Or I'm struck with utter blindness?</p>
<p dir="auto">For completeness, this is what I get if I try to slice the <em>bad</em> log file:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="  ...
  File &quot;/usr/local/bin/dstatlogsplit&quot;, line 54, in get_sublog_by_index
    s_idx, e_idx = log.index.slice_locs(t_stime, t_etime)
  File &quot;/usr/local/lib/python2.7/dist-packages/pandas/core/index.py&quot;, line 2484, in slice_locs
    start_slice = self.get_slice_bound(start, 'left', kind)
  File &quot;/usr/local/lib/python2.7/dist-packages/pandas/core/index.py&quot;, line 2432, in get_slice_bound
    raise err
KeyError: 1429757089310807000L"><pre class="notranslate"><code class="notranslate">  ...
  File "/usr/local/bin/dstatlogsplit", line 54, in get_sublog_by_index
    s_idx, e_idx = log.index.slice_locs(t_stime, t_etime)
  File "/usr/local/lib/python2.7/dist-packages/pandas/core/index.py", line 2484, in slice_locs
    start_slice = self.get_slice_bound(start, 'left', kind)
  File "/usr/local/lib/python2.7/dist-packages/pandas/core/index.py", line 2432, in get_slice_bound
    raise err
KeyError: 1429757089310807000L
</code></pre></div>