<p dir="auto">I just upgraded my projects from pandas 0.16.2 to pandas 0.18.1, but I have a difference on some <code class="notranslate">DataFrame.resample</code> operations, with Weekly frequencies.</p>
<p dir="auto">For instance, I want to resample daily data to weekly data (<code class="notranslate">W-SUN</code>), and apply an offset to the results, so each row will be a <strong>MONDAY</strong> and not a SUNDAY.</p>
<h4 dir="auto">Code Sample</h4>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import pandas as pd
from datetime import timedelta
offset = +timedelta(days=1)

dates = pd.date_range(&quot;2001-01-01&quot;, freq=&quot;D&quot;, periods=18)]
a=pd.DataFrame(data=list(range(18)), columns=[&quot;value&quot;], index=[dates])

a.resample(&quot;1W&quot;, how={&quot;value&quot;: &quot;sum&quot;}, loffset=offset, closed=&quot;right&quot;, label=&quot;right&quot;)"><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-k">from</span> <span class="pl-s1">datetime</span> <span class="pl-k">import</span> <span class="pl-s1">timedelta</span>
<span class="pl-s1">offset</span> <span class="pl-c1">=</span> <span class="pl-c1">+</span><span class="pl-en">timedelta</span>(<span class="pl-s1">days</span><span class="pl-c1">=</span><span class="pl-c1">1</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">"2001-01-01"</span>, <span class="pl-s1">freq</span><span class="pl-c1">=</span><span class="pl-s">"D"</span>, <span class="pl-s1">periods</span><span class="pl-c1">=</span><span class="pl-c1">18</span>)]
<span class="pl-s1">a</span><span class="pl-c1">=</span><span class="pl-s1">pd</span>.<span class="pl-v">DataFrame</span>(<span class="pl-s1">data</span><span class="pl-c1">=</span><span class="pl-en">list</span>(<span class="pl-en">range</span>(<span class="pl-c1">18</span>)), <span class="pl-s1">columns</span><span class="pl-c1">=</span>[<span class="pl-s">"value"</span>], <span class="pl-s1">index</span><span class="pl-c1">=</span>[<span class="pl-s1">dates</span>])

<span class="pl-s1">a</span>.<span class="pl-en">resample</span>(<span class="pl-s">"1W"</span>, <span class="pl-s1">how</span><span class="pl-c1">=</span>{<span class="pl-s">"value"</span>: <span class="pl-s">"sum"</span>}, <span class="pl-s1">loffset</span><span class="pl-c1">=</span><span class="pl-s1">offset</span>, <span class="pl-s1">closed</span><span class="pl-c1">=</span><span class="pl-s">"right"</span>, <span class="pl-s1">label</span><span class="pl-c1">=</span><span class="pl-s">"right"</span>)</pre></div>
<h4 dir="auto">Problem description</h4>
<p dir="auto">With <code class="notranslate">pandas 0.16.2</code>, I got this correct output:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="            value
2001-01-08     21
2001-01-15     70
2001-01-22     62"><pre class="notranslate"><code class="notranslate">            value
2001-01-08     21
2001-01-15     70
2001-01-22     62
</code></pre></div>
<p dir="auto">ie, each row is a weekly aggregation of the data, and each date is a <strong>MONDAY</strong></p>
<p dir="auto">Resulting index is as follow:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="a.index[0]
Timestamp('2001-01-08 00:00:00', offset='W-MON')"><pre class="notranslate"><code class="notranslate">a.index[0]
Timestamp('2001-01-08 00:00:00', offset='W-MON')
</code></pre></div>
<p dir="auto">However, with <code class="notranslate">pandas 0.18.1</code>, I got this output:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="            value
2001-01-07     21
2001-01-14     70
2001-01-21     62"><pre class="notranslate"><code class="notranslate">            value
2001-01-07     21
2001-01-14     70
2001-01-21     62
</code></pre></div>
<p dir="auto">each row is correctly aggregated, but the dates are <strong>SUNDAY</strong>s</p>
<p dir="auto">Resulting index is as follow:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="a.index[0]
Timestamp('2001-01-07 00:00:00', offset='W-SUN')"><pre class="notranslate"><code class="notranslate">a.index[0]
Timestamp('2001-01-07 00:00:00', offset='W-SUN')
</code></pre></div>

<p dir="auto">It's like the <code class="notranslate">loffset</code> parameter is not correctly taken into account in  the new <code class="notranslate">DataFrame.resample()</code> implementation.</p>
<p dir="auto">ie, the output with <code class="notranslate">pandas 0.18.1</code> is the same as the one using <code class="notranslate">pandas 0.16.2</code>, but calling <code class="notranslate">a.resample("1W", how={"value": "sum"}, </code><strong>loffset=None</strong><code class="notranslate">, closed="right", label="right")</code></p>

<h4 dir="auto">Output of <code class="notranslate">pd.show_versions()</code></h4>
<p dir="auto">pandas <code class="notranslate">0.16.1</code> installation:</p>
<details>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="INSTALLED VERSIONS
------------------
commit: None
python: 3.4.5.final.0
python-bits: 64
OS: Linux
OS-release: 3.13.0-106-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8

pandas: 0.16.2
nose: 1.3.7
Cython: 0.22.1
numpy: 1.10.1
scipy: 0.16.0
statsmodels: 0.6.1
IPython: 3.2.1
sphinx: 1.3.1
patsy: 0.3.0
dateutil: 2.4.2
pytz: 2015.7
bottleneck: 1.0.0
tables: 3.2.1
numexpr: 2.4.3
matplotlib: 1.5.0
openpyxl: 2.3.2
xlrd: 0.9.3
xlwt: 1.0.0
xlsxwriter: 0.7.3
lxml: 3.4.4
bs4: 4.3.2
html5lib: None
httplib2: None
apiclient: None
sqlalchemy: 1.0.7
pymysql: 0.6.6.None
psycopg2: None"><pre class="notranslate"><code class="notranslate">INSTALLED VERSIONS
------------------
commit: None
python: 3.4.5.final.0
python-bits: 64
OS: Linux
OS-release: 3.13.0-106-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8

pandas: 0.16.2
nose: 1.3.7
Cython: 0.22.1
numpy: 1.10.1
scipy: 0.16.0
statsmodels: 0.6.1
IPython: 3.2.1
sphinx: 1.3.1
patsy: 0.3.0
dateutil: 2.4.2
pytz: 2015.7
bottleneck: 1.0.0
tables: 3.2.1
numexpr: 2.4.3
matplotlib: 1.5.0
openpyxl: 2.3.2
xlrd: 0.9.3
xlwt: 1.0.0
xlsxwriter: 0.7.3
lxml: 3.4.4
bs4: 4.3.2
html5lib: None
httplib2: None
apiclient: None
sqlalchemy: 1.0.7
pymysql: 0.6.6.None
psycopg2: None
</code></pre></div>
</details>
<p dir="auto">pandas <code class="notranslate">0.18.2</code> installation:</p>
<details>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="INSTALLED VERSIONS
------------------
commit: None
python: 3.4.5.final.0
python-bits: 64
OS: Linux
OS-release: 4.4.0-57-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8

pandas: 0.18.1
nose: 1.3.7
pip: 9.0.1
setuptools: 27.2.0
Cython: 0.22.1
numpy: 1.10.4
scipy: 0.16.0
statsmodels: 0.6.1
xarray: None
IPython: 3.2.1
sphinx: 1.3.1
patsy: 0.3.0
dateutil: 2.4.2
pytz: 2015.6
blosc: None
bottleneck: 1.0.0
tables: 3.2.1
numexpr: 2.6.0
matplotlib: 1.4.3
openpyxl: 2.3.2
xlrd: 0.9.3
xlwt: 1.0.0
xlsxwriter: 0.7.3
lxml: 3.4.4
bs4: 4.3.2
html5lib: None
httplib2: None
apiclient: None
sqlalchemy: 1.0.7
pymysql: 0.6.6.None
psycopg2: None
jinja2: 2.7.3
boto: None
pandas_datareader: None"><pre class="notranslate"><code class="notranslate">INSTALLED VERSIONS
------------------
commit: None
python: 3.4.5.final.0
python-bits: 64
OS: Linux
OS-release: 4.4.0-57-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8

pandas: 0.18.1
nose: 1.3.7
pip: 9.0.1
setuptools: 27.2.0
Cython: 0.22.1
numpy: 1.10.4
scipy: 0.16.0
statsmodels: 0.6.1
xarray: None
IPython: 3.2.1
sphinx: 1.3.1
patsy: 0.3.0
dateutil: 2.4.2
pytz: 2015.6
blosc: None
bottleneck: 1.0.0
tables: 3.2.1
numexpr: 2.6.0
matplotlib: 1.4.3
openpyxl: 2.3.2
xlrd: 0.9.3
xlwt: 1.0.0
xlsxwriter: 0.7.3
lxml: 3.4.4
bs4: 4.3.2
html5lib: None
httplib2: None
apiclient: None
sqlalchemy: 1.0.7
pymysql: 0.6.6.None
psycopg2: None
jinja2: 2.7.3
boto: None
pandas_datareader: None
</code></pre></div>
</details>
<h4 dir="auto">Code Sample, a copy-pastable example if possible</h4>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="# Create DF
df = pd.DataFrame(np.random.rand(5,2), columns=list('AB'), index=pd.date_range('2010-01-01 09:00:00', periods=5, freq='s'))

print(df)
                                       A                    B
2010-01-01 09:00:00             0.283113             0.559642
2010-01-01 09:00:01             0.754942             0.621557
2010-01-01 09:00:02             0.102002             0.892100
2010-01-01 09:00:03             0.885400             0.524359
2010-01-01 09:00:04             0.324761             0.706758

#Resample, loffset works fine using mean(), is offset by 2 hours.
print(df.resample('2s', loffset='2h').mean())
                                       A                    B
2010-01-01 11:00:00             0.519028             0.590599
2010-01-01 11:00:02             0.493701             0.708229
2010-01-01 11:00:04             0.324761             0.706758


# Resample with agg(), loffset doesn't work anymore.
print(df.resample('2s', loffset='2h').agg(dict(A='sum', B='mean')))
                                      A                    B
2010-01-01 09:00:00             1.038055             0.590599
2010-01-01 09:00:02             0.987402             0.708229
2010-01-01 09:00:04             0.324761             0.706758
"><pre class="notranslate"><code class="notranslate"># Create DF
df = pd.DataFrame(np.random.rand(5,2), columns=list('AB'), index=pd.date_range('2010-01-01 09:00:00', periods=5, freq='s'))

print(df)
                                       A                    B
2010-01-01 09:00:00             0.283113             0.559642
2010-01-01 09:00:01             0.754942             0.621557
2010-01-01 09:00:02             0.102002             0.892100
2010-01-01 09:00:03             0.885400             0.524359
2010-01-01 09:00:04             0.324761             0.706758

#Resample, loffset works fine using mean(), is offset by 2 hours.
print(df.resample('2s', loffset='2h').mean())
                                       A                    B
2010-01-01 11:00:00             0.519028             0.590599
2010-01-01 11:00:02             0.493701             0.708229
2010-01-01 11:00:04             0.324761             0.706758


# Resample with agg(), loffset doesn't work anymore.
print(df.resample('2s', loffset='2h').agg(dict(A='sum', B='mean')))
                                      A                    B
2010-01-01 09:00:00             1.038055             0.590599
2010-01-01 09:00:02             0.987402             0.708229
2010-01-01 09:00:04             0.324761             0.706758

</code></pre></div>
<h4 dir="auto">Expected Output</h4>
<p dir="auto">I'd expect the same as with mean(), this is how resample worked in the past with resample(how=...).</p>
<p dir="auto">But maybe I also misunderstood something about the change. If so please enlighten me.</p>
<p dir="auto">Since I need this to keep things going, I use the following workaround for now, please let me know if this is the way to go or if there's a more efficient way:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="print(df.resample('2s', loffset='2h').agg(dict(A='sum', B='mean')).tshift(2, 'h'))"><pre class="notranslate"><code class="notranslate">print(df.resample('2s', loffset='2h').agg(dict(A='sum', B='mean')).tshift(2, 'h'))
</code></pre></div>
<h4 dir="auto">output of <code class="notranslate">pd.show_versions()</code></h4>
<h2 dir="auto">INSTALLED VERSIONS</h2>
<p dir="auto">commit: None<br>
python: 3.5.1.final.0<br>
python-bits: 64<br>
OS: Darwin<br>
OS-release: 15.5.0<br>
machine: x86_64<br>
processor: i386<br>
byteorder: little<br>
LC_ALL: None<br>
LANG: de_DE.UTF-8</p>
<p dir="auto">pandas: 0.18.1<br>
nose: 1.3.7<br>
pip: 8.1.2<br>
setuptools: 20.3<br>
Cython: 0.23.4<br>
numpy: 1.10.4<br>
scipy: 0.17.1<br>
statsmodels: 0.6.1<br>
xarray: None<br>
IPython: 4.2.0<br>
sphinx: 1.3.5<br>
patsy: 0.4.0<br>
dateutil: 2.5.1<br>
pytz: 2016.2<br>
blosc: None<br>
bottleneck: 1.0.0<br>
tables: 3.2.2<br>
numexpr: 2.5.2<br>
matplotlib: 1.5.1<br>
openpyxl: 2.3.2<br>
xlrd: 0.9.4<br>
xlwt: 1.0.0<br>
xlsxwriter: 0.8.4<br>
lxml: 3.6.0<br>
bs4: 4.4.1<br>
html5lib: None<br>
httplib2: None<br>
apiclient: None<br>
sqlalchemy: 1.0.12<br>
pymysql: None<br>
psycopg2: None<br>
jinja2: 2.8<br>
boto: 2.39.0<br>
pandas_datareader: 0.2.1<br>
In [92]:</p>