Skip to content

Different behavior of DataFrame.resample() between pandas 0.16.2 and pandas 0.18.1 #15002

@adrien-pain-01

Description

@adrien-pain-01

I just upgraded my projects from pandas 0.16.2 to pandas 0.18.1, but I have a difference on some DataFrame.resample operations, with Weekly frequencies.

For instance, I want to resample daily data to weekly data (W-SUN), and apply an offset to the results, so each row will be a MONDAY and not a SUNDAY.

Code Sample

import pandas as pd from datetime import timedelta offset = +timedelta(days=1) dates = pd.date_range("2001-01-01", freq="D", periods=18)] a=pd.DataFrame(data=list(range(18)), columns=["value"], index=[dates]) a.resample("1W", how={"value": "sum"}, loffset=offset, closed="right", label="right")

Problem description

With pandas 0.16.2, I got this correct output:

 value 2001-01-08 21 2001-01-15 70 2001-01-22 62 

ie, each row is a weekly aggregation of the data, and each date is a MONDAY

Resulting index is as follow:

a.index[0] Timestamp('2001-01-08 00:00:00', offset='W-MON') 

However, with pandas 0.18.1, I got this output:

 value 2001-01-07 21 2001-01-14 70 2001-01-21 62 

each row is correctly aggregated, but the dates are SUNDAYs

Resulting index is as follow:

a.index[0] Timestamp('2001-01-07 00:00:00', offset='W-SUN') 

It's like the loffset parameter is not correctly taken into account in the new DataFrame.resample() implementation.

ie, the output with pandas 0.18.1 is the same as the one using pandas 0.16.2, but calling a.resample("1W", how={"value": "sum"}, loffset=None, closed="right", label="right")

Output of pd.show_versions()

pandas 0.16.1 installation:

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 

pandas 0.18.2 installation:

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 

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions