Skip to content

False positive for "nested renamer is not supported" error #32156

Closed
@rth

Description

@rth

Code Sample

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'})  # aggregate by a non existing column

produces

<ipython-input-5-f5ac34bf856f> in <module>
----> 1 df.groupby('A').agg({'B': 'sum', 'G': 'min'})

~/src/dgr00/.venv3/lib/python3.6/site-packages/pandas/core/groupby/generic.py in aggregate(self, func, *args, **kwargs)
    938         func = _maybe_mangle_lambdas(func)
    939
--> 940         result, how = self._aggregate(func, *args, **kwargs)
    941         if how is None:
    942             return result

~/src/dgr00/.venv3/lib/python3.6/site-packages/pandas/core/base.py in _aggregate(self, arg, *args, **kwargs)
    364                     obj.columns.intersection(keys)
    365                 ) != len(keys):
--> 366                     raise SpecificationError("nested renamer is not supported")
    367
    368             from pandas.core.reshape.concat import concat

SpecificationError: nested renamer is not supported

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    ApplyApply, Aggregate, Transform, MapBugError ReportingIncorrect or improved errors from pandasGroupby

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions