Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

loffset in resample does not work with ffill, bfill, pad #20744

Closed
badge opened this issue Apr 19, 2018 · 1 comment · Fixed by #20884
Closed

loffset in resample does not work with ffill, bfill, pad #20744

badge opened this issue Apr 19, 2018 · 1 comment · Fixed by #20884
Labels
Bug Resample resample method
Milestone

Comments

@badge
Copy link

badge commented Apr 19, 2018

Minimal example

df = pd.DataFrame(np.random.rand(49),
                  index=pd.DatetimeIndex(start='2018-04-01',
                                         end='2018-04-03',
                                         freq='1h')
                 )

print(df.head())
print(df.resample('D', loffset=pd.Timedelta('12h')).mean())
print(df.resample('D', loffset=pd.Timedelta('12h')).ffill())

Problem description

DataFrame and DataFrameGroupBy both provide a resample method, for resampling timeseries data. These methods have an optional argument, loffset, which accepts a pandas Timedelta instance and is used to adjust the output DataFrame's index, once a suitable aggregation method has been used on the resulting DatetimeIndexResampler or DatetimeIndexResamplerGroupby object.

This works as expected for, for example, mean, but fails in the cases of ffill, bfill and pad. The resample is successful, but the loffset argument is ignored.

Expected Output

                        0

2018-04-01 00:00:00 0.246580
2018-04-01 01:00:00 0.380124
2018-04-01 02:00:00 0.227830
2018-04-01 03:00:00 0.376657
2018-04-01 04:00:00 0.139719
0
2018-04-01 12:00:00 0.434068
2018-04-02 12:00:00 0.471917
2018-04-03 12:00:00 0.395527
0
2018-04-01 12:00:00 0.246580
2018-04-02 12:00:00 0.402313
2018-04-03 12:00:00 0.395527

Output of pd.show_versions()

INSTALLED VERSIONS

commit: None
python: 3.6.4.final.0
python-bits: 64
OS: Windows
OS-release: 7
machine: AMD64
processor: Intel64 Family 6 Model 61 Stepping 4, GenuineIntel
byteorder: little
LC_ALL: None
LANG: None
LOCALE: None.None

pandas: 0.22.0
pytest: 3.0.7
pip: 9.0.3
setuptools: 39.0.1
Cython: 0.27.3
numpy: 1.14.2
scipy: 1.0.0
pyarrow: None
xarray: None
IPython: 6.3.1
sphinx: 1.7.2
patsy: 0.4.1
dateutil: 2.7.2
pytz: 2018.4
blosc: None
bottleneck: 1.2.1
tables: 3.4.2
numexpr: 2.6.2
feather: None
matplotlib: 2.1.2
openpyxl: 2.4.7
xlrd: 1.0.0
xlwt: 1.2.0
xlsxwriter: 0.9.6
lxml: 3.7.3
bs4: 4.6.0
html5lib: 1.0.1
sqlalchemy: 1.1.9
pymysql: None
psycopg2: None
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None

@jreback
Copy link
Contributor

jreback commented Apr 22, 2018

hmm, guess it doesn. a pull-request would be great to fix! (also doesn't work for .asfreq())

@jreback jreback added this to the Next Major Release milestone Apr 22, 2018
johncant added a commit to johncant/pandas that referenced this issue Apr 29, 2018
johncant added a commit to johncant/pandas that referenced this issue Apr 29, 2018
johncant added a commit to johncant/pandas that referenced this issue Apr 29, 2018
johncant added a commit to johncant/pandas that referenced this issue Apr 29, 2018
johncant added a commit to johncant/pandas that referenced this issue Apr 30, 2018
johncant added a commit to johncant/pandas that referenced this issue Apr 30, 2018
@jreback jreback modified the milestones: Next Major Release, 0.23.0 May 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Resample resample method
Projects
None yet
2 participants