Skip to content

BUG: concat doesn't preserve attrs (as alternative for append deprecated in 1.4) #45824

Open
@MarcoGorelli

Description

@MarcoGorelli

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
df1 = pandas.DataFrame({"a": [1]})
df2 = pandas.DataFrame({"a": [2]})
df1.attrs["metadata-xy"] = 42

print(df1.append(df2).attrs)  # keeps the attrs of df1
print(pandas.concat([df1, df2]).attrs)  # no attrs in result

Issue Description

append preserves attrs, but concat doesn't

Originally reported here #35407 (comment)

Expected Behavior

df1.append(df2).attrs and pandas.concat([df1, df2]).attrs should probably match

Installed Versions

Replace this line with the output of pd.show_versions()

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions