Skip to content

ENH: pd.concat with keys and ignore_index=True should raise #59274

Closed
@WillAyd

Description

@WillAyd

Feature Type

  • Adding new functionality to pandas

  • Changing existing functionality in pandas

  • Removing existing functionality in pandas

Problem Description

You can happily pass both of these arguments together, but the ignore_index=True call drops the keys, so it ends up being a moot point:

In [1]: import pandas as pd

In [2]: df1 = pd.DataFrame([[0]])

In [3]: df2 = pd.DataFrame([[42]])

In [4]: pd.concat([df1, df2])
Out[4]: 
    0
0   0
0  42

In [5]: pd.concat([df1, df2], keys=["df1", "df2"])
Out[5]: 
        0
df1 0   0
df2 0  42

In [6]: pd.concat([df1, df2], keys=["df1", "df2"], ignore_index=True)
Out[6]: 
    0
0   0
1  42

Feature Description

pandas can raise that this combination of values does not make sense

Alternative Solutions

status quo

Additional Context

No response

Metadata

Metadata

Labels

EnhancementError ReportingIncorrect or improved errors from pandasReshapingConcat, Merge/Join, Stack/Unstack, Explode

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions