-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Merge multi-index with a multi-index #15980
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
Conversation
Allow the merging of multi-indexed objects with different number of levels
Merge multi-index with a multi-index
you only need 1 PR if u have changes just push to the same one |
Sorry Jeff, I'm just not very experienced with GIT. Thanks for the tip |
pandas/indexes/base.py
Outdated
|
||
def _complete_join(new_lvls, new_lbls, new_nms): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
first thing is that you must have exactly the same levels that match, otherwise this is a raise. They must match in number and name (or None matches None).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The common levels are specified by: overlap = list(set(self_names) & set(other_names)).
I think this way guarantees that they will much in number and name. Am I missing something?
@@ -1224,7 +1220,7 @@ def f(): | |||
expected = ( | |||
DataFrame(dict( | |||
household_id=[1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4], | |||
asset_id=["nl0000301109", "nl0000289783", "gb00b03mlx29", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why would this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is a typo in the original test. I am quite sure because the deleted ID (nl0000289783) does not appear in any dataframe of 'test_join_multi_levels2' function.
TripPurp=['hbw', 'nhb', 'hbo', 'nhb', 'hbw'], | ||
Trips=[1987, 3647, 2470, 4296, 4444], | ||
Distance=[100, 80, 90, np.nan, 75]), | ||
columns=['Origin', 'Destination', 'Period', 'TripPurp', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so the very first test you should have is a self-join.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean result = matrix.join(matrix, how='inner', rsuffix='_joined')
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes
this needs quite a bit more testing. Would need to exercise all of the |
Extra tests have been added. |
TripPurp=['hbw', 'nhb', 'hbo', 'nhb', 'hbw'], | ||
Trips=[1987, 3647, 2470, 4296, 4444], | ||
Distance=[100, 80, 90, np.nan, 75]), | ||
columns=['Origin', 'Destination', 'Period', 'TripPurp', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @jreback , I've implemented the requested changes but I'm not sure they show because I force-pushed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nothing seems to have been pushed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nevertheless, the current commit includes all the requested changes. You can review them whenever possible
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if it was pushed it would show up
there are 2 commits last one from april 12
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think now it must be fine. My changes were pushed in a second commit but now I merged them. Really sorry about the confusion, still getting to know GIT..
Allow the merging of multi-indexed objects with different number of levels
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Merged changes in 1 commit
Allow the merging of multi-indexed objects with different number of levels
Conflicts: pandas/indexes/base.py pandas/tests/tools/test_merge.py
Allow the merging of multi-indexed objects with different number of levels
@harisbal I see you are pushing this, but you need to resolve the conflicts. |
Allow the merging of multi-indexed objects with different number of levels
Allow the merging of multi-indexed objects with different number of levels
This PR is a mess. I'll read the docs more carefully and create a new clean PR. Apologies about all the trouble I've caused |
#6360
Allow the merging of multi-indexed objects with different number of levels.
During tests I receive the following error: pandas/pandas/core/internals.py:4800: ComplexWarning: Casting complex values to real discards the imaginary part