-
-
Notifications
You must be signed in to change notification settings - Fork 18.7k
Closed
Labels
BugError ReportingIncorrect or improved errors from pandasIncorrect or improved errors from pandasReshapingConcat, Merge/Join, Stack/Unstack, ExplodeConcat, Merge/Join, Stack/Unstack, Explode
Milestone
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
>>> df1 = pd.DataFrame({"A": [1]}, index=["x"])
>>> df2 = pd.DataFrame({"A": [1]}, index=["y"])
>>> pd.concat([df1, df2], keys=["x", "y"], levels=[["x", "y", "y"]])
A
x x 1
y y 1
```python
>>> df1 = pd.DataFrame({"A": [1]}, index=["x"])
>>> df2 = pd.DataFrame({"A": [1]}, index=["y"])
>>> pd.concat([df1, df2], levels=[["x", "y"]])
A
x 1
y 1
Issue Description
First, we should raise when levels duplicated. Second, when levels specified and keys not given, then we should also raise since this is unreasonable. (DOC only mentions infering levels from keys but not infering keys from levels)
Expected Behavior
>>> df1 = pd.DataFrame({"A": [1]}, index=["x"])
>>> df2 = pd.DataFrame({"A": [1]}, index=["y"])
>>> pd.concat([df1, df2], keys=["x", "y"], levels=[["x", "y", "y"]])
ValueError: Level values not unique: ['x', 'y', 'y']
>>> df1 = pd.DataFrame({"A": [1]}, index=["x"])
>>> df2 = pd.DataFrame({"A": [1]}, index=["y"])
>>> pd.concat([df1, df2], levels=[["x", "y"]])
ValueError: levels supported only when keys not None
Installed Versions
1.4.1
Metadata
Metadata
Assignees
Labels
BugError ReportingIncorrect or improved errors from pandasIncorrect or improved errors from pandasReshapingConcat, Merge/Join, Stack/Unstack, ExplodeConcat, Merge/Join, Stack/Unstack, Explode