Skip to content

BUG: Concatenating dataframe and series with ignore_index = True drops the series name #60723

Open
@uzzell

Description

Pandas version checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

import pandas as pd

df = pd.DataFrame({'a': [0, 1], 'b': [2, 3]})
s = pd.Series([4, 5], name='c')
pd.concat([df, s])   # columns are ['a', 'b', 'c']
pd.concat([df, s], ignore_index=True)  # columns are ['a', 'b', 0]
pd.concat([df, s.to_frame()])  # columns are ['a', 'b', 'c']
pd.concat([df, s.to_frame()], ignore_index=True)  # columns are ['a', 'b', 'c']

Issue Description

When I concatenate a dataframe with a series and pass ignore_index=True, the series' name does not show up in the resulting dataframe. This is surprising, because the documentation for ignore_index says, "Note the index values on the other axes are still respected in the join."

This seems similar to #56257. That concerned the case in which the name of the series is the same as the name of one of the columns of the dataframe but did not involve ignore_index. That issue has a stale PR (#56362) that looks like it might fix this one, too.

Expected Behavior

Doing pd.concat([df, s], ignore_index=True) should preserve the name of the series.

Installed Versions

INSTALLED VERSIONS

commit : 0691c5c
python : 3.12.2
python-bits : 64
OS : Windows
OS-release : 11
Version : 10.0.22631
machine : AMD64
processor : Intel64 Family 6 Model 165 Stepping 3, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : English_United States.1252

pandas : 2.2.3
numpy : 1.26.4
pytz : 2024.1
dateutil : 2.9.0.post0
pip : 24.3.1
Cython : None
sphinx : None
IPython : None
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : None
blosc : None
bottleneck : None
dataframe-api-compat : None
fastparquet : None
fsspec : None
html5lib : None
hypothesis : None
gcsfs : None
jinja2 : None
lxml.etree : None
matplotlib : None
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
psycopg2 : None
pymysql : None
pyarrow : None
pyreadstat : None
pytest : None
python-calamine : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlsxwriter : None
zstandard : None
tzdata : 2024.1
qtpy : None
pyqt5 : None
None

Metadata

Assignees

No one assigned

    Labels

    BugNeeds TriageIssue that has not been reviewed by a pandas team member

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions