Skip to content

Cannot do agg if dataframe has column "name" #24915

Closed
@ghost

Description

Code Sample, a copy-pastable example if possible

# Your code here
import pandas as pd

df = pd.DataFrame({"a": range(10)})
df.agg({"a": 'mean'}) # this line runs good

df["name"] = range(10)
df.agg({"a": 'mean'}) # now we have RuntimeError: maximum recursion depth exceeded

Problem description

If a dataframe has a column which is called "name", doing aggregation on the dataframe will cause RuntimeError.

But if the column is not called "name" but with some variant like "name0", "name_", it runs good.
import pandas as pd

df = pd.DataFrame({"a": range(10)})
df.agg({"a": 'mean'}) # this line runs good

df["name_"] = range(10)  # not "name"
df.agg({"a": 'mean'}) # this line runs good as well

Expected Output

Output of pd.show_versions()

[paste the output of pd.show_versions() here below this line]

INSTALLED VERSIONS

commit: None
python: 2.7.15.final.0
python-bits: 64
OS: Darwin
OS-release: 18.0.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: None.None

pandas: 0.23.4
pytest: None
pip: 18.1
setuptools: 40.6.3
Cython: None
numpy: 1.16.0
scipy: 1.2.0
pyarrow: 0.11.1
xarray: None
IPython: 5.8.0
sphinx: None
patsy: None
dateutil: 2.7.3
pytz: 2018.9
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: None
openpyxl: None
xlrd: 1.1.0
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: 0.9999999
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.10
s3fs: 0.2.0
fastparquet: None
pandas_gbq: None
pandas_datareader: None

Metadata

Metadata

Assignees

No one assigned

    Labels

    ApplyApply, Aggregate, Transform, MapDuplicate ReportDuplicate issue or pull requestNeeds TestsUnit test(s) needed to prevent regressions

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions