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.
>>> 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 1Issue 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 NoneInstalled Versions
1.4.1
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4