<p dir="auto">from <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/dhirschfeld/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/dhirschfeld">@dhirschfeld</a></p>
<p dir="auto">I just ran across the bug described in issue <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="11924688" data-permission-text="Title is private" data-url="https://github.com/pandas-dev/pandas/issues/3020" data-hovercard-type="issue" data-hovercard-url="/pandas-dev/pandas/issues/3020/hovercard" href="https://github.com/pandas-dev/pandas/issues/3020">#3020</a> (<a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="11924688" data-permission-text="Title is private" data-url="https://github.com/pandas-dev/pandas/issues/3020" data-hovercard-type="issue" data-hovercard-url="/pandas-dev/pandas/issues/3020/hovercard" href="https://github.com/pandas-dev/pandas/issues/3020">#3020</a>) as our unit-tests started failing after upgrading pandas.</p>
<p dir="auto">I did a git bisection and found the first bad commit to be <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/pandas-dev/pandas/commit/9deda9e687915017cc9db7698504ead1f89ead9e/hovercard" href="https://github.com/pandas-dev/pandas/commit/9deda9e687915017cc9db7698504ead1f89ead9e"><tt>9deda9e</tt></a>:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="9deda9e687915017cc9db7698504ead1f89ead9e is the first bad commit
commit 9deda9e687915017cc9db7698504ead1f89ead9e
Author: Chang She
Date:   Sun Dec 2 02:21:10 2012 -0500

    API: change resample to infer correct closed and label value by default #2363

:040000 040000 3abca1d3eb70bcd6ade31581acc4684a3035b81e 4cdeae975685b996ef2f41c738ca70bfd41ca583 M  pandas"><pre class="notranslate"><code class="notranslate">9deda9e687915017cc9db7698504ead1f89ead9e is the first bad commit
commit 9deda9e687915017cc9db7698504ead1f89ead9e
Author: Chang She
Date:   Sun Dec 2 02:21:10 2012 -0500

    API: change resample to infer correct closed and label value by default #2363

:040000 040000 3abca1d3eb70bcd6ade31581acc4684a3035b81e 4cdeae975685b996ef2f41c738ca70bfd41ca583 M  pandas
</code></pre></div>
<p dir="auto">I think this is a fairly serious regression as (apart from causing our unit-tests to fail) it will silently give incorrect answers for an aggregation if the data has been resampled beforehand.</p>
<p dir="auto">The following unit-test demonstrates the problem:</p>
<p dir="auto">def test_resample_doesnt_truncate():<br>
"""Test for issue <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="11924688" data-permission-text="Title is private" data-url="https://github.com/pandas-dev/pandas/issues/3020" data-hovercard-type="issue" data-hovercard-url="/pandas-dev/pandas/issues/3020/hovercard" href="https://github.com/pandas-dev/pandas/issues/3020">#3020</a>"""<br>
import pandas as pd<br>
dates = pd.date_range('01-Jan-2014','05-Jan-2014', freq='D')<br>
series = pd.TimeSeries(1, index=dates)<br>
series = series.resample('D')<br>
assert series.index[0] == dates[0]</p>
<h1 dir="auto"></h1>
<p dir="auto">When resampling from a TimeSeries with freq='MS' to freq='D' the TimeSeries is shifted forward by one day, skipping the first element:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="In [64]: dates = pd.date_range('01-Apr-13','01-May-13',freq='MS')

In [65]: ts = pd.TimeSeries([1,2],dates)

In [66]: ts
Out[66]: 
2013-04-01    1
2013-05-01    2
Freq: MS

In [67]: ts.resample('d',closed='left',label='left')
Out[67]: 
2013-04-02   NaN
2013-04-03   NaN
2013-04-04   NaN
2013-04-05   NaN
2013-04-06   NaN
2013-04-07   NaN
2013-04-08   NaN
2013-04-09   NaN
2013-04-10   NaN
2013-04-11   NaN
2013-04-12   NaN
2013-04-13   NaN
2013-04-14   NaN
2013-04-15   NaN
2013-04-16   NaN
2013-04-17   NaN
2013-04-18   NaN
2013-04-19   NaN
2013-04-20   NaN
2013-04-21   NaN
2013-04-22   NaN
2013-04-23   NaN
2013-04-24   NaN
2013-04-25   NaN
2013-04-26   NaN
2013-04-27   NaN
2013-04-28   NaN
2013-04-29   NaN
2013-04-30   NaN
2013-05-01     2
2013-05-02   NaN
Freq: D"><pre class="notranslate"><span class="pl-v">In</span> [<span class="pl-c1">64</span>]: <span class="pl-s1">dates</span> <span class="pl-c1">=</span> <span class="pl-s1">pd</span>.<span class="pl-en">date_range</span>(<span class="pl-s">'01-Apr-13'</span>,<span class="pl-s">'01-May-13'</span>,<span class="pl-s1">freq</span><span class="pl-c1">=</span><span class="pl-s">'MS'</span>)

<span class="pl-v">In</span> [<span class="pl-c1">65</span>]: <span class="pl-s1">ts</span> <span class="pl-c1">=</span> <span class="pl-s1">pd</span>.<span class="pl-v">TimeSeries</span>([<span class="pl-c1">1</span>,<span class="pl-c1">2</span>],<span class="pl-s1">dates</span>)

<span class="pl-v">In</span> [<span class="pl-c1">66</span>]: <span class="pl-s1">ts</span>
<span class="pl-v">Out</span>[<span class="pl-c1">66</span>]: 
<span class="pl-c1">2013</span><span class="pl-c1">-</span><span class="pl-c1">04</span><span class="pl-c1">-</span><span class="pl-c1">01</span>    <span class="pl-c1">1</span>
<span class="pl-c1">2013</span><span class="pl-c1">-</span><span class="pl-c1">05</span><span class="pl-c1">-</span><span class="pl-c1">01</span>    <span class="pl-c1">2</span>
<span class="pl-v">Freq</span>: <span class="pl-v">MS</span>

<span class="pl-v">In</span> [<span class="pl-c1">67</span>]: <span class="pl-s1">ts</span>.<span class="pl-en">resample</span>(<span class="pl-s">'d'</span>,<span class="pl-s1">closed</span><span class="pl-c1">=</span><span class="pl-s">'left'</span>,<span class="pl-s1">label</span><span class="pl-c1">=</span><span class="pl-s">'left'</span>)
<span class="pl-v">Out</span>[<span class="pl-c1">67</span>]: 
<span class="pl-c1">2013</span><span class="pl-c1">-</span><span class="pl-c1">04</span><span class="pl-c1">-</span><span class="pl-c1">02</span>   <span class="pl-v">NaN</span>
<span class="pl-c1">2013</span><span class="pl-c1">-</span><span class="pl-c1">04</span><span class="pl-c1">-</span><span class="pl-c1">03</span>   <span class="pl-v">NaN</span>
<span class="pl-c1">2013</span><span class="pl-c1">-</span><span class="pl-c1">04</span><span class="pl-c1">-</span><span class="pl-c1">04</span>   <span class="pl-v">NaN</span>
<span class="pl-c1">2013</span><span class="pl-c1">-</span><span class="pl-c1">04</span><span class="pl-c1">-</span><span class="pl-c1">05</span>   <span class="pl-v">NaN</span>
<span class="pl-c1">2013</span><span class="pl-c1">-</span><span class="pl-c1">04</span><span class="pl-c1">-</span><span class="pl-c1">06</span>   <span class="pl-v">NaN</span>
<span class="pl-c1">2013</span><span class="pl-c1">-</span><span class="pl-c1">04</span><span class="pl-c1">-</span><span class="pl-c1">07</span>   <span class="pl-v">NaN</span>
<span class="pl-c1">2013</span><span class="pl-c1">-</span><span class="pl-c1">04</span><span class="pl-c1">-</span><span class="pl-c1">08</span>   <span class="pl-v">NaN</span>
<span class="pl-c1">2013</span><span class="pl-c1">-</span><span class="pl-c1">04</span><span class="pl-c1">-</span><span class="pl-c1">09</span>   <span class="pl-v">NaN</span>
<span class="pl-c1">2013</span><span class="pl-c1">-</span><span class="pl-c1">04</span><span class="pl-c1">-</span><span class="pl-c1">10</span>   <span class="pl-v">NaN</span>
<span class="pl-c1">2013</span><span class="pl-c1">-</span><span class="pl-c1">04</span><span class="pl-c1">-</span><span class="pl-c1">11</span>   <span class="pl-v">NaN</span>
<span class="pl-c1">2013</span><span class="pl-c1">-</span><span class="pl-c1">04</span><span class="pl-c1">-</span><span class="pl-c1">12</span>   <span class="pl-v">NaN</span>
<span class="pl-c1">2013</span><span class="pl-c1">-</span><span class="pl-c1">04</span><span class="pl-c1">-</span><span class="pl-c1">13</span>   <span class="pl-v">NaN</span>
<span class="pl-c1">2013</span><span class="pl-c1">-</span><span class="pl-c1">04</span><span class="pl-c1">-</span><span class="pl-c1">14</span>   <span class="pl-v">NaN</span>
<span class="pl-c1">2013</span><span class="pl-c1">-</span><span class="pl-c1">04</span><span class="pl-c1">-</span><span class="pl-c1">15</span>   <span class="pl-v">NaN</span>
<span class="pl-c1">2013</span><span class="pl-c1">-</span><span class="pl-c1">04</span><span class="pl-c1">-</span><span class="pl-c1">16</span>   <span class="pl-v">NaN</span>
<span class="pl-c1">2013</span><span class="pl-c1">-</span><span class="pl-c1">04</span><span class="pl-c1">-</span><span class="pl-c1">17</span>   <span class="pl-v">NaN</span>
<span class="pl-c1">2013</span><span class="pl-c1">-</span><span class="pl-c1">04</span><span class="pl-c1">-</span><span class="pl-c1">18</span>   <span class="pl-v">NaN</span>
<span class="pl-c1">2013</span><span class="pl-c1">-</span><span class="pl-c1">04</span><span class="pl-c1">-</span><span class="pl-c1">19</span>   <span class="pl-v">NaN</span>
<span class="pl-c1">2013</span><span class="pl-c1">-</span><span class="pl-c1">04</span><span class="pl-c1">-</span><span class="pl-c1">20</span>   <span class="pl-v">NaN</span>
<span class="pl-c1">2013</span><span class="pl-c1">-</span><span class="pl-c1">04</span><span class="pl-c1">-</span><span class="pl-c1">21</span>   <span class="pl-v">NaN</span>
<span class="pl-c1">2013</span><span class="pl-c1">-</span><span class="pl-c1">04</span><span class="pl-c1">-</span><span class="pl-c1">22</span>   <span class="pl-v">NaN</span>
<span class="pl-c1">2013</span><span class="pl-c1">-</span><span class="pl-c1">04</span><span class="pl-c1">-</span><span class="pl-c1">23</span>   <span class="pl-v">NaN</span>
<span class="pl-c1">2013</span><span class="pl-c1">-</span><span class="pl-c1">04</span><span class="pl-c1">-</span><span class="pl-c1">24</span>   <span class="pl-v">NaN</span>
<span class="pl-c1">2013</span><span class="pl-c1">-</span><span class="pl-c1">04</span><span class="pl-c1">-</span><span class="pl-c1">25</span>   <span class="pl-v">NaN</span>
<span class="pl-c1">2013</span><span class="pl-c1">-</span><span class="pl-c1">04</span><span class="pl-c1">-</span><span class="pl-c1">26</span>   <span class="pl-v">NaN</span>
<span class="pl-c1">2013</span><span class="pl-c1">-</span><span class="pl-c1">04</span><span class="pl-c1">-</span><span class="pl-c1">27</span>   <span class="pl-v">NaN</span>
<span class="pl-c1">2013</span><span class="pl-c1">-</span><span class="pl-c1">04</span><span class="pl-c1">-</span><span class="pl-c1">28</span>   <span class="pl-v">NaN</span>
<span class="pl-c1">2013</span><span class="pl-c1">-</span><span class="pl-c1">04</span><span class="pl-c1">-</span><span class="pl-c1">29</span>   <span class="pl-v">NaN</span>
<span class="pl-c1">2013</span><span class="pl-c1">-</span><span class="pl-c1">04</span><span class="pl-c1">-</span><span class="pl-c1">30</span>   <span class="pl-v">NaN</span>
<span class="pl-c1">2013</span><span class="pl-c1">-</span><span class="pl-c1">05</span><span class="pl-c1">-</span><span class="pl-c1">01</span>     <span class="pl-c1">2</span>
<span class="pl-c1">2013</span><span class="pl-c1">-</span><span class="pl-c1">05</span><span class="pl-c1">-</span><span class="pl-c1">02</span>   <span class="pl-v">NaN</span>
<span class="pl-v">Freq</span>: <span class="pl-v">D</span></pre></div>