Skip to content

label keyword argument for resample causes an error when used with a groupby object #13235

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
roycoding opened this issue May 20, 2016 · 2 comments
Labels
Bug Resample resample method
Milestone

Comments

@roycoding
Copy link
Contributor

roycoding commented May 20, 2016

Code Sample, a copy-pastable example if possible

import numpy as np
import pandas as pd

index = pd.date_range('2000-01-01', freq='2D', periods=5)
df = pd.DataFrame(index=index, data={'col1':[0,0,1,1,2], 'col2':[1,1,1,1,1]})

df.groupby('col1').resample('1W', label='left').sum()

The dataframe

            col1  col2
2000-01-01     0     1
2000-01-03     0     1
2000-01-05     1     1
2000-01-07     1     1
2000-01-09     2     1

Expected Output

                 col1  col2
col1
0    1999-12-26     0     1
     2000-01-02     0     1
1    2000-01-02     2     2
2    2000-01-02     2     1

Actual ouput

TypeError                                 Traceback (most recent call last)
<ipython-input-53-6e7ac0fde8b3> in <module>()
----> 1 df.groupby('col1').resample('1W', label='left').sum()

/Users/roycoding/venv-lib-upgrade/lib/python2.7/site-packages/pandas/core/groupby.pyc in resample(self, rule, *args, **kwargs)
   1080         """
   1081         from pandas.tseries.resample import get_resampler_for_grouping
-> 1082         return get_resampler_for_grouping(self, rule, *args, **kwargs)
   1083
   1084     @Substitution(name='groupby')

/Users/roycoding/venv-lib-upgrade/lib/python2.7/site-packages/pandas/tseries/resample.pyc in get_resampler_for_grouping(groupby, rule, how, fill_method, limit, kind, **kwargs)
    910                                        fill_method=fill_method,
    911                                        limit=limit,
--> 912                                        **kwargs)
    913
    914

TypeError: _maybe_process_deprecations() got an unexpected keyword argument 'label'

Without the label keyword, I get this (with expected right labeled dates):

                 col1  col2
col1
0    2000-01-02     0     1
     2000-01-09     0     1
1    2000-01-09     2     2
2    2000-01-09     2     1

output of pd.show_versions()

INSTALLED VERSIONS
------------------
commit: None
python: 2.7.8.final.0
python-bits: 64
OS: Darwin
OS-release: 13.4.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8

pandas: 0.18.1
nose: 1.3.7
pip: 1.5.6
setuptools: 3.6
Cython: None
numpy: 1.11.0
scipy: 0.15.1
statsmodels: 0.6.1
xarray: None
IPython: 3.2.1
sphinx: None
patsy: None
dateutil: 2.5.3
pytz: 2016.4
blosc: None
bottleneck: None
tables: None
numexpr: 2.5
matplotlib: 1.4.3
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: 4.4.1
html5lib: 0.9999999
httplib2: 0.9.2
apiclient: None
sqlalchemy: 1.0.12
pymysql: None
psycopg2: 2.6.1 (dt dec pq3 ext lo64)
jinja2: 2.8
boto: None
pandas_datareader: None
@roycoding roycoding changed the title label keyword argument for resample causes an error when used with a groupby object label keyword argument for resample causes an error when used with a groupby object May 20, 2016
@jreback
Copy link
Contributor

jreback commented May 20, 2016

So the **kwargs should not be passed here

simple fix. These args are all eaten by the TimeGrouper except those explicity named.

want to do a PR?

@jreback jreback added Bug Resample resample method labels May 20, 2016
@jreback jreback added this to the 0.18.2 milestone May 20, 2016
@roycoding
Copy link
Contributor Author

want to do a PR?

I'll take a shot at it. Thanks.

roycoding added a commit to roycoding/pandas that referenced this issue May 20, 2016
roycoding added a commit to roycoding/pandas that referenced this issue May 25, 2016
Fix for incorrect passing of kwargs to helper function when calling groupby().resample(..) with label keyword.
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
Development

Successfully merging a pull request may close this issue.

2 participants