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

Fixturize tests/frame/test_join.py #25639

Merged
merged 1 commit into from
Mar 10, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 18 additions & 24 deletions pandas/tests/frame/test_join.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import pytest

from pandas import DataFrame, Index, period_range
from pandas.tests.frame.common import TestData
import pandas.util.testing as tm


Expand All @@ -16,11 +15,6 @@ def frame_with_period_index():
index=period_range(start='2000', freq='A', periods=4))


@pytest.fixture
def frame():
return TestData().frame


@pytest.fixture
def left():
return DataFrame({'a': [20, 10, 0]}, index=[2, 1, 0])
Expand Down Expand Up @@ -63,11 +57,11 @@ def test_join(left, right, how, sort, expected):
tm.assert_frame_equal(result, expected)


def test_join_index(frame):
def test_join_index(float_frame):
# left / right

f = frame.loc[frame.index[:10], ['A', 'B']]
f2 = frame.loc[frame.index[5:], ['C', 'D']].iloc[::-1]
f = float_frame.loc[float_frame.index[:10], ['A', 'B']]
f2 = float_frame.loc[float_frame.index[5:], ['C', 'D']].iloc[::-1]

joined = f.join(f2)
tm.assert_index_equal(f.index, joined.index)
Expand All @@ -91,7 +85,7 @@ def test_join_index(frame):
# outer

joined = f.join(f2, how='outer')
tm.assert_index_equal(joined.index, frame.index.sort_values())
tm.assert_index_equal(joined.index, float_frame.index.sort_values())
tm.assert_index_equal(joined.columns, expected_columns)

with pytest.raises(ValueError, match='join method'):
Expand All @@ -101,16 +95,16 @@ def test_join_index(frame):
msg = 'columns overlap but no suffix'
for how in ('outer', 'left', 'inner'):
with pytest.raises(ValueError, match=msg):
frame.join(frame, how=how)
float_frame.join(float_frame, how=how)


def test_join_index_more(frame):
af = frame.loc[:, ['A', 'B']]
bf = frame.loc[::2, ['C', 'D']]
def test_join_index_more(float_frame):
af = float_frame.loc[:, ['A', 'B']]
bf = float_frame.loc[::2, ['C', 'D']]

expected = af.copy()
expected['C'] = frame['C'][::2]
expected['D'] = frame['D'][::2]
expected['C'] = float_frame['C'][::2]
expected['D'] = float_frame['D'][::2]

result = af.join(bf)
tm.assert_frame_equal(result, expected)
Expand All @@ -122,28 +116,28 @@ def test_join_index_more(frame):
tm.assert_frame_equal(result, expected.loc[:, result.columns])


def test_join_index_series(frame):
df = frame.copy()
s = df.pop(frame.columns[-1])
def test_join_index_series(float_frame):
df = float_frame.copy()
s = df.pop(float_frame.columns[-1])
joined = df.join(s)

# TODO should this check_names ?
tm.assert_frame_equal(joined, frame, check_names=False)
tm.assert_frame_equal(joined, float_frame, check_names=False)

s.name = None
with pytest.raises(ValueError, match='must have a name'):
df.join(s)


def test_join_overlap(frame):
df1 = frame.loc[:, ['A', 'B', 'C']]
df2 = frame.loc[:, ['B', 'C', 'D']]
def test_join_overlap(float_frame):
df1 = float_frame.loc[:, ['A', 'B', 'C']]
df2 = float_frame.loc[:, ['B', 'C', 'D']]

joined = df1.join(df2, lsuffix='_df1', rsuffix='_df2')
df1_suf = df1.loc[:, ['B', 'C']].add_suffix('_df1')
df2_suf = df2.loc[:, ['B', 'C']].add_suffix('_df2')

no_overlap = frame.loc[:, ['A', 'D']]
no_overlap = float_frame.loc[:, ['A', 'D']]
expected = df1_suf.join(df2_suf).join(no_overlap)

# column order not necessarily sorted
Expand Down