Skip to content

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

Closed
wants to merge 12 commits into from
Closed

Merge multi-index with a multi-index #15980

wants to merge 12 commits into from

Conversation

harisbal
Copy link
Contributor

#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

harisbal added 2 commits April 12, 2017 01:08
Allow the merging of multi-indexed objects with different number of levels
Merge multi-index with a multi-index
@jreback
Copy link
Contributor

jreback commented Apr 12, 2017

you only need 1 PR if u have changes just push to the same one

@harisbal
Copy link
Contributor Author

Sorry Jeff, I'm just not very experienced with GIT. Thanks for the tip


def _complete_join(new_lvls, new_lbls, new_nms):
Copy link
Contributor

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).

Copy link
Contributor Author

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",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why would this change?

Copy link
Contributor Author

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',
Copy link
Contributor

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.

Copy link
Contributor Author

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')

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

@jreback
Copy link
Contributor

jreback commented Apr 13, 2017

this needs quite a bit more testing. Would need to exercise all of the how cases, empty levels, and error conditions (mismatched) levels.

@harisbal
Copy link
Contributor Author

Extra tests have been added.
The case of joining between levels that do not result in unique index raises error

TripPurp=['hbw', 'nhb', 'hbo', 'nhb', 'hbw'],
Trips=[1987, 3647, 2470, 4296, 4444],
Distance=[100, 80, 90, np.nan, 75]),
columns=['Origin', 'Destination', 'Period', 'TripPurp',
Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Contributor

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

Copy link
Contributor Author

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..

@jreback jreback added the Reshaping Concat, Merge/Join, Stack/Unstack, Explode label Apr 20, 2017
@harisbal harisbal closed this Apr 21, 2017
@harisbal harisbal deleted the MultiIndex_operations branch April 21, 2017 01:03
@harisbal harisbal reopened this Apr 21, 2017
Allow the merging of multi-indexed objects with different number of levels
Copy link
Contributor Author

@harisbal harisbal left a 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

harisbal added 4 commits April 24, 2017 21:46
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
@jreback
Copy link
Contributor

jreback commented Apr 25, 2017

@harisbal I see you are pushing this, but you need to resolve the conflicts.

@harisbal harisbal closed this Apr 25, 2017
@harisbal
Copy link
Contributor Author

harisbal commented Apr 25, 2017

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants