Skip to content

groupby(pd.Grouper) ignores loffset #28302

Closed
@ghost

Description

Code Sample, a copy-pastable example if possible

import pandas as pd
df = pd.date_range(start="1/1/2018", end="1/2/2018", periods=1000).to_frame()
print(df.resample("1h", loffset="15min").last().index)
print(df.groupby(pd.Grouper(freq="1h", loffset="15min")).last().index)

Problem description

I thought the two calls should be equivalent. However, the output is:

DatetimeIndex(['2018-01-01 00:15:00', '2018-01-01 01:15:00',
               '2018-01-01 02:15:00', '2018-01-01 03:15:00',
               '2018-01-01 04:15:00', '2018-01-01 05:15:00',
               '2018-01-01 06:15:00', '2018-01-01 07:15:00',
               '2018-01-01 08:15:00', '2018-01-01 09:15:00',
               '2018-01-01 10:15:00', '2018-01-01 11:15:00',
               '2018-01-01 12:15:00', '2018-01-01 13:15:00',
               '2018-01-01 14:15:00', '2018-01-01 15:15:00',
               '2018-01-01 16:15:00', '2018-01-01 17:15:00',
               '2018-01-01 18:15:00', '2018-01-01 19:15:00',
               '2018-01-01 20:15:00', '2018-01-01 21:15:00',
               '2018-01-01 22:15:00', '2018-01-01 23:15:00',
               '2018-01-02 00:15:00'],
              dtype='datetime64[ns]', freq='H')
DatetimeIndex(['2018-01-01 00:00:00', '2018-01-01 01:00:00',
               '2018-01-01 02:00:00', '2018-01-01 03:00:00',
               '2018-01-01 04:00:00', '2018-01-01 05:00:00',
               '2018-01-01 06:00:00', '2018-01-01 07:00:00',
               '2018-01-01 08:00:00', '2018-01-01 09:00:00',
               '2018-01-01 10:00:00', '2018-01-01 11:00:00',
               '2018-01-01 12:00:00', '2018-01-01 13:00:00',
               '2018-01-01 14:00:00', '2018-01-01 15:00:00',
               '2018-01-01 16:00:00', '2018-01-01 17:00:00',
               '2018-01-01 18:00:00', '2018-01-01 19:00:00',
               '2018-01-01 20:00:00', '2018-01-01 21:00:00',
               '2018-01-01 22:00:00', '2018-01-01 23:00:00',
               '2018-01-02 00:00:00'],
              dtype='datetime64[ns]', freq='H')

Output of pd.show_versions()

INSTALLED VERSIONS

commit : None
python : 3.7.3.final.0
python-bits : 64
OS : Linux
OS-release : 4.4.0-17134-Microsoft
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : C.UTF-8
LOCALE : en_US.UTF-8

pandas : 0.25.1
numpy : 1.17.1
pytz : 2019.2
dateutil : 2.8.0
pip : 19.2.3
setuptools : 41.2.0
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.4.1
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.10.1
IPython : 7.8.0
pandas_datareader: 0.7.4
bs4 : None
bottleneck : None
fastparquet : None
gcsfs : None
lxml.etree : 4.4.1
matplotlib : 3.1.1
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 0.14.1
pytables : None
s3fs : None
scipy : 1.3.1
sqlalchemy : None
tables : None
xarray : None
xlrd : None
xlwt : None
xlsxwriter : 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