-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
False positive for "nested renamer is not supported" error #32156
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
Confirmed. The incorrect error message threw me off as well. |
Same problem |
Same problem here, bug is due to non-existing column |
same problem here, anyone has a workaround method? thx |
Can confirm, got the same exception due to a non-existing column name. |
It's also inconsistent: import pandas as pd
df = pd.DataFrame({'A': [1, 1, 1, 2, 2], 'B': range(5), 'C': range(5)})
df.groupby('A').agg({'B': 'sum', 'G': ['min']) # <- use ['min'] instead of 'min' raises the correct error: |
You wrote G instead of C. 'G' is nothing. 'C' is the column. Applying multiple aggregation a column |
I think this one is also related. I tried to rename the column right after groupby by the way it is done in Here is the example: df = pd.DataFrame({'A': [1, 1, 1, 2, 2],'B': range(5)})
df.groupby('A').agg({'B': {'foo': 'sum'}}) The error message is:
|
We are expecting the appropriate error message. The current error message is not pointing to the right direction. |
I also ran into this error and as mentioned, it was caused by trying to aggregate a non-existent column. Version 1.0.3 |
got the same error when there are duplicate columns in the dataframe. |
I only get this error when I'm running my code with command or git bash, when I'm running my code in jupyter it works fine, what's the best way to solve it by still using the agg()? |
Instead of using |
thanks a lot, upstairs |
I think this has been fixed on master: See this issue 32755 and PR #32836. I now get the below error message on master, rather than the "nested renamer" error: import pandas as pd
df = pd.DataFrame({'A': [1, 1, 1, 2, 2], 'B': range(5), 'C': range(5)})
df.groupby('A').agg({'B': 'sum', 'G': 'min'})
Traceback (most recent call last):
File "C:\Users\timhu\Anaconda3\envs\pandas-dev-2\lib\site-packages\IPython\core\interactiveshell.py", line 3331, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-2-08e47b9415b3>", line 4, in <module>
df.groupby('A').agg({'B': 'sum', 'G': 'min'})
File "c:\users\timhu\documents\code\pandas\pandas\core\groupby\generic.py", line 948, in aggregate
result, how = self._aggregate(func, *args, **kwargs)
File "c:\users\timhu\documents\code\pandas\pandas\core\base.py", line 354, in _aggregate
raise SpecificationError(f"Column(s) {cols} do not exist")
pandas.core.base.SpecificationError: Column(s) ['G'] do not exist I think this issue can be closed. |
Looks to be addressed by #32836 |
Code Sample
produces
Problem description
While groupby.agg() with a dictionary when renaming was deprecated in 1.0 (
https://pandas.pydata.org/pandas-docs/stable/whatsnew/v0.20.0.html#deprecate-groupby-agg-with-a-dictionary-when-renaming) the corresponding error message can also be obtained when aggregating by an non existing column which can lead to confusion.
Expected Output
Error saying that the column
G
does not exist.Output of
pd.show_versions()
INSTALLED VERSIONS
python : 3.6.4.final.0
OS : Linux
machine : x86_64
pandas : 1.0.1
The text was updated successfully, but these errors were encountered: