Skip to content

BUG: resample ignores 'kind' argument, always behaves like kind='datetime' #24103

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

Closed
PAeberhard opened this issue Dec 4, 2018 · 1 comment · Fixed by #54099
Closed

BUG: resample ignores 'kind' argument, always behaves like kind='datetime' #24103

PAeberhard opened this issue Dec 4, 2018 · 1 comment · Fixed by #54099
Labels
Bug Datetime Datetime data dtype Groupby Period Period data type

Comments

@PAeberhard
Copy link

Code Sample

import pandas as pd
pd.show_versions()

index = pd.DatetimeIndex(["20181101 1100", "20181101 1200", "20181102 1300", "20181102 1400"], name='datetime')
df = pd.DataFrame(data=[["A", 1.4], ["B", 140.5], ["A", 1.6], ["B", 145.0]],
                  columns=["ONE", "TWO"],
                  index=index)

grouped = df.groupby("ONE").TWO

# Resampling onto a period index: expected result is a PeriodIndex, actual is DatetimeIndex.
resampled_period = grouped.resample("D", kind="period").last()
assert isinstance(resampled_period.index.get_level_values('datetime'), pd.PeriodIndex)

# Resampling onto a datetime index: works as expected.
resampled_datetime = grouped.resample("D", kind="datetime").last()
assert isinstance(resampled_datetime.index.get_level_values('datetime'), pd.DatetimeIndex)

Problem description

The 'kind' argument to groupby-resample in the example above is ignored and the result is always as if the argument passed is kind="datetime".

Expected Output

The 'datetime' level in the MultiIndex in the example above should be of type PeriodIndex if kind="period", but instead we get DatetimeIndex.

Output of pd.show_versions()

INSTALLED VERSIONS

commit: None
python: 2.7.13.final.0
python-bits: 64
OS: Linux
OS-release: 3.10.0-514.10.2.el7.x86_64
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_GB.UTF-8
LOCALE: en_GB.UTF-8

pandas: 0.23.4
pytest: 3.1.0
pip: 8.1.1
setuptools: 28.8.0
Cython: None
numpy: 1.15.4
scipy: None
pyarrow: None
xarray: None
IPython: 5.3.0
sphinx: None
patsy: None
dateutil: 2.7.5
pytz: 2018.7
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: None
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: None
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: None
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None

@gfyoung gfyoung added Groupby Dtype Conversions Unexpected or buggy dtype conversions labels Dec 6, 2018
@gfyoung
Copy link
Member

gfyoung commented Dec 6, 2018

cc @jreback

@mroeschke mroeschke added Bug Period Period data type Datetime Datetime data dtype and removed Dtype Conversions Unexpected or buggy dtype conversions labels Jun 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Datetime Datetime data dtype Groupby Period Period data type
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants