Skip to content

Chained groupby-resample object raises error when used twice with different column selector #13906

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
jer0nim0 opened this issue Aug 4, 2016 · 1 comment
Labels
Duplicate Report Duplicate issue or pull request

Comments

@jer0nim0
Copy link

jer0nim0 commented Aug 4, 2016

Going from 0.18.0 to 0.18.1, a chained groupby - resample object can now only be used once. A second similar operation raises a KeyError when a column that is not used in the first operation is selected.

Code Sample, a copy-pastable example if possible

N = 5
df = pd.DataFrame({'a': np.ones(N), 'b': np.ones(N), 'c': np.ones(N)}, 
                  index=pd.date_range('2016-01-01', periods=N))
group = df.groupby('a').resample('1D')
# OK:
print group[['b']].count()
# Error:
print group[['c']].count()

Actual Output

                b
a                
1.0 2016-01-01  1
    2016-01-02  1
    2016-01-03  1
    2016-01-04  1
    2016-01-05  1

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-101-875a81207428> in <module>()
----> 1 group[['c']].count()

C:\Miniconda2\lib\site-packages\pandas\tseries\resample.pyc in __getitem__(self, key)
    174     def __getitem__(self, key):
    175         try:
--> 176             return super(Resampler, self).__getitem__(key)
    177         except (KeyError, com.AbstractMethodError):
    178 

C:\Miniconda2\lib\site-packages\pandas\core\base.pyc in __getitem__(self, key)
    331                 bad_keys = list(set(key).difference(self.obj.columns))
    332                 raise KeyError("Columns not found: %s"
--> 333                                % str(bad_keys)[1:-1])
    334             return self._gotitem(list(key), ndim=2)
    335 

KeyError: "Columns not found: 'c'"

Expected Output


                b
a                
1.0 2016-01-01  1
    2016-01-02  1
    2016-01-03  1
    2016-01-04  1
    2016-01-05  1

                c
a                
1.0 2016-01-01  1
    2016-01-02  1
    2016-01-03  1
    2016-01-04  1
    2016-01-05  1

output of pd.show_versions()

INSTALLED VERSIONS

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

pandas: 0.18.1
nose: None
pip: 8.1.2
setuptools: 23.0.0
Cython: None
numpy: 1.11.1
scipy: 0.17.1
statsmodels: 0.6.1
xarray: None
IPython: 4.1.2
sphinx: 1.3.5
patsy: 0.4.1
dateutil: 2.5.3
pytz: 2016.6.1
blosc: None
bottleneck: None
tables: None
numexpr: None
matplotlib: 1.5.1
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: None
httplib2: None
apiclient: None
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.8
boto: None
pandas_datareader: None

@TomAugspurger
Copy link
Contributor

Thanks for the report. This has been fixed on master (#13175 I believe).

The release candidate for 0.19 should be out in a few weeks.

@TomAugspurger TomAugspurger added the Duplicate Report Duplicate issue or pull request label Aug 4, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate Report Duplicate issue or pull request
Projects
None yet
Development

No branches or pull requests

2 participants