Skip to content
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

TST: add validation checks on levels keyword from pd.concat #46653

Closed
2 of 3 tasks
GYHHAHA opened this issue Apr 6, 2022 · 0 comments · Fixed by #46654
Closed
2 of 3 tasks

TST: add validation checks on levels keyword from pd.concat #46653

GYHHAHA opened this issue Apr 6, 2022 · 0 comments · Fixed by #46654
Labels
Bug Error Reporting Incorrect or improved errors from pandas Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Milestone

Comments

@GYHHAHA
Copy link
Contributor

GYHHAHA commented Apr 6, 2022

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

@GYHHAHA GYHHAHA added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Apr 6, 2022
@mzeitlin11 mzeitlin11 added Reshaping Concat, Merge/Join, Stack/Unstack, Explode Error Reporting Incorrect or improved errors from pandas and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Apr 6, 2022
@jreback jreback added this to the 1.5 milestone Apr 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug 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.

3 participants