-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
DataFrameGroupBy.aggregate can not work with tuple
as an argument
#18079
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
Comments
Hi @sinanonur, your example works in the newly released 0.21.0. Please upgrade when you can
|
@bobhaffner : Cool! Mind adding that test so that we can close this issue? |
Hi @gfyoung Yes, sure thing. |
So this is interesting. I was building a test for this and everything started as expected
But then I tried this
and got this Am I missing something obvious? I'll try to dig into this more later on. Click to see full traceback--------------------------------------------------------------------------- ValueError Traceback (most recent call last) ~/miniconda3/envs/dev35/lib/python3.5/site-packages/pandas/core/groupby.py in aggregate(self, arg, *args, **kwargs) 3636 result = self._aggregate_multiple_funcs( -> 3637 [arg], _level=_level, _axis=self.axis) 3638 result.columns = Index(~/miniconda3/envs/dev35/lib/python3.5/site-packages/pandas/core/base.py in _aggregate_multiple_funcs(self, arg, _level, _axis) ValueError: no results During handling of the above exception, another exception occurred: ValueError Traceback (most recent call last) ~/miniconda3/envs/dev35/lib/python3.5/site-packages/pandas/core/internals.py in init(self, blocks, axes, do_integrity_check, fastpath) ~/miniconda3/envs/dev35/lib/python3.5/site-packages/pandas/core/internals.py in _verify_integrity(self) ~/miniconda3/envs/dev35/lib/python3.5/site-packages/pandas/core/internals.py in construction_error(tot_items, block_shape, axes, e) ValueError: Shape of passed values is (2, 2), indices imply (2, 1) During handling of the above exception, another exception occurred: ValueError Traceback (most recent call last) ~/miniconda3/envs/dev35/lib/python3.5/site-packages/pandas/core/groupby.py in aggregate(self, arg, *args, **kwargs) ~/miniconda3/envs/dev35/lib/python3.5/site-packages/pandas/core/groupby.py in aggregate(self, arg, *args, **kwargs) ~/miniconda3/envs/dev35/lib/python3.5/site-packages/pandas/core/groupby.py in _aggregate_generic(self, func, *args, **kwargs) ~/miniconda3/envs/dev35/lib/python3.5/site-packages/pandas/core/groupby.py in _wrap_generic_output(self, result, obj) ~/miniconda3/envs/dev35/lib/python3.5/site-packages/pandas/core/frame.py in init(self, data, index, columns, dtype, copy) ~/miniconda3/envs/dev35/lib/python3.5/site-packages/pandas/core/frame.py in _init_dict(self, data, index, columns, dtype) ~/miniconda3/envs/dev35/lib/python3.5/site-packages/pandas/core/frame.py in _arrays_to_mgr(arrays, arr_names, index, columns, dtype) ~/miniconda3/envs/dev35/lib/python3.5/site-packages/pandas/core/internals.py in create_block_manager_from_arrays(arrays, names, axes) ~/miniconda3/envs/dev35/lib/python3.5/site-packages/pandas/core/internals.py in construction_error(tot_items, block_shape, axes, e) ValueError: Shape of passed values is (2, 2), indices imply (2, 1) |
That's odd, as if we define the following function: def f(x):
return tuple(x) The code works. Have a look to see what's going on there. |
Back on this again, but not having much luck figuring out the root cause. Below is an excerpt from the When I do When I do @gfyoung's successful tuple func also follows the else Not sure why the if is needed in the first place? Also, this issue warns about using agg with classes Any guidance is appreciated.
|
Try removing and see what happens. When there's a bug in our code, all bets are (almost) off 😄 |
The following code raises
ValueError
Here is a more replicatable version:
Problem description
The statement above does not work because
tuple
is not a function. It throws:ValueError: no results
Workaround
use the following
groupby
statement insteadThis was issued as a result of the following discussion: pylint-dev/pylint#1709 (comment)
Expected Output
Should be able to work without raising a
ValueError
Output of
pd.show_versions()
INSTALLED VERSIONS
commit: None
python: 2.7.12.final.0
python-bits: 64
OS: Linux
OS-release: 4.4.0-97-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: en_US.UTF-8
LANG: en_US.UTF-8
LOCALE: None.None
pandas: 0.20.3
pytest: None
pip: 8.1.2
setuptools: 28.2.0
Cython: 0.24.1
numpy: 1.13.3
scipy: 0.18.1
xarray: None
IPython: 5.4.1
sphinx: 1.4.8
patsy: 0.4.1
dateutil: 2.5.3
pytz: 2016.7
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: 1.5.3
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: 1.0b10
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.8
s3fs: None
pandas_gbq: None
pandas_datareader: None
The text was updated successfully, but these errors were encountered: