Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
b581789
Allow for join between two multi-index dataframe instances
Sep 19, 2018
2d61a12
Merge remote-tracking branch 'upstream/master' into multi-index-join
harisbal Sep 19, 2018
4d4acc5
Merge remote-tracking branch 'upstream/master' into multi-index-join
harisbal Oct 7, 2018
66d82fb
Review
harisbal Oct 8, 2018
c091bb4
Merge remote-tracking branch 'upstream/master' into multi-index-join
Oct 8, 2018
d56ebcd
Second review
harisbal Oct 9, 2018
0cdad73
Merge remote-tracking branch 'upstream/master' into multi-index-join
Oct 9, 2018
c2a65aa
Merge remote-tracking branch 'upstream/master' into multi-index-join
harisbal Oct 10, 2018
571fdf7
Merge remote-tracking branch 'upstream/master' into multi-index-join
Nov 1, 2018
ae2d8ad
Review
harisbal Nov 1, 2018
405c1a4
Merge remote-tracking branch 'upstream/master' into multi-index-join
harisbal Nov 1, 2018
1d2d9f3
Fix ci
harisbal Nov 3, 2018
f0ac24d
Merge branch 'master' into multi-index-join
Nov 3, 2018
5ac40ff
Merge remote-tracking branch 'upstream/master' into multi-index-join
harisbal Nov 3, 2018
be862c7
Update v0.24.0.txt
harisbal Nov 4, 2018
e10cbde
Update docstring _restore_dropped_levels_multijoin
harisbal Nov 4, 2018
06d48d0
Update docstring _restore_dropped_levels_multijoin
harisbal Nov 4, 2018
f54c151
Merge remote-tracking branch 'upstream/master' into multi-index-join
Nov 4, 2018
c75108d
Merge remote-tracking branch 'origin/multi-index-join' into multi-ind…
harisbal Nov 5, 2018
c690260
Merge remote-tracking branch 'upstream/master' into multi-index-join
harisbal Nov 6, 2018
4092b34
updated comments
harisbal Nov 6, 2018
cfd5fcc
Refactoring
harisbal Nov 6, 2018
6c8131d
Review
harisbal Nov 10, 2018
ecaf515
Merge remote-tracking branch 'upstream/master' into multi-index-join
harisbal Nov 10, 2018
8b5d0aa
Merge remote-tracking branch 'upstream/master' into harisbal-multi-in…
TomAugspurger Nov 14, 2018
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Review
  • Loading branch information
harisbal committed Nov 10, 2018
commit 6c8131d060e82166e91734d86522fca3e1888855
7 changes: 2 additions & 5 deletions pandas/core/reshape/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -1164,11 +1164,8 @@ def _convert_to_mulitindex(index):
if isinstance(index, MultiIndex):
return index
else:
levels = [index.values]
labels = [list(range(index.size))]
names = [index.name]
return MultiIndex(levels=levels, labels=labels, names=names,
verify_integrity=False)
return MultiIndex.from_arrays([index.values],
names=[index.name])

# For multi-multi joins with one overlapping level,
# the returned index if of type Index
Expand Down
84 changes: 42 additions & 42 deletions pandas/tests/reshape/merge/test_multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,44 @@ def right():
columns=['j_one', 'j_two', 'j_three'])


@pytest.fixture
def left_multi():
return (
DataFrame(
dict(Origin=['A', 'A', 'B', 'B', 'C'],
Destination=['A', 'B', 'A', 'C', 'A'],
Period=['AM', 'AM', 'IP', 'AM', 'OP'],
TripPurp=['hbw', 'nhb', 'hbo', 'nhb', 'hbw'],
Trips=[1987, 3647, 2470, 4296, 4444]),
columns=['Origin', 'Destination', 'Period',
'TripPurp', 'Trips'])
.set_index(['Origin', 'Destination', 'Period', 'TripPurp']))


@pytest.fixture
def right_multi():
return (
DataFrame(
dict(Origin=['A', 'A', 'B', 'B', 'C', 'C', 'E'],
Destination=['A', 'B', 'A', 'B', 'A', 'B', 'F'],
Period=['AM', 'AM', 'IP', 'AM', 'OP', 'IP', 'AM'],
LinkType=['a', 'b', 'c', 'b', 'a', 'b', 'a'],
Distance=[100, 80, 90, 80, 75, 35, 55]),
columns=['Origin', 'Destination', 'Period',
'LinkType', 'Distance'])
.set_index(['Origin', 'Destination', 'Period', 'LinkType']))


@pytest.fixture
def on_cols_multi():
return ['Origin', 'Destination', 'Period']


@pytest.fixture
def idx_cols_multi():
return ['Origin', 'Destination', 'Period', 'TripPurp', 'LinkType']


class TestMergeMulti(object):

def setup_method(self):
Expand Down Expand Up @@ -549,66 +587,28 @@ def test_join_multi_levels2(self):
tm.assert_frame_equal(result, expected)


@pytest.fixture
def left_multi():
return (
DataFrame(
dict(Origin=['A', 'A', 'B', 'B', 'C'],
Destination=['A', 'B', 'A', 'C', 'A'],
Period=['AM', 'AM', 'IP', 'AM', 'OP'],
TripPurp=['hbw', 'nhb', 'hbo', 'nhb', 'hbw'],
Trips=[1987, 3647, 2470, 4296, 4444]),
columns=['Origin', 'Destination', 'Period',
'TripPurp', 'Trips'])
.set_index(['Origin', 'Destination', 'Period', 'TripPurp']))


@pytest.fixture
def right_multi():
return (
DataFrame(
dict(Origin=['A', 'A', 'B', 'B', 'C', 'C', 'E'],
Destination=['A', 'B', 'A', 'B', 'A', 'B', 'F'],
Period=['AM', 'AM', 'IP', 'AM', 'OP', 'IP', 'AM'],
LinkType=['a', 'b', 'c', 'b', 'a', 'b', 'a'],
Distance=[100, 80, 90, 80, 75, 35, 55]),
columns=['Origin', 'Destination', 'Period',
'LinkType', 'Distance'])
.set_index(['Origin', 'Destination', 'Period', 'LinkType']))


@pytest.fixture
def on_cols():
return ['Origin', 'Destination', 'Period']


@pytest.fixture
def idx_cols():
return ['Origin', 'Destination', 'Period', 'TripPurp', 'LinkType']


class TestJoinMultiMulti(object):

def test_join_multi_multi(self, left_multi, right_multi, join_type,
on_cols, idx_cols):
on_cols_multi, idx_cols_multi):
# Multi-index join tests
expected = (pd.merge(left_multi.reset_index(),
right_multi.reset_index(),
how=join_type, on=on_cols).set_index(idx_cols)
how=join_type, on=on_cols_multi).set_index(idx_cols_multi)
.sort_index())

result = left_multi.join(right_multi, how=join_type).sort_index()
tm.assert_frame_equal(result, expected)

def test_join_multi_empty_frames(self, left_multi, right_multi, join_type,
on_cols, idx_cols):
on_cols_multi, idx_cols_multi):

left_multi = left_multi.drop(columns=left_multi.columns)
right_multi = right_multi.drop(columns=right_multi.columns)

expected = (pd.merge(left_multi.reset_index(),
right_multi.reset_index(),
how=join_type, on=on_cols).set_index(idx_cols)
how=join_type, on=on_cols_multi).set_index(idx_cols_multi)
.sort_index())

result = left_multi.join(right_multi, how=join_type).sort_index()
Expand Down