-
-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
DEPR: Merging on different number of levels #34862
Comments
Does the UesrWarning make it clear that you should be passing the same number of levels? |
Yes, the warning is clear. But why not to add auto-leveling of columns with different levels? If it can break something (I really don't know what it is) then the The auto-leveling can be useful if the pandas is used in an automatic data-processing flow when the column levels shapes are not known ahead. Or does this feature look like "rarely used" and therefore unnecessary? |
I'm not sure. Perhaps investigate the original issue where the warning was added? |
Ok, investigation is started... The warning was added in bb9b9c5 (line 200) by @nbonnotte and @jreback after #9455 and #12219. See discussion in #12219 starting with this comment (as result the warning was added?). @jreback wrote in this comment
@jreback, did you mean "option == optional parameter for If so, is the optional parameter for auto-leveling of multi-index columns is an actual issue? |
@dinya I think the warning is fine, meaning some people really want to do this, but I am open to deprecating this and simply prohibiting merging on different number of levels as the results are unexpected. |
@TomAugspurger @jreback was this level dropping deprecated/prohibited in the 1.2.0 release? After upgrading I'm seeing "ValueError: Length of names must match number of levels in MultiIndex." where as with 1.1.5 I previously saw the UserWarning. |
@shawnbissell you would have to show a reproducible example |
Merging dfs with different column lelvels has been disallowed ref pandas-dev/pandas#34862
* Transform positional argument into keyword argument From pandas 2.0 any only accepts keyworkd arguments ref pandas-dev/pandas#44896 * Change how reciprocal is computed I have not fully understood why this solve the problem, but splitting the operation in 2 lines does not seem to work * Catch warnings from pandas.to_datetime Now pandas.to_datetime raises a warning when the column cannot be converted * check_dtype=False in tests datetime features Pandas dataframes created from python integers are created with int column types `int64` but the operation tested returns `int32` which caused issues * Use droplevel before merging Merging dfs with different column lelvels has been disallowed ref pandas-dev/pandas#34862 * Change expected values for months I am not sure why this caused an issue, maybe due to type casting? * run black * run black on tests * isort _variable_type_checks.py * Fix datetime_subtraction --------- Co-authored-by: Claudio Salvatore Arcidiacono <[email protected]>
Two dataframes with MultiIndex in columns (shapes are different).
Case 1
returns
It's ok. Columns saved its structure from the both dataframes. They are tuples, but it can be fixed (for example with something like this).
Case 2
returns
When the left DataFrame is a DataFrame with fewer column levels the merge result is questionable: lower levels are dropped.
Is this a bug or a feature (result levels shape must be the same as for the left DataFrame)?
Notes:
UserWarning: merging between different levels can give an unintended result ...
.I have searched the [pandas] tag on StackOverflow for similar questions.
I have asked my usage related question on StackOverflow (see 62490244).
The text was updated successfully, but these errors were encountered: