Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
1 of 3 tasks
WillAyd opened this issue Jul 18, 2024 · 4 comments · Fixed by #59398
Closed
1 of 3 tasks

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

WillAyd opened this issue Jul 18, 2024 · 4 comments · Fixed by #59398
Assignees
Labels
Enhancement Error Reporting Incorrect or improved errors from pandas Reshaping Concat, Merge/Join, Stack/Unstack, Explode

Comments

@WillAyd
Copy link
Member

WillAyd commented Jul 18, 2024

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

@WillAyd WillAyd added Enhancement Reshaping Concat, Merge/Join, Stack/Unstack, Explode Error Reporting Incorrect or improved errors from pandas labels Jul 18, 2024
@Animesh-Shukla
Copy link

take

@Prabhat-Thapa45
Copy link

@WillAyd so kinda warning should be raised to warn this as counterproductive action

@MarcoGorelli
Copy link
Member

@Prabhat-Thapa45 rather than warning, I think the suggestion is that an informative error be raised

@jahn96
Copy link
Contributor

jahn96 commented Jul 26, 2024

take

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement Error Reporting Incorrect or improved errors from pandas Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants